0Pricing
Web3 & DApp Development Fundamentals · Lesson

Token Metadata

tokenURI and JSON.

Token Metadata is a free Web3 & DApp Development Fundamentals lesson on CoddyKit — lesson 3 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Web3 & DApp Development Fundamentals learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.

What Is Token Metadata?

Metadata describes what an NFT actually represents: its name, description, image, and attributes. While ownership is stored on-chain, the descriptive data usually lives off-chain in a JSON file.

The link between them is the tokenURI.

The tokenURI Function

The metadata extension defines tokenURI(tokenId), which returns a URL pointing to the JSON metadata for that specific token.

<code>function tokenURI(uint256 tokenId) external view returns (string memory);</code>

The Metadata JSON Schema

The standard JSON has a few well-known fields. Marketplaces like OpenSea read these to display the NFT.

<code>{
  'name': 'Cool Cat #42',
  'description': 'A very cool cat.',
  'image': 'ipfs://Qm.../42.png',
  'attributes': [
    { 'trait_type': 'Color', 'value': 'Blue' }
  ]
}</code>

Attributes and Traits

The attributes array lists traits as objects with trait_type and value. These power rarity rankings and filtering on marketplaces.

<code>'attributes': [
  { 'trait_type': 'Background', 'value': 'Sky' },
  { 'trait_type': 'Level', 'value': 5 }
]</code>

Per-Token URIs

One approach stores a unique URI per token in a mapping. This is flexible but uses more storage.

<code>mapping(uint256 => string) private _tokenURIs;

function tokenURI(uint256 id) public view returns (string memory) {
    return _tokenURIs[id];
}</code>

Base URI Pattern

A cheaper approach stores a single base URI and appends the token id. This works when files are named sequentially like 1.json, 2.json, and so on.

<code>string private baseURI = 'ipfs://QmFolder/';

function tokenURI(uint256 id) public view returns (string memory) {
    return string(abi.encodePacked(baseURI, _toString(id), '.json'));
}</code>

Why IPFS?

Hosting metadata on a normal server is risky: if the server goes down or the file changes, the NFT breaks. IPFS uses content-addressed hashes, so a URI like ipfs://Qm... always points to the exact same immutable content.

Content Addressing

An IPFS hash (CID) is derived from the file's content. Change one byte and the hash changes. This guarantees the metadata cannot be silently swapped, preserving the NFT's integrity.

<code>// image: 'ipfs://bafybeih.../art.png'
// the CID itself proves the content is unaltered</code>

On-Chain Metadata

For fully decentralized NFTs, you can store metadata entirely on-chain by returning a base64-encoded data URI. This costs more gas but removes any off-chain dependency.

<code>// returns: data:application/json;base64,<encoded JSON>
// fully on-chain, no IPFS or server needed</code>

Reveal Mechanics

Many drops mint with a placeholder URI, then switch the base URI after sale to reveal the real art. This prevents buyers from sniping rare traits before mint.

<code>bool public revealed = false;

function setRevealed() public onlyOwner {
    baseURI = 'ipfs://QmRealArt/';
    revealed = true;
}</code>

How Marketplaces Read It

A marketplace calls tokenURI(id), fetches the returned JSON, then loads the image and renders attributes. Following the standard schema is what makes your NFT display correctly everywhere.

Quick Check

Test your understanding of token metadata.

Recap

You learned about NFT metadata:

  • tokenURI(id) returns a link to the token's JSON metadata
  • The JSON holds name, description, image, and attributes
  • Use per-token URIs or a base URI + id pattern
  • IPFS content addressing keeps metadata immutable; on-chain metadata removes dependencies entirely
  • Reveal patterns hide art until after mint

Frequently asked questions

Is the “Token Metadata” lesson free?

Yes — the full text of “Token Metadata” is free to read here on the web, and the Web3 & DApp Development Fundamentals course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Web3 & DApp Development Fundamentals course, upgrade to CoddyKit PRO.

What will I learn in “Token Metadata”?

tokenURI and JSON. You practise Web3 & DApp Development Fundamentals with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start Web3 & DApp Development Fundamentals?

No prior experience is required. Web3 & DApp Development Fundamentals on CoddyKit is structured for beginners through advanced learners; this is — lesson 3 of 4, so you can start here or from the beginning and move at your own pace.

How long does the “Token Metadata” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this Web3 & DApp Development Fundamentals lesson?

Yes. Every Web3 & DApp Development Fundamentals lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. The ERC-721 Standard
  2. Minting NFTs
  3. Token Metadata
  4. Marketplaces
← Back to Web3 & DApp Development Fundamentals