Tips for Building on Aptos

Remeber to Store Object's ExtendRef

When you are dealing with Object, remember to always store the extend ref of it. You only have access to extend ref at the time of Object creation, if you don't store it you will permanently lose access to it. Without extend ref, you won't be able to generate signer for the Object. Without access to the signer, your funds in the Object will be locked forever.

Here's the minimal code snippet to create an Object and store its extend ref in a resource in the Object:

const VAULT_SEED: vector<u8> = b"VAULT";
struct Vault has key {
extend_ref: object::ExtendRef,
fun init_module(sender: &signer) {
let vault_constructor_ref = &object::create_named_object(sender, VAULT_SEED);
let vault_signer = &object::generate_signer(vault_constructor_ref);
move_to(vault_signer, Vault {
extend_ref: object::generate_extend_ref(vault_constructor_ref),
fun get_vault_signer(): signer acquires Vault {
let vault = borrow_global<Vault>(get_vault_addr());

Custom Indexer is Required for Efficient Data Query

In our example code, we store registries such as all issuers, all holders and all holdings in the format of array on-chain. Although this is convenient for implementation, it's not efficient as operations like find data and delete data in array is O(n). In production, both Aptos and Solana encourage developers to build custom indexer that listens to events emit from the contract and store data in database like Postgres. This way, frontend can query data efficiently.

At Aptos Labs, we are actively working on an indexer SDK or indexer framework to make the process easier. Stay tuned for more updates!