Find all NFTs owned by address

If you are building a marketplace, a wallet, a portfolio management or a gallery, most likely you will need an accurate and real-time data about NFTs that are being owned by an address, as well as NFT properties that are included in the NFT metadata (such as name, description, image, traits and other attributes).

To get all NFTs that are owned by an address on a blockchain at any given point in time would require indexing the entire blockchain, decoding logs emitted by each transaction in every block and counting every transfer event, andthen calculating ownership of every NFT. Missing a single transfer due to the network issues, chain reorg or a bug will lead to incorrect data and a failure to verify if a wallet truly owns a particular asset.

Additionally, it would require tracking every ERC721 and ERC1155 contract and NFTs on external resources like web servers, IPFs etc where the metadata is stored, which is a big challenge on its own.

Mnemonic solves this problem by providing accurate real-time ownership data and statistics about every address on the blockchain with a single call to the API.

Step 1: Use NFTs by the Owner endpoint to build the query

In the first step we will use a NFTs by the Owner endpoint that provides a snapshot of currently owned NFTs by a given address.

Copy
Copied
'https://ethereum.rest.mnemonichq.com/tokens/v1beta1/by_owner/0x3eb4b12127EdC81A4d2fD49658db07005bcAd065'

Step 2: Execute the query

For example, with cURL run the folloing command:

curlpython
Copy
Copied
curl -i -X GET \
'https://ethereum.rest.mnemonichq.com/tokens/v1beta1/by_owner/0x3eb4b12127EdC81A4d2fD49658db07005bcAd065' \
-H 'X-API-Key: YOUR_API_KEY_HERE'
Copy
Copied
import requests # requires `pip install requests`

result = requests.get(
    'https://ethereum.rest.mnemonichq.com/tokens/v1beta1/by_owner/0x3eb4b12127EdC81A4d2fD49658db07005bcAd065',
    headers={'x-api-key': 'YOUR_API_KEY_HERE'}
).json()

Note: Make sure to obtain and specify a valid API key in the request headers.

Step 3: Process the result

The results should look something like this

Copy
Copied
{
    "tokens": [
        {
            "contractAddress": "0x3e6046b4d127179f0a421f3148b43cf52c08fc41",
            "tokenId": "8526",
            "type": "TOKEN_TYPE_ERC721",
            "metadata": {
                "metadataUri": {
                    "uri": "ipfs://QmVbZhfYHDyttyPjHQokVHVPYe7Bd5RdUrhxHoE6QimyYs/8526",
                    "mimeType": "application/json"
                },
                "name": "You #8526",
                "description": "BFF's inaugural collection \"You\" celebrates the uniqueness of women and non-binary friends across our community and the world. Every NFT has unique perks built in, plus utility within the BFF universe.",
                "image": {
                    "uri": "ipfs://QmZkkoNaKp6PMv6wwy5YqsHvk3EkigUMvhgrmo3SaohZbP/8526.png",
                    "mimeType": "image/png"
                }
            },
            "quantity": "1"
        },
        {
            "contractAddress": "0x495f947276749ce646f68ac8c248420045cb7b5e",
            "tokenId": "36879996169960578461403022214606499702494133366280062521859522885222909607937",
            "type": "TOKEN_TYPE_ERC1155",
            "metadata": {
                "metadataUri": {
                    "uri": "https://api.opensea.io/api/v1/metadata/0x495f947276749Ce646f68AC8c248420045cb7b5e/0x5189568e4f38fb1c86e7288f016c8d3f9474c1dc000000000000030000000001",
                    "mimeType": "application/json"
                },
                "name": "Cryptokyo One",
                "description": "A figure seen by many but understood by few. Cryptokyo is an offshoot of my Tokyo Ginza gallery show.",
                "image": {
                    "uri": "https://lh3.googleusercontent.com/ULMtzdTiFQ4rJwlngj0Q4XuQlt7PR20dUwJ9ygL-ScNNjLJMuHUGeQBnj4tM-0mdl7VAopLUtZxg1Sy0K2pS8ql-V4o-yncOBHfsRw",
                    "mimeType": "image/png"
                }
            },
            "quantity": "1"
        },

        ...
        <trimmed>
    ]
}

There are more filters available to help refine the search results

  • contractAddress – filters the result based on a particular collection;
  • tokenTypes – filters the result based on specific token types (i.e. erc721, erc1155 etc);
  • limit and offset – controls the pagination;

After you completed this tutorial, let us know about your experience or if you have any feedback by tagging us on Twitter @mnemonichq or reaching out directly to our support@mnemonichq.com!