Metadata storage

Choose where token metadata lives and how your contract returns it

Your token URI can return metadata from a hosted URL, a decentralized network, or the contract itself.

Storage methodURI exampleNotes
Hosted JSONhttps://example.com/metadata/1.jsonHost the JSON on your own server or cloud storage.
IPFSipfs://bafy...Return an ipfs:// URI for metadata stored on IPFS.
Arweavear://example-transaction-idReturn an ar:// URI for metadata stored on Arweave.
Data URIdata:application/json;base64,...Return Base64-encoded JSON directly from the contract.
ERC-4804web3://example.eth/tokenJSON/1Resolve JSON through an EVM call.
ERC-8493onchain:application/json?key=metadata_uriRead JSON, or a single field, that the contract stores under ERC-8048.

IPFS and Arweave

For IPFS, return ipfs://<hash>, such as ipfs://QmTy8w65yBXgyfG2ZBg5TrfB2hPjrDQH3RCQFJGkARStJb.

For Arweave, return ar://<hash>, such as ar://jK9sR4OrYvODj7PD3czIAyNJalub0-vdV_JAg1NqQ-o.

Onchain metadata

For small collections or generative art, tokenURI or uri can return Base64-encoded JSON with a data:application/json;base64, prefix.

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

import "@openzeppelin/contracts/token/ERC721/ERC721.sol";
import "@openzeppelin/contracts/utils/Base64.sol";

contract OnchainMetadataExample is ERC721 {
    constructor() ERC721("Onchain Creature", "OCC") {
        _mint(msg.sender, 1);
    }

    function tokenURI(uint256 tokenId) public pure override returns (string memory) {
        require(tokenId == 1, "Nonexistent token");

        string memory json = Base64.encode(
            bytes("{\"name\":\"Onchain Creature #1\",\"description\":\"A fully onchain NFT stored in Base64 JSON.\"}")
        );

        return string.concat("data:application/json;base64,", json);
    }
}

Onchain metadata increases gas costs. Use it when the metadata is compact.

ERC-4804 web3:// URIs

OpenSea supports ERC-4804 web3:// URIs for NFT metadata. A web3:// URI can resolve an ENS name or contract address, an optional chain ID, a method call, and its arguments.

Return raw JSON from the target method when possible:

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;

contract MetadataResolver {
    function tokenJSON(uint256) external pure returns (string memory) {
        return "{\"name\":\"My NFT\",\"description\":\"...\",\"image\":\"...\"}";
    }
}

For example, web3://test4804nftsupport.eth/tokenJSON/0 resolves the ENS name on mainnet, calls tokenJSON(uint256) with 0, and parses the returned JSON. To call a contract on another chain, include its chain ID: web3://0xd4c5292b9689238f0a51c88505b1d1d6714ce95a0:8453/tokenURI/1.

OpenSea also supports a data URI returned from a web3:// endpoint for backward compatibility. Return raw JSON for new implementations because it avoids encoding one URI inside another.

If the target contract's resolveMode() returns "5219" (ERC-6944), OpenSea calls its ERC-5219 request() function instead. The path segments become the resource, the query becomes the params, and the body of a 200 response is used as the metadata.

ERC-8493 onchain: URIs

A field in your token's JSON can point at a value your contract stores under ERC-8048, using an onchain: URI from the ERC-8493 draft. OpenSea calls metadata(tokenId, key) on the token's contract and uses the returned bytes as the field's value.

{
  "name": "Onchain Creature #1",
  "image": "onchain:image/png",
  "animation_url": "onchain:text/html?key=animation",
  "attributes": [{ "trait_type": "Mood", "value": "onchain:?key=mood" }]
}
  • A top-level field reads the key named after it, so image above reads the key image. Add ?key= to read a different key.
  • A field inside an object or array, such as an attribute's value, must name its key with ?key=. Without one, OpenSea treats the field as absent.
  • Give media fields a media type, such as image/png or text/html. OpenSea treats untyped bytes in image or animation_url as application/octet-stream, which does not display.
  • Text fields such as name, description and attribute values are read as UTF-8 text when the media type is text/plain or left out.
  • If the call reverts or returns empty bytes, OpenSea treats the field as absent.
  • If the JSON has a top-level metadata_contract address, OpenSea reads from that contract instead, on the same chain.

An existing contract that can't add ERC-8048 can still use onchain: values. Deploy a separate metadata contract that implements metadata(tokenId, key) and stores the values, then add "metadata_contract": "0x…" at the top level of each token's JSON. OpenSea reads every onchain: value in that JSON from the metadata contract, with the same token ID. This works for any token whose JSON can still be edited, such as JSON served from your own server.

tokenURI or uri can also return an onchain: URI for the whole JSON document. It must name its key, and metadata_uri is the name ERC-8493 recommends:

function tokenURI(uint256) public pure override returns (string memory) {
    return "onchain:application/json?key=metadata_uri";
}

When you change a stored value, emit ERC-4906 MetadataUpdate for the token so OpenSea refreshes it. See Updating metadata.

OpenSea does not resolve onchain: URIs in contract-level metadata yet.