EIPs Explained

ERC-1046 · Final · ERC · 2018-04-13

ERC-1046: tokenURI Interoperability

Gives ERC-20 tokens an ERC-721-style tokenURI pointing to JSON metadata (name, description, images, icons) and adds an interop field so wallets can tell ERC-20, ERC-721 and ERC-1155 metadata apart.

What problem does it solve?

ERC-721 NFTs have tokenURI(id), which points to a JSON file with a name, description and image. ERC-20 tokens have nothing similar. Wallets and explorers end up relying on hand-maintained token lists to show a logo or a description, and they cannot easily tell from metadata alone what kind of token a contract is.

ERC-1046 brings the same metadata pattern to ERC-20, and adds a small shared interop object to ERC-20, ERC-721 and ERC-1155 metadata so one parser can handle all three.

How it works

ERC-20 extension. A compliant token adds one function with no arguments:

function tokenURI() external view returns (string memory);

The URI must resolve to JSON with these fields:

  • interop (required): { "erc1046": true } marks this as ERC-20 metadata.
  • name, symbol, decimals: optional. If the matching on-chain function exists and returns a value, the two must agree. decimals defaults to 18.
  • description: one plain-text paragraph.
  • image / images: images for the token. Bitmaps should be 320–1080 px wide.
  • icons: square icons with a transparent background.

ERC-721 and ERC-1155 extensions. Their existing metadata JSON should gain an interop field set to { "erc721": true } or { "erc1155": true }. ERC-1155 contracts may also expose tokenURI(uint256), which must return the same URI as uri(id).

To save gas, the spec recommends that new tokens skip the on-chain name(), symbol() and decimals() and keep those values only in the metadata. It also recommends leaving decimals out of the JSON when it is 18.

Sample code

An ERC-20 token's metadata file:

{
  "interop": { "erc1046": true },
  "name": "Example Token",
  "symbol": "EXT",
  "description": "A sample token used to illustrate ERC-1046 metadata.",
  "image": "ipfs://<cid>/banner.png",
  "icons": ["ipfs://<cid>/icon-512.png"]
}

Reading it with ethers v6:

import { Contract, JsonRpcProvider } from "ethers";

const provider = new JsonRpcProvider(process.env.RPC_URL);
const token = new Contract(tokenAddress, ["function tokenURI() view returns (string)"], provider);

const uri: string = await token.tokenURI();
const url = uri.startsWith("ipfs://") ? `https://ipfs.io/ipfs/${uri.slice(7)}` : uri;
const meta = await (await fetch(url)).json();
if (meta.interop?.erc1046) console.log(meta.name, meta.icons?.[0]);

Things to know

  • The extension is optional and fully backward compatible. Existing ERC-20 tokens are unaffected, and many tools will not yet look for tokenURI().
  • Leaving out name()/symbol()/decimals() saves gas, but tools that only read those functions will then show nothing. Weigh that before following the recommendation.
  • Security: fetching arbitrary URIs from a contract is a server-side request forgery risk. Wallets should allow only specific URI schemes and ports.
  • The spec chose a JSON interop field over ERC-165 checks, so a client can learn the token type from the metadata alone without extra calls.

#token #metadata #erc20 #nft #wallet

Details

Authors
Tommy Nicholas (@tomasienrbc), Matt Russo (@mateosu), John Zettler (@JohnZettler), Matt Condon (@shrugs), Gavin John (@Pandapip1)
Status
Final
Type
Standards Track / ERC
Created
2018-04-13
Requires
Required by

Machine-readable: Markdown · JSON