â™Ļī¸NFTs

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:

Pre-requisites

Get Started

JavaScript/TypeScript/Python

If you are using JavaScript/TypeScript or Python, Install the Airstack SDK:

React

npm install @airstack/airstack-react

Node

npm install @airstack/node

Then, add the following snippets to your code:

import { init, useQuery } from "@airstack/airstack-react";

init("YOUR_AIRSTACK_API_KEY");

const query = `YOUR_QUERY`; // Replace with GraphQL Query

const Component = () => {
  const { data, loading, error } = useQuery(query);

  if (data) {
    return <p>Data: {JSON.stringify(data)}</p>;
  }

  if (loading) {
    return <p>Loading...</p>;
  }

  if (error) {
    return <p>Error: {error.message}</p>;
  }
};

Other Programming Languages

To access the Airstack APIs in other languages, you can use https://api.airstack.xyz/gql as your GraphQL endpoint.

🤖 AI Natural Language​

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.

Try Demo

Code

query MyQuery {
  Accounts(
    input: {
      filter: {
        tokenAddress: { _in: ["0x26727ed4f5ba61d3772d1575bca011ae3aef5d36"] }
      }
      blockchain: ethereum
      limit: 200
    }
  ) {
    Account {
      address {
        addresses
        domains {
          name
          isPrimary
        }
        socials {
          dappName
          profileName
          profileTokenId
          profileTokenIdHex
          userId
          userAssociatedAddresses
        }
      }
    }
  }
}

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

query MyQuery {
  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
        }
      }
    }
  }
}

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.

Try Demo

query GetOptimisticWithCustomParameters {
  TokenNfts(
    input: {
      filter: { address: { _eq: "0x23581767a106ae21c074b2276D25e5C3e136a68b" } }
      blockchain: ethereum
    }
  ) {
    TokenNft {
      erc6551Accounts(
        input: {
          filter: {
            # Your custom implementation address
            implementation: {
              _eq: "0x2d25602551487c3f3354dd80d76d54383a243358"
            }
            # Your custom registry address
            registry: { _eq: "0x02101dfB77FDE026414827Fdc604ddAF224F0921" }
            # Your salt number
            salt: { _eq: "0" }
          }
          showOptimisticAddress: true
          limit: 200
        }
      ) {
        implementation
        registry
        salt
        createdAtBlockNumber
        createdAtBlockTimestamp
        creationTransactionHash
        address {
          # Optimistic TBA address
          addresses
        }
      }
    }
  }
}

Get Token Bound Accounts By Specific NFT

You can get all the token bound accounts given by a specific NFT with contract address tokenAddress and token ID tokenId:

You can fetch cross-chain ERC6551 accounts, by specifying the blockchain to a different chain to where the token address is deployed.

Try Demo

Code

query MyQuery {
  Accounts(
    input: {
      filter: {
        tokenAddress: { _eq: "0x26727ed4f5ba61d3772d1575bca011ae3aef5d36" }
        tokenId: { _eq: "1" }
      }
      blockchain: ethereum
      limit: 200
    }
  ) {
    Account {
      address {
        addresses
        domains {
          name
          isPrimary
        }
        socials {
          dappName
          profileName
        }
      }
    }
  }
}

Get Owner NFT of a Token Bound Account

You can get the owner NFT of a specific token bound account address:

Try Demo

Code

query MyQuery {
  Accounts(
    input: {
      blockchain: ethereum
      filter: { address: { _in: "0xa1afb6a11ef500229538bfb38d5a0b8c1b61b425" } }
    }
  ) {
    Account {
      nft {
        address
        metaData {
          name
          description
          image
        }
      }
    }
  }
}

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.

More Resources

Last updated

Was this helpful?