How to directly interact with an NFT smart contract using Etherscan

2021-03-18

Want to better understand what’s happening under the hood with an Ethereum NFT? Here’s how to read your artwork’s metadata files and asset URLs directly from the blockchain using Etherscan.

First, find your NFT’s contract address (0xff..33) and tokenID (e.g. 420).

On OpenSea this is pretty easy:

On Foundation they link directly to the Etherscan page for the associated contract and tokenID:

Next, punch your contract address into Etherscan and click “Contract”

Peruse the code, nod thoughtfully to yourself, then switch to the “Read contract” tab. These are all of the methods this smart contract exposes publicly:

For NFT metadata we want the tokenURI method. Punch in your tokenID and press “Query”:

Congrats, you just queried data out of the Ethereum blockchain! With Ethereum you have to pay to write data (that’s the gas fee), but read operations are free.

That URL links to the the ERC-721 metadata for the NFT, which is usually stored as JSON:

This particular NFT’s metadata is hosted at https://api.artblocks.io/token/20000093 and the image is https://api.artblocks.io/image/20000093. Usually these are links to a distributed storage system like IPFS. For more about see my post IPFS and distributed storage for cryptoartists

Artblocks’ metadata includes a lot of fields, like copyright, aspect ratio, and more. Most NFT metadata is pretty thin and just includes image. Confusingly that is usually a link to a video, not an image, but here we are.

Using this Etherscan web interface, you are directly interacting with the Ethereum blockchain. This is exactly the same thing that all the NFT marketplace sites you’re browsing are doing–they’re all pulling data from the same public blockchain, like a giant shared database. When people get hype about web3, this is why. You can login to another site and all your data just comes with you. No more vendor lock.

Note that this won’t work out-of-the-box with every contract. Developers have published and verified the source code of their contract for Etherscan’s contract interface to work with it.

Some other important methods are symbol, tokenSupply, and transfer/safeTransfer, which are part of the ERC-20 and ERC-721 standards.

A dumb fun fact you can share at parties: tokenURI is actually an optional field, meaning images and assets aren’t built-in to the idea of an NFT at all. Enjoy!