πŸ’ŽAccount Versions

Learn how to use Airstack to fetch certain versions of token-bound (ERC6551) accounts.

Currently, Airstack indexes all the official ERC6551 registry contracts on Ethereum and Base:

If you are deploying ERC6551 using a custom registry contract, please reach out to us to add it to the Airstack API by joining our Telegram.

By default, ERC721 NFTs can have multiple versions of ERC6551 accounts controlled by it.

Using the registry filter that is provided in the Accounts API, you can fetch only certain versions of ERC6551 accounts that your dapp supports.

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 A Certain Version of ERC6551 Accounts

You can use the Accounts API to fetch certain version of the ERC6551 accounts, e.g. all v.0.3.1 ERC6551 accounts:

Try Demo

Code

query MyQuery {
  Accounts(
    input: {
      blockchain: ethereum,
      filter: {
        # set registry to v.0.3.1 registry address
        registry: {_eq: "0x000000006551c19487814612e58FE06813775758"}
      },
      limit: 200,
      order: {createdAtBlockTimestamp: DESC}
    }
  ) {
    Account {
      address {
        addresses
      }
      nft {
        address
        tokenId
        token {
          name
        }
        contentValue {
          image {
            medium
          }
        }
      }
    }
  }
}

Get A Certain Version of ERC6551 Accounts By NFT Collection

You can use the Accounts API to fetch certain version of the ERC6551 accounts of an NFT Collection, e.g. all v.0.3.1 ERC6551 accounts of Sapienz NFT:

Try Demo

Code

query MyQuery {
  Accounts(
    input: {
      blockchain: ethereum,
      filter: {
        # set registry to v.0.3.1 registry address
        registry: {_eq: "0x000000006551c19487814612e58FE06813775758"},
        # ERC721 NFT Collection address
        tokenAddress: {_eq: "0x26727ed4f5ba61d3772d1575bca011ae3aef5d36"}
      },
      limit: 200,
      order: {createdAtBlockTimestamp: DESC}
    }
  ) {
    Account {
      address {
        addresses
      }
      nft {
        tokenId
        contentValue {
          image {
            medium
          }
        }
      }
    }
  }
}

Get A Certain Version of ERC6551 Accounts Owned By A User

You can use the TokenBalances API to fetch certain version of the ERC6551 accounts owned by a user, e.g. all v.0.3.1 ERC6551 accounts owned by 0xjw.eth:

Try Demo

Code

query MyQuery {
  TokenBalances(
    input: {
      filter: {
        # Owner of ERC6551 accounts
        owner: {_eq: "0xjw.eth"},
        # Filter out only ERC721 NFTs
        tokenType: {_eq: ERC721}
      },
      blockchain: ethereum,
      limit: 200
    }
  ) {
    TokenBalance {
      tokenNfts {
        erc6551Accounts(
          input: {
            filter: {
              # set registry to v.0.3.1
              registry: {_eq: "0x000000006551c19487814612e58FE06813775758"}
            }
          }
        ) {
          address {
            addresses
          }
          nft {
            address
            tokenId
            token {
              name
            }
            contentValue {
              image {
                medium
              }
            }
          }
        }
      }
    }
  }
}

Developer Support

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

More Resources

Last updated

Was this helpful?