Home

tokenuri

TokenURI, commonly written tokenURI, refers to a function in NFT smart contracts that returns a URI pointing to a JSON metadata document for a given token ID. In the ERC-721 standard, tokenURI(uint256 tokenId) is part of the metadata extension and must return a string representing the location of the token’s metadata. The metadata document is typically a JSON object containing fields such as name, description, image, and attributes. The image field is usually a URL or an IPFS link to the media asset; attributes is an array of trait objects used for showcasing token characteristics.

The URI may use various schemes, including https, ipfs, or data URIs. When metadata is hosted off-chain,

Implementations may build tokenURI by concatenating a baseURI with the tokenId or by returning a full URI

See also: ERC-721, ERC-1155, metadata extension.

the
URI
serves
as
a
pointer
to
the
data,
allowing
metadata
to
be
updated
independently
of
the
contract.
To
improve
decentralization
and
immutability,
many
projects
store
metadata
on
IPFS
or
other
decentralized
storage.
ERC-1155
uses
a
different
approach:
a
base
URI
with
a
placeholder
{id}
that
can
be
replaced
by
the
token’s
ID.
stored
per
token.
Some
marketplaces
read
tokenURI
to
fetch
metadata
and
render
NFT
details.
The
specificity
of
tokenURI
is
not
enforced
beyond
returning
a
string;
the
format
of
the
metadata
is
defined
by
the
project.