Skip to content

Latest commit

 

History

History
355 lines (285 loc) · 9.53 KB

nft-owners.md

File metadata and controls

355 lines (285 loc) · 9.53 KB
description layout
Learn how to use Airstack to get token-bound (ERC6551) accounts by the owner of NFT that owns the accounts and vice versa.
title description tableOfContents outline pagination
visible
true
visible
true
visible
true
visible
visible
true

📭 NFT Owners

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:

Variables Default Value Description
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

  • An Airstack account
  • Basic knowledge of GraphQL
  • Basic knowledge of ERC6551

Get Started

JavaScript/TypeScript/Python

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

{% tabs %} {% tab title="npm" %} React

npm install @airstack/airstack-react

Node

npm install @airstack/node

{% endtab %}

{% tab title="yarn" %} React

yarn add @airstack/airstack-react

Node

yarn add @airstack/node

{% endtab %}

{% tab title="pnpm" %} React

pnpm install @airstack/airstack-react

Node

pnpm install @airstack/node

{% endtab %}

{% tab title="pip" %}

pip install airstack

{% endtab %} {% endtabs %}

Then, add the following snippets to your code:

{% tabs %} {% tab title="React" %}

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>;
  }
};

{% endtab %}

{% tab title="Node" %}

import { init, fetchQuery } from "@airstack/node";

init("YOUR_AIRSTACK_API_KEY");

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

const { data, error } = await fetchQuery(query);

console.log("data:", data);
console.log("error:", error);

{% endtab %}

{% tab title="Python" %}

import asyncio
from airstack.execute_query import AirstackClient

api_client = AirstackClient(api_key="YOUR_AIRSTACK_API_KEY")

query = """YOUR_QUERY""" # Replace with GraphQL Query

async def main():
    execute_query_client = api_client.create_execute_query_object(
        query=query)

    query_response = await execute_query_client.execute_query()
    print(query_response.data)

asyncio.run(main())

{% endtab %} {% endtabs %}

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.

Airstack AI (Demo)

Get Token Bound Accounts By NFT Owner Address

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

{% hint style="info" %} For non-deployed (optimistic) TBAs, it can be checked through some of the fields' value:

  • createdAtBlockNumber: -1
  • createdAtBlockTimestamp: null
  • creationTransactionHash: null {% endhint %}

Try Demo

{% embed url="https://app.airstack.xyz/query/5GhSQXiErE" %} Get Token Bound Accounts By NFT Owner Address (Demo) {% endembed %}

Code

{% tabs %} {% tab title="Query" %}

query MyQuery {
  TokenBalances(
    input: {
      filter: {
        owner: { _in: "0xa75b7833c78EBA62F1C5389f811ef3A7364D44DE" }
        tokenType: { _eq: ERC721 }
      }
      blockchain: ethereum
      limit: 200
    }
  ) {
    TokenBalance {
      tokenNfts {
        address
        tokenId
        erc6551Accounts {
          address {
            addresses
          }
          createdAtBlockNumber
          createdAtBlockTimestamp
        }
      }
    }
  }
}

{% endtab %}

{% tab title="Response" %}

{
  "data": {
    "TokenBalances": {
      "TokenBalance": [
        {
          "tokenNfts": {
            "address": "0x26727ed4f5ba61d3772d1575bca011ae3aef5d36",
            "tokenId": "0",
            // This NFT have 2 TBAs deployed on Ethereum mainnet
            "erc6551Accounts": [
              {
                "address": {
                  "addresses": [
                    "0x5416e5dc14caa0950b2a24ede1eb0e97c360bcf5"
                  ]
                },
                "createdAtBlockNumber": 17213826,
                "createdAtBlockTimestamp": "2023-05-08T05:53:59Z"
              },
              {
                "address": {
                  "addresses": [
                    "0xb5307cb1ae1385f64de8442d5d48ff86479f4f8c"
                  ]
                },
                "createdAtBlockNumber": 18467201,
                "createdAtBlockTimestamp": "2023-10-31T02:40:23Z"
              }
            ]
          }
        },
        {
          "tokenNfts": {
            "address": "0xa7d8d9ef8d8ce8992df33d8b8cf4aebabd5bd270",
            "tokenId": "207000185",
            "erc6551Accounts": [
              {
                "address": {
                  "addresses": [
                    // Non-deployed (Optimistic) TBA address
                    "0x062e978c4867df2ed10a3092234659829d44b9f1"
                  ]
                },
                "createdAtBlockNumber": -1, // This indicate that the TBA has not been deployed yet
                "createdAtBlockTimestamp": null
              }
            ]
          }
        },
        // Other ERC721 NFTs with their TBA address
      ]
    }
  }
}

{% endtab %} {% endtabs %}

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

{% embed url="https://app.airstack.xyz/query/dgS4j5UWyj" %} Get The Owner Of NFT That Owns A Given Token Bound Accounts Address {% endembed %}

Code

{% tabs %} {% tab title="Query" %}

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

{% endtab %}

{% tab title="Response" %}

{
  "data": {
    "Accounts": {
      "Account": [
        {
          "nft": {
            "tokenBalances": [
              {
                "owner": {
                  "addresses": ["0xcf94ba8779848141d685d44452c975c2ddc04945"]
                }
              }
            ]
          }
        }
      ]
    }
  }
}

{% endtab %} {% endtabs %}

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

Footnotes

  1. owner of NFT that owns the ERC6551 accounts