ERC-7531 · Review · ERC · 2023-10-01
ERC-7531: Staked ERC-721 Ownership Recognition
Lets a staking pool or other holding contract declare who really holds the ownership or usage rights of an ERC-721 it has custody of, so staked legacy NFTs keep their perks.
What problem does it solve?
Many early NFTs, such as the CryptoPunks or Bored Ape examples the spec cites, have no built-in "lock" feature. To stake them, you must transfer them to the staking contract. From that moment, ownerOf returns the pool, not you. Gated events, airdrops, games and social verification that check ownerOf stop recognising you as the owner, even though you still own the NFT economically.
Newer designs keep the NFT in your wallet and lock it, but that requires the NFT contract itself to support locking, which older collections cannot add. ERC-7531 instead puts the burden on the holding contract: it announces who the real rights holder is.
How it works
The holding contract (staking pool, lending vault...) implements:
rightsHolderOf(tokenAddress, tokenId, right): returns the address that holds a given right over a token the contract currently holds. It must revert if the token does not exist or is not held.RightsHolderChange(tokenAddress, tokenId, holder, right): emitted in the same block as theTransferinto the contract or any later block. A laterTransferof that token automatically invalidates it, so no extra event is needed on unstake.
Rights are bytes4 ids. Two are standard:
| Right | Id |
|---|---|
bytes4(keccak256("ownership")) |
0x399d2b36 |
bytes4(keccak256("usage")) |
0x230a5961 |
"Usage" covers cases like lending: the borrower, not the lending contract, should be able to play with the NFT in a game.
An optional IERC7531Rights extension on the NFT contract (supportedERC7531Rights, supportsERC7531Right) lists which rights a collection cares about. If it is absent, apps should consider only the two standard rights.
Sample code
An app resolving the effective owner of an NFT (ethers v6):
import { Contract } from "ethers";
const OWNERSHIP = "0x399d2b36";
const nft = new Contract(nftAddress, ["function ownerOf(uint256) view returns (address)"], provider);
async function effectiveOwner(tokenId: bigint): Promise<string> {
const holder = await nft.ownerOf(tokenId);
// Is the current owner a contract that implements ERC-7531?
if ((await provider.getCode(holder)) === "0x") return holder;
const pool = new Contract(holder, [
"function rightsHolderOf(address,uint256,bytes4) view returns (address)",
], provider);
try {
return await pool.rightsHolderOf(nftAddress, tokenId, OWNERSHIP);
} catch {
return holder; // not ERC-7531 or token not tracked
}
}
Things to know
- Status: Review. Details may still change before Final.
- Any contract can emit
RightsHolderChange. When indexing events, accept one only if the emitting contract is the token's current owner per the latestTransfer. CallingrightsHolderOfon the actualownerOf(as above) avoids this problem. - You are trusting the pool to report correctly; a buggy or malicious pool can attribute rights to the wrong wallet.
- Compare ERC-7432, where roles are granted per NFT in a registry, and ERC-4907, which adds a "user" role inside the NFT contract itself.