Introduction

Hi, I'm cardene, a software engineer and technical writer focused on blockchain and AI.

I've also authored Japanese technical books on specification-driven development with LLMs and decentralized application (DApp) development.

I also build and publish a variety of tools, libraries, and open-source projects.

ERC-4987 proposes a way to query the token balances attributable to individual users when ERC-20, ERC-721, or ERC-1155 tokens are held by a smart contract.

This article translates, summarizes, and expands on the following proposal.

More EIP explainers:

Overview

ERC-4987 defines interfaces through which a contract can expose information about the ownership and balances of tokens it holds.

Ordinarily, the owner recorded by a token contract is an externally owned account or a contract account. ERC-4987 distinguishes the actual token holder (the custody contract) from the functional owner (the user to whom the held tokens are attributed).

These interfaces allow on-chain and off-chain applications to query who the functional owner is and how many tokens are held on that user's behalf.

Functional ownership in this context is an accounting relationship reported by the holder contract. The interface does not itself establish legal ownership or grant withdrawal or transfer permissions.

Motivation

DeFi and NFT applications increasingly rely on contracts that hold tokens on behalf of users. This creates an interoperability problem.

  • Staking and lending protocols may require users to deposit their tokens into a contract.
  • Once deposited, those tokens are no longer recorded as belonging directly to the user's wallet. Applications that check wallet balances alone may therefore exclude the user from governance, membership, or other token-based features.

ERC-4987 provides a common way to identify functional ownership even when a contract is the actual holder.

Applications can use this information to recognize tokens deposited in staking or lending contracts, subject to their own eligibility rules. This can improve composability between protocols and reduce the need for application-specific integrations.

Example applications

The proposed interfaces can support applications that need to identify functional token owners or query their balances.

  • Governance systems, such as determining voting eligibility.
  • Blockchain games, such as identifying character ownership.
  • PFP authentication, such as linking profile pictures to NFT ownership.
  • Art galleries and showcases, such as identifying the user associated with an exhibited work.
  • Token-based membership programs, such as restricting features to eligible holders.

Specification

Common requirements

Each interface extends IERC165. Implementations must return true from supportsInterface for the applicable interface identifier.

Token standard Interface Interface ID
ERC-20 IERC20Holder 0x74c89d54
ERC-721 IERC721Holder 0x16b900ff
ERC-1155 IERC1155Holder 0xced24c37

IERC20Holder

IERC20Holder.sol
/**
 * @notice the ERC20 holder standard provides a common interface to query
 * token balance information
 */
interface IERC20Holder is IERC165 {
  /**
   * @notice emitted when the token is transferred to the contract
   * @param owner functional token owner
   * @param tokenAddress held token address
   * @param tokenAmount held token amount
   */
  event Hold(
    address indexed owner,
    address indexed tokenAddress,
    uint256 tokenAmount
  );

  /**
   * @notice emitted when the token is released back to the user
   * @param owner functional token owner
   * @param tokenAddress held token address
   * @param tokenAmount held token amount
   */
  event Release(
    address indexed owner,
    address indexed tokenAddress,
    uint256 tokenAmount
  );

  /**
   * @notice get the held balance of the token owner
   * @dev should throw for invalid queries and return zero for no balance
   * @param tokenAddress held token address
   * @param owner functional token owner
   * @return held token balance
   */
  function heldBalanceOf(address tokenAddress, address owner)
    external
    view
    returns (uint256);
}

Events

Hold

Emitted when tokens are transferred into the holder contract.

  • owner
    • The functional owner's address.
  • tokenAddress
    • The address of the ERC-20 token contract.
  • tokenAmount
    • The amount held.
Release

Emitted when tokens are released from the holder contract back to the user.

  • owner
    • The functional owner's address.
  • tokenAddress
    • The address of the ERC-20 token contract.
  • tokenAmount
    • The amount released.

Functions

heldBalanceOf

Returns the amount of a specified ERC-20 token held by the contract on behalf of a specified user.

  • The arguments identify the token contract and functional owner.
  • A valid query with no corresponding balance returns zero.
  • Invalid queries should revert.

IERC721Holder

IERC721Holder.sol
/**
 * @notice the ERC721 holder standard provides a common interface to query
 * token ownership and balance information
 */
interface IERC721Holder is IERC165 {
  /**
   * @notice emitted when the token is transferred to the contract
   * @param owner functional token owner
   * @param tokenAddress held token address
   * @param tokenId held token ID
   */
  event Hold(
    address indexed owner,
    address indexed tokenAddress,
    uint256 indexed tokenId
  );

  /**
   * @notice emitted when the token is released back to the user
   * @param owner functional token owner
   * @param tokenAddress held token address
   * @param tokenId held token ID
   */
  event Release(
    address indexed owner,
    address indexed tokenAddress,
    uint256 indexed tokenId
  );

  /**
   * @notice get the functional owner of a held token
   * @dev should throw for invalid queries and return zero for a token ID that is not held
   * @param tokenAddress held token address
   * @param tokenId held token ID
   * @return functional token owner
   */
  function heldOwnerOf(address tokenAddress, uint256 tokenId)
    external
    view
    returns (address);

  /**
   * @notice get the held balance of the token owner
   * @dev should throw for invalid queries and return zero for no balance
   * @param tokenAddress held token address
   * @param owner functional token owner
   * @return held token balance
   */
  function heldBalanceOf(address tokenAddress, address owner)
    external
    view
    returns (uint256);
}

Events

Hold

Emitted when an ERC-721 NFT is transferred into the holder contract.

  • tokenId
    • The identifier of the held NFT.
Release

Emitted when the NFT is released back to the user.

Functions

heldOwnerOf

Returns the functional owner's address for a specified NFT. If a valid token ID is not held by the contract, the function returns the zero address.

heldBalanceOf

Returns the number of NFTs from a specified token contract held on behalf of the given owner.

IERC1155Holder

IERC1155Holder.sol
/**
 * @notice the ERC1155 holder standard provides a common interface to query
 * token balance information
 */
interface IERC1155Holder is IERC165 {
  /**
   * @notice emitted when the token is transferred to the contract
   * @param owner functional token owner
   * @param tokenAddress held token address
   * @param tokenId held token ID
   * @param tokenAmount held token amount
   */
  event Hold(
    address indexed owner,
    address indexed tokenAddress,
    uint256 indexed tokenId,
    uint256 tokenAmount
  );

  /**
   * @notice emitted when the token is released back to the user
   * @param owner functional token owner
   * @param tokenAddress held token address
   * @param tokenId held token ID
   * @param tokenAmount held token amount
   */
  event Release(
    address indexed owner,
    address indexed tokenAddress,
    uint256 indexed tokenId,
    uint256 tokenAmount
  );

  /**
   * @notice get the held balance of the token owner
   * @dev should throw for invalid queries and return zero for no balance
   * @param tokenAddress held token address
   * @param owner functional token owner
   * @param tokenId held token ID
   * @return held token balance
   */
  function heldBalanceOf(
    address tokenAddress,
    address owner,
    uint256 tokenId
  ) external view returns (uint256);
}

Events

Hold

Emitted when ERC-1155 tokens are transferred into the holder contract.

  • tokenId
    • The identifier of the token type.
  • tokenAmount
    • The amount held.
Release

Emitted when tokens are released back to the user.

Functions

heldBalanceOf

Returns the quantity of a particular ERC-1155 token ID held by the contract on behalf of a specified user.

Rationale

Including the token address in function arguments

Functions such as heldBalanceOf accept a tokenAddress argument because a single holder contract may manage tokens issued by multiple token contracts.

  • Single-token holder contracts can use a fixed supported token address. They should still handle invalid token queries according to the interface requirements.
  • Multi-token holder contracts can use the token address to distinguish balances belonging to different token contracts.

This design allows the same interface to serve both single-token and multi-token applications.

Separate interfaces for different token standards

ERC-20, ERC-721, and ERC-1155 use different token accounting models.

  • ERC-20
    • Tracks fungible token balances.
  • ERC-721
    • Tracks ownership of individual token IDs.
  • ERC-1155
    • Tracks quantities for individual token IDs.

Separate interfaces accommodate these differences. A holder contract supporting multiple token standards can implement the relevant interfaces.

Compatibility

ERC-4987 is designed to work with existing ERC-20, ERC-721, and ERC-1155 token contracts without requiring changes to those token contracts.

Contracts holding tokens must implement the appropriate ERC-4987 interfaces to expose functional ownership information.

Applications such as governance systems, games, and authentication services must also be updated to query functions such as heldBalanceOf and heldOwnerOf when evaluating held tokens.

Security

Untrusted holder contracts

Any contract can claim to implement these interfaces, including contracts that report fabricated ownership information. Applications must not treat interface support alone as proof that the returned information is accurate.

Potential consequences of trusting false information include:

  • Granting voting power to users who do not actually hold the required governance tokens.
  • Granting game benefits based on fabricated item or character ownership.
  • Allowing unauthorized access to NFT-based membership services.

Applications relying on ERC-4987 queries should establish which holder contracts they trust and verify that those contracts maintain appropriate accounting and custody controls.

Checking consistency with actual token holdings

Applications should consider verifying the information against the underlying token contract.

  • Confirm that the holder contract actually holds the relevant ERC-20, ERC-721, or ERC-1155 tokens.
  • Check that reported balances are consistent with the holder contract's actual token balance.
  • For ERC-721, verify that the underlying ownerOf function identifies the holder contract as the NFT's actual owner.

These checks establish backing but do not independently prove that a particular user is entitled to the reported balance. Applications must also consider how the holder allocates balances among users, avoid counting the same tokens multiple times, and evaluate whether its records can be manipulated.

Citation

Devin Conley (@devinaconley), "ERC-4987: Held token interface [DRAFT]," Ethereum Improvement Proposals, no. 4987, September 2021. [Online serial]. Available: https://eips.ethereum.org/EIPS/eip-4987.

Conclusion

ERC-4987 proposes standardized interfaces for querying the functional ownership and balances of ERC-20, ERC-721, and ERC-1155 tokens deposited in smart contracts. Applications can use these interfaces to recognize held tokens without confusing the custody contract with the user to whom the tokens are attributed.

Questions are welcome via Twitter @cardene777.

Other publications:

https://chaldene.net/