📭NFT Owners

Learn how to use Airstack to get token-bound (ERC6551) accounts by the owner of NFT that owns 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:

VariablesDefault ValueDescription

registry

0x000000006551c19487814612e58FE06813775758

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.

salt

0

The ERC6551 account's salt.

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 By NFT Owner Address

You can fetch all the token bound accounts owned by a given address owner:

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 {
  TokenBalances(
    input: {
      filter: {
        owner: { _in: "0xa75b7833c78EBA62F1C5389f811ef3A7364D44DE" }
        tokenType: { _eq: ERC721 }
      }
      blockchain: ethereum
      limit: 200
    }
  ) {
    TokenBalance {
      tokenNfts {
        address
        tokenId
        erc6551Accounts {
          address {
            addresses
          }
          createdAtBlockNumber
          createdAtBlockTimestamp
        }
      }
    }
  }
}

Get The Owner Of NFT That Owns A Given Token Bound Accounts Address

You can find the owner of the NFT that owns a given TBA by using the Accounts API and providing the TBA address to the address fitler:

Try Demo

Code

query MyQuery {
  Accounts(
    input: {
      filter: { address: { _in: "0x9ff8faf2c61f50d24677e9cb5aaf988c91525539" } }
      blockchain: ethereum
    }
  ) {
    Account {
      nft {
        tokenBalances {
          owner {
            addresses
          }
        }
      }
    }
  }
}

Developer Support

If you have any questions or need help regarding fetching ERC6551 token bound accounts data by NFT owners, please join our Airstack's Telegram group.

More Resources

Last updated

Was this helpful?