ERC-8495: Token Metadata JSON Schema

This proposal specifies the JSON document that tokenURI returns in ERC-721 and ERC-6909 and that uri returns in ERC-1155.

Most deployed tokens already use this format, but only part of it was ever specified. ERC-721 and ERC-1155 define name, description and image. Everything else wallets and marketplaces show (animation_url, attributes and its display_type values, external_url, background_color) comes from a page OpenSea published in 2018. Clients fill the gaps differently, so the same token renders differently from one app to the next.

Draft: erc-8495.md (ethereum/ERCs#2163)

The draft covers:

  • Every field and its type, every display_type value in use, and what clients do with values that don’t match, such as booleans, quoted numbers and dates in milliseconds.
  • The URI schemes clients must resolve (https, ipfs, ar, data), the ones they may resolve (ipns, and web3 from ERC-4804), and the ones they must never resolve.
  • Fetching rules: ipfs:// URIs instead of gateway URLs, sandboxing HTML in animation_url, and keeping server-side fetches away from private addresses.
  • How later proposals add fields without breaking older clients.

The Rationale cites an October 2026 survey of 708 Ethereum and Base contracts. 113 of the 204 IPFS gateway URLs in it failed when fetched as written, and more contracts use text as a display_type than string. The draft accepts both.

Questions we’d like input on:

  1. Data URIs. The draft recommends base64, because fetch drops everything after # in an unencoded data URL, which breaks JSON that contains a #. Clients must accept base64 and should accept unencoded JSON, percent-decoding it exactly once as fetch does (updated after the discussion below). Is that the right line?
  2. Dates. Clients may read a date value of 1000000000000 or more as milliseconds. A lower cutoff would misread 253402300800 (the year 10000), which some contracts use to mean “never expires”.
  3. Onchain values. ERC-8493 (discussion) defines an onchain: URI scheme that points a field at a value stored under ERC-8048 or ERC-8049, such as "image": "onchain:image/png". OpenSea supports it in beta. This draft does not name it: “Clients MAY resolve other schemes” already allows it. If it proves out, it can be added in a later update or as an extension.

A companion extension adds a model_3d field that lists a token’s 3D files by format (glTF, USDZ, VRM, STL and others). We’ll post it separately and link it here.

Feedback from wallet, marketplace and indexer teams is the most useful: tell us anything your client does today that this draft would break.

Authors: Devin Finzer, Alex Atallah and Ryan Ghods

2 Likes

From the wallet support side: NFTs showing a blank image are a frequent source of “is my NFT gone?” questions. Having clients resolve ipfs:// links directly, instead of relying on the gateway URL baked into the metadata, seems like it would cut down a lot of those. When an image genuinely can’t load, a clear placeholder saying so would also help more than an empty tile.

On the data URI question, base64 as the SHOULD is fine. The percent-decode rule is the part that splits clients. fetch() percent-decodes the body of every non-base64 data: URL (the data: URL processor in the Fetch spec does it unconditionally), while “SHOULD percent-decode one that does not parse as written” only decodes when parsing fails. A payload like {"name":"a%22,%22image%22:%22https://x%22} parses as written, so a client that slices the string shows a name full of %22 and no image, and a fetch client gets a document with an image key. A contract that escapes quotes in a user-chosen name but leaves % alone can be fed exactly that, and the two kinds of client render different tokens. Percent-decoding exactly once, always, matches fetch and gives every client the same document.

Related: RFC 8259 leaves duplicate member names unpredictable. JSON.parse keeps the last one, serde rejects the object when it decodes into a struct, and onchain JSON assembled by string concatenation is where duplicates show up, a second image or animation_url after a field the minter controls. Saying a document with a duplicated top-level key is invalid, or that clients MUST take the last one, closes that gap.

@Anzus_GemWallet thanks, that matches what we see. Resolving ipfs:// directly fixes most blank images. A placeholder for media that won’t load is up to each client, so the spec leaves it out.

1 Like

@Zealynx agreed on both, and both are now in the draft (ethereum/ERCs#2163). Clients MUST percent-decode an unencoded data: payload exactly once before parsing, matching the Fetch Standard. OpenSea already does that. Producers MUST NOT repeat a member name, and clients MUST use the last value of a repeated member, which matches JSON.parse and common JSON libraries, so deployed tokens keep working.

A collection reveal could update the traits and artwork but keep the same image URL. The metadata update section tells wallets to fetch the JSON again, but they could still show the new traits alongside the old cached artwork. Could it clarify whether an update event should also refresh cached images when their URLs haven’t changed?

Thanks for putting this together. A specification for the metadata format that most tokens already use is long overdue, and the draft gets many of the hard details right. Here are a few points of feedback, based on my own test suites and knowledge of deployed collections. Feel free to treat them as you like.

SUBSTANTIVE: Raw JSON returned from tokenURI or uri

Section: Specification > Resolving URIs; Deployed forms

Issue. Some marketplaces (notably OpenSea) accept raw JSON returned from ERC-721 tokenURI or ERC-1155 uri. Both standards define the return value as a URI, so this behavior is unspecified and persists only because some clients tolerate it.

As a result, implementers currently have to guess. Some clients check for a leading { and parse the value, while others treat it as a malformed URI, so the same token renders in one product and fails in another. This is the kind of divergence the proposal aims to remove.

“Producers MUST use absolute URIs” already makes raw JSON non-conformant for producers, but only implicitly, and the draft does not specify client behavior. Raw JSON also differs from the existing deployed forms. ipfs://ipfs/<cid> or an object-valued attributes has a single unambiguous reading, whereas a non-URI string can only be identified as JSON heuristically.

Suggested text (Resolving URIs, new paragraph):

“A metadata URI that is not an absolute URI, such as raw JSON, is not conformant. Producers MUST NOT return raw JSON from tokenURI or uri. Clients SHOULD NOT process it as a metadata document. Producers that build metadata onchain SHOULD return it as a data:application/json;base64, URI.”

Alternative. If you prefer to keep such tokens readable, raw JSON could instead be listed under Deployed forms. In that case the ERC should also define how clients recognize it, so that every client applies the same heuristic.

SCOPE: ERC-1155 {id} substitution and deployed practice

Section: Specification > Resolving URIs

For ERC-1155 tokens, clients MUST apply ERC-1155’s {id} substitution to the metadata URI and to string values in the document.

Issue. ERC-1155 (Metadata) requires {id} to be replaced with the token ID in hexadecimal form: lowercase, without a 0x prefix, and zero-padded to 64 characters. In practice, most ERC-1155 collections that use {id} do not conform. They serve their documents at the decimal ID instead.

Data. I sampled Ethereum mainnet: every contract that emitted TransferSingle in 60 evenly spaced windows of 1,000 blocks, from block 6,500,000 (late 2018) to 26,404,722. About 16% of these contracts return a {id} template. Of the 323 whose servers still respond, 181 (56%) are non-conformant, almost all because only the decimal ID resolves. For IPFS directory templates (ipfs://<cid>/{id}) the proportion is 68%. A likely cause is that directories are uploaded with files named 1, 2, 3 and cannot be changed afterwards.

A client that implements the requirement as written therefore fails on a majority of these collections. A client that tries the hexadecimal form first and falls back to the decimal ID resolves 319 of the 323.

Question. This may well be out of scope, since the rule is defined by ERC-1155. However, the draft restates it as a client requirement, so if you consider it in scope, I would suggest taking an explicit position, for example:

Suggested text (Resolving URIs, new paragraph):

“Producers SHOULD return a complete URI from uri(uint256) rather than a {id} template. A producer that returns a template MUST serve the document at the hexadecimal form defined by ERC-1155.”

Suggested text (Deployed forms, new item):

“A {id} template whose documents are served only at the decimal token ID. When the hexadecimal URI does not resolve to a metadata document, clients SHOULD retry once with the decimal token ID.”

The dataset (contract, token ID, template, and the result of both lookups) is available on request.

TECHNICAL: Non-conformant data: URI used as an example

Section: Specification > Resolving URIs; Test Cases

Issue. The example of an unencoded payload, data:application/json;utf8,{"name":"Example"}, is not a valid URI. The characters {, } and " are not permitted unencoded (RFC 3986, Section 2), and ;utf8 is not a valid parameter, since RFC 2397 (Section 3) requires the form attribute=value, for example ;charset=utf-8. Clients accepting it is reasonable. However, because the Test Cases table lists it without qualification, readers may take it as an example of a conformant URI.

Suggested change (Test Cases, first table):

OLD:
| `data:application/json;utf8,{"name":"Example"}` | `{"name":"Example"}` |

NEW:
| `data:application/json,%7B%22name%22%3A%22Example%22%7D` | `{"name":"Example"}` |
| `data:application/json;utf8,{"name":"Example"}` | Not conformant. Read as `{"name":"Example"}` by clients that accept it. |

Suggested text (Resolving URIs, after the data URI paragraph):

“Producers that do not use base64 MUST percent-encode the payload.”

QUESTION: Fragment handling in unencoded data: URIs

Section: Specification > Resolving URIs; Rationale

Clients … MUST percent-decode an unencoded payload exactly once before parsing it, as the Fetch Standard does for data: URLs.

Issue. This fixes the decoding step, but it does not say whether clients also remove everything from the first # onwards, as the Fetch Standard’s data: URL processor does. Every parser has to make this choice, and the draft currently leaves it to each implementation.

The choice matters in practice because an unescaped # is very common in non-base64 payloads that are not percent-encoded correctly (the ;utf8, style). It appears in names such as Creature #42, as the Rationale notes, and above all in onchain SVG embedded in the JSON, where hex colors like fill="#ff0000" are everywhere. Meanwhile, a fragment on a data: URI can also be intentional, for example on an HTML animation_url.

A strict rule that follows Fetch cuts these payloads at the first #, so they fail to parse. A lenient rule keeps them readable but departs from what browsers do. In my view, letting those tokens break is acceptable, since they are non-conformant anyway. What matters is that the choice is made explicitly in the ERC, so that all clients break, or succeed, on the same tokens.

Question. Is this intentionally left unspecified? If not, I would suggest stating the rule and pinning it with a test case, for example for the strict reading:

Suggested text (Resolving URIs, after the data URI paragraph):

“Clients MUST remove the fragment, starting at the first #, before decoding an unencoded payload, as the Fetch Standard does. Producers MUST percent-encode # in an unencoded payload as %23.”

Suggested test case (Test Cases, first table):

| `data:application/json;utf8,{"name":"Creature #42"}` | Not conformant. The payload ends at `#` and does not parse. |

SECURITY: Integrity of content fetched through gateways

Section: Specification > Resolving URIs; Security Considerations

Issue. The draft permits clients to “fetch ipfs and ar content through any gateway”, and the Security Considerations rely on content addressing (“Content-addressed URIs change only when the contract returns a new one”). That property holds only if the content is verified. A gateway can return bytes that do not match the requested CID.

Suggested text (Security Considerations, new item):

“A gateway can return content that does not match the requested CID. Clients that fetch ipfs content through a gateway they do not operate SHOULD verify it against the CID, for example by requesting raw blocks or a CAR file from a trustless gateway, and SHOULD otherwise treat it as unverified.”

INFORMATIONAL: URIs in image_data

Section: Specification > Other fields; Deployed forms

A notable share of deployed tokens place a URI in image_data, likely because OpenSea has historically accepted URIs there. As image_data is already a legacy field, no change is necessary. If Deployed forms is intended to be exhaustive, this case could be added to it.

I have a few further minor comments (media type detection, IPFS gateway URLs as a deployed form, and additional test vectors) and can follow up on them separately if useful. I am also happy to open a PR against the draft for any of the suggested text above.

Also my take on your three questions:

  1. Data URIs. Yes, with the two additions above: producers that do not use base64 percent-encode the payload, and the ERC states whether clients remove a fragment before decoding.

  2. Dates. I would drop the millisecond reading. display_type: "date" already marks the value as a date, and the draft defines it in seconds, so a millisecond value is simply non-conformant. The cutoff itself is reasonable, but as a MAY it guarantees divergence: 1694173211000 shows as 2023 in one client and as the year 55656 in another. Either every client applies the rule or none does, and I would prefer none: the value is Unix seconds and is read as written. If you want to keep these tokens readable, make the rule a SHOULD so that clients at least agree.

  3. Onchain values. I would leave onchain out of this ERC, also after ERC-8493 is merged. “Clients MAY resolve other schemes” already allows it, so naming it adds no client behavior, only an endorsement, and it ties this ERC to a draft that can still change. Deployed tokens do not use it yet, and this ERC is strongest when it sticks to codifying what they already do. I have separate reservations about the scheme itself, which I will raise in the ERC-8493 thread later.

If by “an explicit date data type” you meant a new type for milliseconds (say, date_ms), say that directly.

Thanks for writing this down. The Deployed forms section alone will save client teams a lot of guesswork.

One case between the document and the contract. The Rationale says protocols that settle on a trait need an onchain source, and Security Considerations covers the trait offer. The same split shows up in plain display, when a contract implements an interface whose value the producer also writes as an attribute: a permanently locked ERC-8451 collection can still serve {"trait_type": "Transferable", "value": "Yes"}. A client that shows both presents two answers to the same question, and the draft does not say which one to trust.

Would you consider a line saying that, when an attribute conflicts with a value the contract exposes through an interface it reports via ERC-165, clients SHOULD show the onchain value?

@Revinand good point. Metadata updates now says a client that refetches a document on an update event should also refetch the media it references, even when the URI is unchanged, unless the URI is content-addressed.

@tokenfox thanks, this is very useful, the 1155 data especially. All of it is now in the PR:

  • Raw JSON from tokenURI is a deployed form, recognized only when the trimmed value begins with { and ends with }. OpenSea already reads it that way.
  • {id} templates served only at the decimal ID are a deployed form, with one decimal retry after the hexadecimal URI fails. OpenSea already does exactly that. Producers that use a template MUST serve the hex form.
  • The ;utf8, example is now listed as non-conformant, and producers that don’t use base64 MUST percent-encode the payload.
  • Fragments: clients keep any # in a metadata document’s payload. Cutting at the first # would break onchain SVG tokens that render today, and JSON has no use for a fragment. Creature #42 is a test case.
  • Gateway content SHOULD be verified against the CID, with a matching Security Considerations item.
  • URIs in image_data are a deployed form.
  • The millisecond date reading is a SHOULD, so clients agree. Dropping it would show deployed millisecond dates as the year 55656 everywhere.
  • onchain: agreed, “MAY resolve other schemes” already covers it, so it’s out. If it’s warranted later, it can come in an update or as an extension.

A PR for the minor items (media type detection, gateway URLs, test vectors) is welcome.

@antferr added: when an attribute conflicts with a value the contract reports through an interface it declares via ERC-165, clients SHOULD show the contract’s value.

1 Like

What counts as a failed lookup for the decimal ID retry? Suppose both paths serve valid but different metadata and the hex request times out. Should the wallet cache the decimal result or wait for a 404 on the hex path before it falls back?

2 Likes

Thanks. I can confirm that my earlier points are addressed.

On the minor items: I opened one PR, which lets clients read IPFS gateway URLs as ipfs URIs: Let clients read IPFS gateway URLs as ipfs URIs by tokenfox · Pull Request #1 · ryanio/ERCs · GitHub. Feel free to assess it separately.

On the name and scope: the title says this ERC is a JSON Schema for token metadata, but its scope is wider. More than half of its normative requirements are processing rules for clients: how to resolve and fetch URIs, how to read malformed input and deployed forms, and how to display content safely. The JSON Schema block itself defers to the text: “Where this schema differs from the text above, the text applies.”

I agree that these processing rules belong in this ERC. The title and description just don’t reflect them. I would suggest renaming it to something like Token Metadata Format and Processing, with the description:

Defines the JSON document that token URIs resolve to and how clients resolve, fetch, read, and safely display it.

If you’d rather keep the “JSON Schema” wording from ERC-721 and ERC-1155, Token Metadata JSON Schema and Processing also fits within the 44-character title limit for ERCs.

On the unescaped # in data: URIs: given the deployed forms, keeping the # makes sense, and we already agree that producers should encode it. But I’d like to spell out what this choice means for clients:

  1. General-purpose data: URI parsers don’t follow this rule. Every mainstream browser cuts the payload at the first #, and so does anything else that implements the Fetch Standard, Node.js’s built-in fetch included. For example, fetch('data:application/json,{"name":"Creature #42"}') returns {"name":"Creature. A client can’t hand a metadata data: URI to the platform’s URL parser or fetch. It needs its own parser for metadata documents.
  2. A client that follows ERC-8495 departs from the URI standards for these URIs, not only from Fetch:
    • RFC 3986, Section 3.5: the fragment is separated from the rest of the URI before it is dereferenced.
    • RFC 2397: the data part is made of URL characters, and an unescaped # is not one of them. It starts the fragment.
    • WHATWG URL Standard: the parser assigns everything after # to the fragment.
    • Fetch Standard, data: URL processor: the URL is serialized with the fragment excluded.
  3. The rule covers only data: URIs that carry a metadata document. A data: URI in image or animation_url still loses everything after # when a browser loads it. A client therefore reads the same kind of URI in two ways, depending on where it appears.

For a client that wants to show as many deployed tokens as possible, the rule you are proposing is a good call. But a client that also wants to follow the URI and Fetch standards can’t follow both for these URIs, and has to choose.

I’m not asking to change the rule. I’d only suggest that the draft say this outright, for example in Rationale or Backwards Compatibility: “Conforming clients cannot use a standard data: URL parser for metadata documents, and depart from RFC 3986, RFC 2397 and the URL and Fetch Standards here.” Then implementers know before they find out from a broken token.

@SergeevDmitry clients retry the decimal URI when the hex request fails for any reason, timeouts included, since this exists only to read deployed tokens. If the hex URI later resolves, it wins on the next refresh. Adding that.

@tokenfox thanks. Merged the gateway PR, renamed to “Token Metadata JSON Schema and Processing”, and added your data URI note to Backwards Compatibility.

2 Likes

@ryanio I tested the current draft against the token datasets and tooling known to me, and have a few updates to suggest. I’ll propose them in smaller batches to keep each diff small and so we can discuss each change separately. The first batch is four independent PRs:

  1. Processing a metadata URI (Specify metadata URI processing as ordered steps by tokenfox · Pull Request #2 · ryanio/ERCs · GitHub). The rules for turning a metadata URI into a document become one ordered procedure. It follows up on my post above about # in data: URIs. A client replaces every # with %23 and passes the result to the Fetch Standard’s data: URL processor. The # stays in the payload as now, but the departure from the URI standards shrinks to that one replacement, so clients can use fetch instead of writing their own parser. Purpose-written parsers already fail on deployed tokens: decodeURIComponent throws on the bare % in Sol Seedlings #499, and skipping the decode leaves Crypto Coasters #780’s nested animation_url unusable. The steps also say that a fetch that fails or returns a non-2xx HTTP status gives no document, which settles the edge of the decimal retry @SergeevDmitry asked about: a JSON error body is never taken as metadata.
  2. Gateway URLs as a SHOULD (Recommend reading IPFS gateway URLs as ipfs URIs by tokenfox · Pull Request #3 · ryanio/ERCs · GitHub). Reading IPFS gateway URLs as ipfs URIs goes from MAY to SHOULD. ipfs.io and dweb.link, the hosts in the current test cases, now answer non-browser requests with HTTP 429.
  3. IPFS path verification (Verify IPFS paths from the URI's CID by tokenfox · Pull Request #4 · ryanio/ERCs · GitHub). Verification starts from the CID in the URI and covers the blocks along its path. Checking the file against a CID the gateway reports accepts whatever the gateway sends.
  4. HTML in image (Do not render image as a document by tokenfox · Pull Request #5 · ryanio/ERCs · GitHub). Clients don’t render image as a document outside the animation_url isolation rules, and should treat a text/html image as absent.

Each PR has the evidence tokens in its description. They can be taken or dropped separately.

(And sorry for the formatting issues in my previous post, now fixed. This forum is still rather new to me.)

Thanks @tokenfox. I merged all four PRs into the ERC-8495 draft, including the ordered URI processing steps and IPFS path verification from the URI’s CID.

I clarified that {id} substitution happens before gateway rewriting. The IPFS lookup uses only the CID and path. If no gateway or node serves the content, clients should fall back to the original substituted URL. A verification failure rules out that fallback.

The 2xx check now applies to the final HTTP response after redirects, and the image rule explicitly covers both text/html and application/xhtml+xml.

I also checked all seven data: examples with Node’s fetch() after replacing # with %23. Each returned the expected text.

1 Like

@ryanio thanks for merging ryanio/ERCs#2 to #5, and for the follow-ups in 1e333657. The fallback and redirect wording is clearer than what I had.

Before suggesting anything else, I’d like to agree on where the proposal stops. I went back through everything left on my list with that in mind. Most of it either belongs in another proposal, or is already covered by the text or by the specs it cites. What’s left is one scope PR and one fix.

1. Scope

ryanio/ERCs#6 adds one sentence to the Specification:

This proposal does not define how clients obtain the metadata URI from a contract, the semantics of URI schemes beyond the rules given here, or content that a contract exposes outside the metadata document.

It also adds a Rationale bullet that says where those topics go instead. Neither changes a requirement. They make explicit what the definitions already imply, so later suggestions, mine included, have a line to be measured against. If you’d draw the line somewhere else, I’d rather settle that first.

2. What I’m leaving out

These fall outside that boundary. Some could become their own proposals that require this one:

  • Onchain metadata too costly to read. Where I Begin #1 needs about 3.4 billion gas for tokenURI, more than RPC providers allow for one eth_call. That is a contract interface question, and it comes before any URI exists.
  • A general model for URI schemes and storage systems, where each scheme states its mutability, verification and gateway forms. It would be the natural home for web3 (with ERC-6860 and ERC-7087) and for onchain: (ERC-8493), but it is too large for this proposal.
  • Content that contracts return from other functions, such as tokenHTML, Art Blocks getTokenHtml, or Zora’s tokenMetadataURI. Extensions add fields to the document, so they can’t describe these functions.
  • Diagnostic names for validators, and conformance classes. Both help tools more than tokens.
  • Attribute conflicts with transfer state that isn’t declared through ERC-165. No live token has a conflicting trait, and ERC-7496 already covers settlement.

Two things I raised in post #7 I’m also closing. I’m dropping media type detection: having drafted it, I think the existing fallback line is enough. The HTML and SVG rules apply however the type was determined, and since ryanio/ERCs#5, image is never rendered as a document. And I take it that leaving out “Producers SHOULD return a complete URI rather than a {id} template” was deliberate. The decimal retry already handles the practical problem, so I won’t press it.

3. One fix

ryanio/ERCs#7: # in media data URIs. Backwards Compatibility explains that a data URI in image or animation_url loses everything after an unencoded #, but it gives clients no way out. The PR adds that clients MAY replace every # with %23 in a media data URI before loading it, as step 4 already does for metadata. Like step 4, this departs from RFC 3986, so I think it needs the explicit permission. It’s a MAY because an SVG data URI could carry a real fragment. For a live case, Sol Seedlings #499’s image (data:image/svg+xml;utf8,<svg ... stroke='#fff' ...>) shows as a broken image in Chrome as written, and renders after the escape.

Once these are settled, I’m happy to do another round of cross-checks.

@tokenfox @ryanio one case that step 4 now breaks and plain fetch handles. In a base64 data URI a # can only start a fragment, since # isn’t in the base64 alphabet. Fetch drops the fragment and decodes fine, but after the replacement the processor percent-decodes %23 back to # inside the body, and forgiving-base64 decode fails on it. In Node 22, fetch(‘data:application/json;base64,eyJuYW1lIjoiRXhhbXBsZSJ9#x’) returns {“name”:“Example”}, and the same URI with %23x fails to fetch. So a base64 metadata URI with a fragment, which every fetch client reads today, comes out absent.

I’d only replace # when the URI is not base64, using the same ;base64 check the data: URL processor makes, and add that URI as a test case that reads as {“name”:“Example”}. The MAY in ryanio/ERCs#7 has the same issue for a base64 SVG image that carries #svgView(…), so it could take the same condition.

1 Like

Thanks @tokenfox and @Zealynx. I merged the scope clarification and media URI rule into the ERC-8495 draft.

Step 4 now escapes # only in non-base64 metadata URIs. Clients can do the same for non-base64 media, while base64 URIs keep their fragments intact.

I added the #x regression case and checked all eight metadata examples with Node’s fetch(). I also checked SVG media with a literal #fff color and a base64 SVG with a #svgView(...) fragment.