0Pricing
Web3 & DApp Development Fundamentals · レッスン

トークンメタデータ

tokenURIとJSON

「トークンメタデータ」はCoddyKit上の無料Web3 & DApp Development Fundamentalsレッスンです。 これはレッスン3/4です。 下記で完全なレッスンを無料で読むことができます。その後、ブラウザ内の組み込みコードエディタと24時間対応のAIチューターでハンズオン演習できます。 これはWeb3 & DApp Development Fundamentals学習パスの一部であり、ウェブとCoddyKitアプリ全体で進捗が同期されます。 Web3 & DApp Development Fundamentalsコースには全4レッスンが含まれています。

このレッスンの一部はまだ翻訳されておらず、英語で表示されています。

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

よくある質問

「トークンメタデータ」レッスンは無料ですか?

はい。「トークンメタデータ」の完全なテキストはこのウェブで無料で読めます。インタラクティブに演習し(組み込みコードエディタと24時間対応のAIチューター)、Web3 & DApp Development Fundamentalsコースの残りをアンロックするには、CoddyKit PROにアップグレードしてください。 Web3 & DApp Development Fundamentalsコースには全4レッスンが含まれています。

「トークンメタデータ」で何を学びますか?

tokenURIとJSON ブラウザで直接実行するハンズオンコードでWeb3 & DApp Development Fundamentalsを演習し、24時間対応のAIチューターがレッスンを進める中での質問に答えます。

Web3 & DApp Development Fundamentalsを始めるのに経験は必要ですか?

事前経験は必要ありません。CoddyKitのWeb3 & DApp Development Fundamentalsは初級者から上級者向けに構成されているため、ここから始めるか最初から始めて、自分のペースで進むことができます。 これはレッスン3/4です。

「トークンメタデータ」レッスンにはどのくらい時間がかかりますか?

ほとんどのCoddyKitレッスンは約5~10分かかります。各レッスンはコンパクトでインタラクティブなので、着実に進歩し、ウェブとアプリ全体で正確に前回の場所から再開できます。

このWeb3 & DApp Development Fundamentalsレッスンでコードを書いて実行できますか?

はい。すべてのWeb3 & DApp Development Fundamentalsレッスンに組み込みコードエディタが含まれているため、ブラウザでリアルコードを書いて実行し、即座のAIフィードバックを取得できます。ローカル設定は不要です。

このコースのすべてのレッスン

  1. ERC-721標準
  2. NFTのミント
  3. トークンメタデータ
  4. マーケットプレイス
← Web3 & DApp Development Fundamentalsに戻る