---
eip: 2477
label: ERC-2477
title: Token Metadata Integrity
status: Stagnant
type: Standards Track
category: ERC
created: 2020-01-02
requires: 165, 721, 1155
official: https://eips.ethereum.org/EIPS/eip-2477
source: https://github.com/ethereum/ERCs/blob/master/ERCS/erc-2477.md
canonical: https://eips.huatuo.xyz/eip-2477/
lang: en
tldr: "Lets NFT and multi-token contracts publish a hash of each token's metadata (and its schema) on-chain, so clients can detect if the off-chain JSON was changed or tampered with."
tags: [nft, metadata, integrity, erc]
---

# ERC-2477: Token Metadata Integrity

> This specification defines a mechanism by which clients may verify that a fetched token metadata document has been delivered without unexpected manipulation.

**TL;DR:** Lets NFT and multi-token contracts publish a hash of each token's metadata (and its schema) on-chain, so clients can detect if the off-chain JSON was changed or tampered with.

## What problem does it solve?

[ERC-721](/eip-721/) and [ERC-1155](/eip-1155/) tokens point to their metadata with a URI. In practice most of those URIs are ordinary HTTPS URLs. Whoever controls the server can change the name, description or image of a token at any time, and a wallet or marketplace has no way to notice.

ERC-2477 borrows the idea of the web's **Subresource Integrity (SRI)**: alongside the URI, the contract exposes a cryptographic digest of the document. A client fetches the JSON, hashes it, and compares. If the hashes differ, the content was changed after the digest was published.

## How it works

The contract implements two view functions (ERC-165 interface ID `0x832a7e0e`):

| Function | Returns |
| --- | --- |
| `tokenURIIntegrity(tokenId)` | `(bytes digest, string hashAlgorithm)` of the metadata document |
| `tokenURISchemaIntegrity(tokenId)` | `(bytes digest, string hashAlgorithm)` of that document's JSON schema |

For ERC-721, `tokenURIIntegrity(21)` covers the document at `tokenURI(21)`; for ERC-1155 it covers `uri(16)`. Either value may be empty (`""`) when not available.

Key rules:

- The contract **must** also implement [ERC-165](/eip-165/).
- Any hash algorithm may be used, but every client **must** support `sha256`. SHA-384/512 are optional because they are expensive on-chain.
- Metadata may additionally carry `$schema` plus a `$schemaIntegrity` object (`digest`, `hashAlgorithm`) to pin its schema from inside the document.
- Emitting an event when the integrity value changes is allowed but not required.

The spec walks through several designs, from "hash only the metadata" to "hash both the metadata and the schema on-chain and in the document". Any change to a protected document requires updating the corresponding on-chain digest.

## Sample code

A minimal ERC-721 extension storing a SHA-256 digest per token:

```solidity
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;

interface IERC2477 {
    function tokenURIIntegrity(uint256 tokenId)
        external view returns (bytes memory digest, string memory hashAlgorithm);
    function tokenURISchemaIntegrity(uint256 tokenId)
        external view returns (bytes memory digest, string memory hashAlgorithm);
}

abstract contract MetadataIntegrity is IERC2477 {
    mapping(uint256 => bytes32) internal _metadataSha256;

    function tokenURIIntegrity(uint256 tokenId)
        external view returns (bytes memory, string memory)
    {
        bytes32 d = _metadataSha256[tokenId];
        if (d == bytes32(0)) return ("", "");
        return (abi.encodePacked(d), "sha256");
    }

    function tokenURISchemaIntegrity(uint256)
        external pure returns (bytes memory, string memory)
    {
        return ("", ""); // schema integrity not provided
    }
}
```

Verifying from a client (ethers v6, Node.js):

```ts
import { Contract, sha256, toUtf8Bytes, hexlify } from "ethers";

const nft = new Contract(address, [
  "function tokenURI(uint256) view returns (string)",
  "function tokenURIIntegrity(uint256) view returns (bytes, string)",
], provider);

const [uri, [digest, algo]] = await Promise.all([nft.tokenURI(id), nft.tokenURIIntegrity(id)]);
const body = await (await fetch(uri)).text();      // hash the exact bytes served
if (algo === "sha256" && sha256(toUtf8Bytes(body)) !== hexlify(digest)) {
  throw new Error("metadata does not match on-chain digest");
}
```

## Things to know

- **Status: Stagnant.** It has not progressed to Final and wallet/marketplace support should not be assumed.
- Hash the exact bytes served. Re-serialising the JSON (different whitespace or key order) changes the digest.
- Integrity is not immutability: the owner can still update the on-chain digest. It only makes changes detectable.
- Content-addressed URIs (for example IPFS CIDs) or on-chain `data:` URIs give similar guarantees without an extra function.
- Although the header lists ERC-721 and ERC-1155 as required, the approach works with any token that exposes a metadata URI.


---

This is an unofficial plain-language summary. Read the full specification: https://eips.ethereum.org/EIPS/eip-2477
