NFTs (Non-Fungible Tokens) are a way for digital artists to create and share, reaching a wider audience than traditional art markets, and remunerating digital creators. They have taken the Web3 space by storm over the past year, and we at Infura have loved being part of this momentum with the launch of the NFT SDK beta and IPFS API and gateway.
However, during the deprecation of our public gateway and API, in favor of an authenticated API and gateway - in which you can have your own unique subdomain - we have noticed that some NFT mints do not follow best practices.
This blog reiterates the need and reasoning behind not hard coding an HTTP gateway URL into the metadata.
Don't hard code a gateway URL into metadata
Uniform Resource Identifier vs. Uniform Resource Locator
Non-Fungible-Tokens (NFTs) consist of two key features: a unique identifier and off-chain metadata. The combination of these is what makes the artwork unique and verifiable.
What makes it unique and verifiable in the IPFS network is the Content Identifier or CID. This is because the CID is a hash of the exact contents of the content of the NFT (Image, audio, in-game character, etc.) If the content changes, even slightly, the hash changes.
This is because the IPFS network makes use of content addressing via the CID, rather than location-based addressing like in Web2. Using the unique CID, the content of an NFT can be located anywhere on the IPFS network, as long as one node running IPFS is storing it.
In other words, to identify your NFT stored on IPFS within the metadata, without tying it inextricably to a gateway provider, the best practice is to use a Uniform Resource Identifier (URI) and not a Uniform Resource Locator (URL). Remember, Web3 and Web2 run on different protocols.
There are, of course, times when a URL is useful. For example, sharing links to access content when you are unsure whether the person you want to share it with uses a browser that supports IPFS by default.
If you copy and paste: ipfs://bafybeigdyrzt5sfp7udm7hu76uh7y26nf3efuylqabf3oclgtqy55fbzdi into a Chrome browser tab you will see a set of Google search results.
If you download Brave Browser and copy and paste the same URI, it will resolve to the content behind it.
An example of a URL which does resolve in a Chrome tab is: https://ipfs.io/ipfs/bafybeigdyrzt5sfp7udm7hu76uh7y26nf3efuylqabf3oclgtqy55fbzdi. This uses a public gateway run by Protocol Labs.
Here is a list of the public gateways available for IPFS.
What does this mean?
- Do not hardcode a URL into an NFT metadata you wish to store using IPFS (or any decentralized storage network) - use a URI of the form above. This will mean that your content will persist and be retrievable on the IPFS network if there is at least one copy available. Get into the practice of tying NFT content to the CID, not to a location
- Consider adding support in your smart contract for the URI of the tokens to be changed after it’s minted; this will future-proof your content. See below.
What you can do within your NFT metadata to update URI with CID
There are many reasons why someone might want to amend the metadata for an NFT: you could be making a game character whose attributes evolve; the NFT could represent ownership of a property whose residents naturally change over time, and so on. As such, the metadata may need to change. ERC-721 doesn’t come with an updateable URI as a standard, but as long as all the compulsory methods are implemented from the standard specification, modifications can be made, including the ability to edit the metadata.
What we have done since we deprecated the public gateway and API
- We have set up a redirect to go to the ipfs.io/ gateway. If your project contains a hardcoded URL instead of the preferred URI we have set up a redirect that preserves the HTTP query parameters
We will redirect for Paths:
And for Subdomains:
2. We pride ourselves in our infrastructure’s ability to broadcast CIDs to the network. Your pins are still on the IPFS network and you can find with any of the public gateways remember to add /ipfs/<CID> or…
3. Set up an account with Infura and set up a dedicated gateway with your own subdomain to make content available to your customers via the IPFS network
4. And of course, you can also run your own node!