ERC-5298 · Stagnant · ERC · 2022-07-12
ERC-5298: ENS Trust to hold NFTs under ENS name
A 'trust' contract that holds NFTs on behalf of an ENS name, so tokens can be sent to someone's name even before they have a wallet, and whoever owns the name later claims them.
What problem does it solve?
To receive an NFT today you need a wallet address first, and the token is tied to that address. If you want to gift an NFT to alice.eth before she has set up a wallet, or tie ownership to a name rather than to a specific key, there is no standard way to do it.
ERC-5298 decouples NFT ownership from wallet addresses by letting a contract hold tokens for an ENS node. The current owner of that ENS name can later claim the token to any address.
How it works
A compliant "ENS trust" contract:
-
Accepts ERC-721 and ERC-1155 tokens by implementing the standard receiver hooks. The sender passes the target ENS node (namehash) in the
dataargument ofsafeTransferFrom, and the trust records the token under that node. -
Exposes one function:
function claimTo(address to, bytes32 ensNode, address operator, uint256 tokenId) external payable; -
claimToMUST check thatmsg.senderowns the ENS node (or is approved in an implementation-specific way), then callssafeTransferFromon the token contract to send the token toto.
Any ENS node is allowed. The spec does not define getters or setters for the ENS registry address or for listing holdings.
Sample code
A simplified ERC-721-only trust (illustrative, unaudited):
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
interface IENS { function owner(bytes32 node) external view returns (address); }
interface IERC721 { function safeTransferFrom(address, address, uint256) external; }
contract ENSTrust {
IENS public immutable ens;
// token contract => tokenId => ENS node it is held for
mapping(address => mapping(uint256 => bytes32)) public heldFor;
constructor(IENS _ens) { ens = _ens; }
function onERC721Received(address, address, uint256 tokenId, bytes calldata data)
external returns (bytes4)
{
require(data.length == 32, "data must be ENS node");
heldFor[msg.sender][tokenId] = bytes32(data); // msg.sender = token contract
return this.onERC721Received.selector;
}
function claimTo(address to, bytes32 node, address token, uint256 tokenId) external payable {
require(ens.owner(node) == msg.sender, "not ENS owner");
require(heldFor[token][tokenId] == node, "not held for node");
delete heldFor[token][tokenId];
IERC721(token).safeTransferFrom(address(this), to, tokenId);
}
}
Sending: nft.safeTransferFrom(me, trust, tokenId, namehash("alice.eth")).
Things to know
- Status: Stagnant. Security considerations in the spec are marked "Needs discussion".
- Whoever controls the ENS name controls the tokens. An expired, transferred or wrapped name changes who can claim; for wrapped names,
ENS.owner()returns the wrapper contract, so check how your implementation resolves ownership. - The spec's reference code warns against decoding raw
dataas a node in production; use a clearly typed encoding instead. - For giving an NFT its own account rather than tying it to a name, see ERC-6551.