ERC-6066 · Final · ERC · 2022-11-29
ERC-6066: Signature Validation Method for NFTs
An ERC-1271-style isValidSignature(tokenId, hash, data) check that lets an NFT itself act as a signer, so authority can follow the token instead of a particular wallet.
What problem does it solve?
Wallets prove consent with ecrecover, and smart contract accounts do it with ERC-1271 isValidSignature(hash, signature). But there was no standard way for an NFT to sign.
That matters when an NFT represents a role. Imagine a DAO whose officer positions (CFO, COO…) are NFTs that change hands after each election. If the sitting CFO signs an agreement with their personal key, the signature stays with that person after they leave office. With ERC-6066, the signature belongs to the CFO token, so the office keeps its commitments when its holder changes. The spec also mentions wrapped ENS subdomains, which are NFTs, as natural signers for organisational hierarchies.
How it works
An ERC-721 or ERC-1155 contract may implement one function:
function isValidSignature(uint256 tokenId, bytes32 hash, bytes calldata data)
external view returns (bytes4 magicValue);
- It returns the magic value
0x12edb34fif tokentokenIdhas validly "signed"hash. - It must not modify state, and it may call other contracts to decide.
datais optional extra context, following the ERC-5750 pattern of a trailingbytesparameter for future extensibility.- Callers that support contract signatures must use this method when the signer is an NFT holder.
How a token comes to sign is deliberately left open, just as ERC-1271 does not mandate a signing scheme. The reference implementation follows the Gnosis Safe approach: the current owner calls sign(tokenId, hash), which stores an on-chain approval flag. The "signature" is therefore a recorded act of consent, not a cryptographic signature.
The magic value equals the ERC-165 interface ID of IERC6066, so the same constant is used for interface detection.
Sample code
Minimal signing NFT based on OpenZeppelin ERC-721:
// SPDX-License-Identifier: CC0-1.0
pragma solidity ^0.8.20;
import "@openzeppelin/contracts/token/ERC721/ERC721.sol";
interface IERC6066 {
function isValidSignature(uint256 tokenId, bytes32 hash, bytes calldata data)
external view returns (bytes4);
}
contract OfficeBadge is ERC721, IERC6066 {
bytes4 constant MAGIC = 0x12edb34f;
mapping(uint256 => mapping(bytes32 => bool)) private signed;
constructor() ERC721("Office", "OFC") {}
function sign(uint256 tokenId, bytes32 hash) external {
require(ownerOf(tokenId) == msg.sender, "not holder");
signed[tokenId][hash] = true;
}
function isValidSignature(uint256 tokenId, bytes32 hash, bytes calldata)
external view returns (bytes4)
{
return signed[tokenId][hash] ? MAGIC : bytes4(0xffffffff);
}
function supportsInterface(bytes4 id) public view override returns (bool) {
return id == type(IERC6066).interfaceId || super.supportsInterface(id);
}
}
Verifying from a dapp (ethers v6):
const ok = (await badge.isValidSignature(tokenId, digest, "0x")) === "0x12edb34f";
Things to know
- Status is Final.
- Contract-based signatures are revocable or changeable by design; a check that passed yesterday may fail today. Re-verify at the moment you rely on it.
- Signing authority follows the token. Selling or transferring the NFT transfers the power to sign future messages, so treat such tokens like keys.
- Because there is no cryptographic signature, verifiers must trust the NFT contract's logic; review it as carefully as a wallet contract.