Learn how to use Airstack to get token-bound (ERC6551) accounts by NFTs that own the accounts and vice versa
Airstack provides easy-to-use APIs that index both deployed and non-deployed (optimistic) ERC6551 accounts across Ethereum and Base to enrich ERC6551 dapps with on-chain and off-chain data.
For non-deployed (optimistic) ERC6551 accounts, it will be available in the tokenNfts nested queries and the value will be calculated through a hashing function that depends on 3 input variables:
Table Of Contents
In this guide you will learn how to use Airstack to:
Airstack provides an AI solution for you to build GraphQL queries to fulfill your use case easily. You can find the AI prompt of each query in the demo's caption or title for yourself to try.
Get Token Bound Accounts (ERC6551) By NFT Collection Address(es)
You can get all the deployed ERC6551 accounts owned by a given :
If you would like to include NFTs with no TBA and show the associated non-deployed (optimistic) TBAs to be included in the result, then check this query instead.
In addition, you can also fetch cross-chain ERC6551 accounts, by specifying the blockchain to a different chain to where the token address is deployed.
Get All Deployed and Non-Deployed (Optimistic) Token Bound Accounts (ERC6551) By NFT Collection Address(es)
You can fetch all deployed and non-deployed (optimistic) TBAs on NFT Collection(s) by using the TokenNfts API and providing the NFT collection address to the address filter:
For non-deployed (optimistic) TBAs, it can be checked through some of the fields' value:
createdAtBlockNumber: -1
createdAtBlockTimestamp: null
creationTransactionHash: null
Try Demo
Code
queryMyQuery { TokenNfts( input: {filter: {address: {_in: ["0x26727ed4f5ba61d3772d1575bca011ae3aef5d36"]} },blockchain: ethereum,limit: 200 } ) { TokenNft { address tokenId erc6551Accounts( # set this to `true` to show all optimistic/non-deployed and deployed TBAs # set this to `false` to show all deployed TBA accounts input: {showOptimisticAddress: true} ) { createdAtBlockNumber createdAtBlockTimestamp address { addresses } } } }}
{"data": {"TokenNfts": {"TokenNft": [ {"tokenId":"0",// This NFT have 2 deployed TBAs on Ethereum"erc6551Accounts": [ {"createdAtBlockNumber":17213826,// Block number when the TBA was created"createdAtBlockTimestamp":"2023-05-08T05:53:59Z","address": {"addresses": ["0x5416e5dc14caa0950b2a24ede1eb0e97c360bcf5" ] } }, {"createdAtBlockNumber":18467201,"createdAtBlockTimestamp":"2023-10-31T02:40:23Z","address": {"addresses": ["0xb5307cb1ae1385f64de8442d5d48ff86479f4f8c" ] } } ] }, {"tokenId":"100","erc6551Accounts": [ {// This NFT have no TBA"createdAtBlockNumber":-1,"createdAtBlockTimestamp":null,"address": {"addresses": [// This TBA address is optimistic"0x35dc2fd127fcc7a0ed33b29d7e58e4bc01b13b2d" ] } } ] },// ] } }}
Get Optimistic Token Bound Accounts (ERC6551) for Custom Implementations
You can fetch non-deployed (optimistic) TBAs on NFT Collection(s) by using the TokenNfts API and providing the NFT collection address. You can control which optimistic accounts to retrieve by changing the values of implementation, registry, and salt in the input filters.
At the moment only _eq is supported for the inputs. If you want to get multiple custom implementations in one call, you need to duplicate your query and set aliases for each if you want to pass them in one API call. You can find an example how to do that here.
{"data": {"Accounts": {"Account": [ {"nft": {"address":"0x26727ed4f5ba61d3772d1575bca011ae3aef5d36","metaData": {"name":"Sapienz #3504", "description": "SAPIENZ is a collection of 15,000 networked playable characters created in partnership between STAPLEVERSE and RHYMEZLIKEDIMEZ. Imagine a reality where the marriage of art and commerce is seamless, where creativity is the currency and collaboration the fuel that powers our collective evolution. This is not merely a vision of the future, but a tangible reality within your grasp with the SAPIENZ world. The goal is to build the next 100+ years of street culture, are you in?",
"image":"https://sapienz.imgix.net/rendered/3504.png?s=5d9251a2fe167597a1f5fbdf12e84ab3" } } } ] } }}
Developer Support
If you have any questions or need help regarding fetching ERC6551 token bound accounts data by NFTs, please join our Airstack's Telegram group.
The registry address of the ERC6551 account. This can be used to indicate the different versions of ERC6551 accounts.
This defaults to registry v.0.3.1.
implementation
0x55266d75D1a14E4572138116aF39863Ed6596E7F
The implementation address of ERC6551 account.
Defaulting implementation to the official standard ERC6551 implementation address.