Indexing NFTs for Wallets

Josh Itzkovitz (0xskittles.eth)
SimpleHash
Published in
4 min readAug 10, 2022

Non-fungible token (NFT) technology has taken the world by storm, gaining global attention from crypto natives and newcomers alike. Its soaring popularity has propelled innovative means for exhibiting digital art and assets. It’s still early days however: developers are building and experimenting with new types of applications throughout the space, taking advantage of the technology’s potential.

For most use cases, NFT developers must quickly retrieve all the needed information from a specific blockchain for a given set of NFTs. Here are a couple of examples using existing applications:

Mobile wallets

Wallet applications typically query a user’s public address, to obtain a list of their owned NFTs and associated metadata, which is then beautifully displayed.

Marketplaces and aggregators have similar NFT retrieval needs.

Marketplaces and aggregators have similar NFT retrieval needs.

However, as the space is nascent, it’s not necessarily easy for developers to ingest NFT data into their apps. And there are some important differences between developing for web2 to web3 applications to consider.

Content-based addressing

To simplify, in most web2 applications, a physical address, most commonly a URL, usually points to a resource on a remote location or website. The familiar Internet file system is sometimes referred to as location-based addressing; for example, an image on abc123.com could be addressed as:

www.abc123.com/image.jpeg.

However, if the server that stores image.jpeg goes offline, you cannot access the file anymore. Thus, whoever controls the location controls the content.

In Web3, distributed storage systems (e.g., IPFS or Arweave) are often used to overcome this issue, sometimes called content-based addressing. Instead of identifying content using its location, we use its cryptographic hash, which never changes. This decentralized storage method increases the durability, the integrity and the security of stored data. It only takes the presence of node(s) on a given network for its content to be universally available.

Nevertheless, content-based addressing comes with a unique set of challenges. Each NFT has a unique ID that distinguishes it from any other token living on (a given) blockchain, thus making it truly non-fungible. While it’s relatively straightforward to find a specific token id, more advanced queries, such as aggregation, and keeping track of ownership changes, require the processing the history of the events emitted by a smart contract.

NFTs usually link to media and metadata outside of their hosted blockchain networks, as file storage on most blockchains is extremely expensive. Storing one gigabyte of data on the Ethereum network costs on the order of 35 million USD.

This complicates things further, as this off-chain media and metadata needs to be retrieved along with the on-chain data, when applications make their queries.

SimpleHash makes it easy

SimpleHash takes care of these challenges, by querying, storing, and indexing NFT metadata, and media (which is cached on our CDN), and keeping it up to date with new mints, ownership changes, and metadata updates. This saves developers a huge amount of time. Instead of building out their own indexing infrastructure, or querying multiple independent data sources with each request (which can be very slow), we serve up NFT data ready to be embedded into user-facing apps. Plus, we standardize the schema across chains, and take care of the edge cases involved.

As a simple example, our NFTs by Wallet endpoint allows any developer to pass a specific user’s public address, and to get back the metadata of NFTs held by them.

The endpoint supports querying multiple networks and wallets simultaneously; to supply multiple values, provide them comma separated in the query params, (e.g., chains=polygon,ethereum&wallet_addresses=0xa12,0xb34). (As of mid May 2022, we’re currently live on Ethereum mainnet, Polygon, Optimism and Arbitrum).

Here’s a quick example of a request using two blockchain networks (Ethereum and Polygon):

curl --request GET \\
--url '<https://api.simplehash.com/api/v0/nfts/owners?chains=polygon,ethereum&wallet_addresses=0xfa6E0aDDF68267b8b6fF2dA55Ce01a53Fad6D8e2>' \\
--header 'Accept: application/json' \\
--header 'x-api-key: sh_sk1_BjNhW3DDE7ev'

By default, the endpoint will return all the NFTs and associated metadata per asset held by the wallet address: 0xfa6E0aDDF68267b8b6fF2dA55Ce01a53Fad6D8e2 in the current example.

We offer dozens of ways to query NFT data in addition to this endpoint — you can read the API docs for an in-depth documentation with live example curl widgets of our endpoints, so you can them out yourself!

Before you start building, you’ll need to grab an API key here.

We’d love to know what you’re creating using the SimpleHash API. Tell us on Twitter! It’s also the best way to stay up-to-date with new feature implementations and optimizations. Stay tuned to this blog for more explanations and deep dives into NFT data and infrastructure.

--

--