Skip to main content

ERC6551 Primitives

  • ERC6551 Registry, keeping track of registrations of Token-Bound Accounts (TBAs) on the chain

ERC6551 Registry

Example

extensions:
- name: "ERC6551 Registry"
type: "erc6551-registry"
contractAddress: "0x01...ef" # optional. Uses the new ERC6551 registry by default (WARNING: multiple projects use the old registry. See more info below)
implementation: "0x01...ef" # optional. Filters to only TBAs created with a specific implementation
tokenContract: "0x01...ef" # optional. Filters to only TBAs for a specific NFT collection
tokenId: "1234" # optional. Filters to only TBAs for a specific token ID in the collection
salt: "1234" # optional. Filters to only TBAs generated with a specific salt. Note: this is not an `indexed` field in the contract, so this will not lower the number of RPC calls
startBlockHeight: 7654321

Meaning

ERC6551 uses a global registry that where all TBAs are registered. This address is constant among all chains, and acts as an easy way to know all the TBAs deployed to the chain

This extension allows you to track all the TBAs that exist so that your game can easily aggregate state across different accounts owned by the same player, and it can allow you to treat specific kinds of TBA (ex: where the owner is a specific NFT for your game or a specific tool like AWNS) differently.

Contract address

ERC6551 has had multiple versions using different contract addresses. You can find the history of all contract addresses used here.

Notably, the old address did not used indexed fields for the AccountCreated EVM logs, making them slower to index for some use-cases among other changes. Be sure to check which version of the registry your project uses.

Utility functions

  • getErc6551AccountOwner, fetch the NFT that owns this account:
export async function getErc6551AccountOwner(
readonlyDBConn: PoolClient,
extensionName: string,
accountCreated: string
): Promise<TokenIdPair | null>;
  • getAllOwnedErc6551Accounts, fetch all accounts owned by this NFT. This call is NOT recursive:
export async function getErc6551AccountOwner(
readonlyDBConn: PoolClient,
extensionName: string,
nft: TokenIdPair
): Promise<string[]>;