ERC-4987 Custodied token ownership query interface (Held token interface)
Stagnant · Vaults & DeFi · created 2021-09-21
A lightweight interface that lets a contract holding deposited tokens, such as through staking, lending, or vesting, expose the actual owner and balance of those tokens for external queries.
Why it is needed
As DeFi and NFTs increasingly intersect, there is a growing split between the entity that actually holds a token (a contract) and the person who actually uses it (the user). For example, once a user stakes an NFT or deposits it as loan collateral, the contract becomes the token's official owner from that moment on. Because of this, systems that rely on ownership verification, such as governance voting, PFP authentication, or membership programs, no longer recognize that user as the owner. As a result, users are forced to choose between the benefits of depositing a token (interest, rewards, etc.) and the existing utility of holding it (voting rights, authentication, etc.). Without a standard way to resolve this, every custodial contract and every consuming system ends up building its own ad hoc integration.
What to implement
function heldBalanceOf(address tokenAddress, address owner) external view returns (uint256);: Queries the ERC20 balance held in custody by a specific owner for the given token address.function heldOwnerOf(address tokenAddress, uint256 tokenId) external view returns (address);: Queries the actual owner of a given tokenId from the contract holding it in custody.function heldBalanceOf(address tokenAddress, address owner) external view returns (uint256);: Queries the number of ERC721 tokens held in custody by a specific owner for the given token address.
In depth
Three token-specific interfaces and ERC165 identifiers
This standard defines three separate interfaces by token type: IERC20Holder, IERC721Holder, and IERC1155Holder. A contract implementing any of these interfaces must also implement ERC165, and calling supportsInterface must return true for 0x74c89d54 (ERC20), 0x16b900ff (ERC721), and 0xced24c37 (ERC1155) respectively. All three interfaces inherit from IERC165.
Behavior rules for heldBalanceOf and heldOwnerOf
heldBalanceOf takes tokenAddress and owner (and also tokenId for ERC1155) and returns the custodied balance; it should throw on an invalid query and return 0 if there is no balance. heldOwnerOf takes tokenAddress and tokenId and returns the address of the user who actually holds that token; it should throw on an invalid query and return the zero address if that tokenId is not in custody.
Hold and Release events
The Hold event is emitted when a token enters a contract and begins being held in custody, and the Release event is emitted when a custodied token is returned to a user. Both events have owner (functional owner) and tokenAddress as indexed parameters, and for ERC721 and ERC1155, tokenId is also indexed. ERC20 and ERC1155 additionally record tokenAmount.
Reason for the tokenAddress parameter
The tokenAddress parameter is included in most functions to support cases where a single custodial contract holds several different token contracts in custody at once. This parameter remains fully compatible with contracts that hold only a single token address, making it a more general design.
Why the interfaces are separated by token type
The logic for holding ERC20, ERC721, and ERC1155 is often independent of one another, so three separate interfaces are proposed. If a single contract holds multiple token types at once, it can implement each corresponding interface.
Compatibility with existing token standards
This standard is fully compatible with all existing ERC20, ERC721, and ERC1155 token contracts, and the token contracts themselves require no modification. However, the contract holding the tokens (the holder) must additionally implement this lightweight interface, and systems that consume this standard (such as governance) must also update their ownership-determination logic to account for it.
Chained lookup logic in the reference implementation
The reference implementation shows a consumer example for ERC721: it checks whether the address obtained from token.ownerOf(tokenId) is a contract, and if so, checks via ERC165 whether it supports IERC721Holder (0x16b900ff), then calls heldOwnerOf. If the return value is not the zero address, that value is used as the functional owner; otherwise, or if the interface is not supported, the original ownerOf result is treated as the owner.
Proposal status: Stagnant
This proposal is in Stagnant status, meaning active discussion or progress has stopped. It has not been finalized as a standard, so the content may change or be abandoned in the future.
Things to watch out for
- Do not trust ownership information from unknown contracts: A malicious actor could implement this interface while reporting false or manipulated ownership or balance information. This could be used to manipulate governance, games, membership programs, and similar systems, so information provided by unverified contracts should not be trusted as is.
- Separately verify the holding contract's total balance and ownership: Consuming systems should not simply trust the values returned by heldBalanceOf or heldOwnerOf, but should add a safeguard that independently confirms the actual total token balance and ownership held by the holding contract itself.