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.
This article covers ERC7631, a proposal that allows ERC20 and ERC721 tokens to affect each other, enabling more flexible token design and operation.
This article translates, summarizes, and elaborates on the following specification.
I have also written about a range of other EIPs.
Overview
This proposal describes how contracts for divisible ERC20 and indivisible ERC721 tokens can work together. Specifically, an action taken in one contract can be reflected in the other. Understanding the differences between these two token types is important.
What are ERC20 tokens?
ERC20 tokens are divisible.
Tokens can be split and traded in smaller units.
For example, one token can be divided into units such as 0.1 tokens.
This makes them suitable for representing assets such as currencies and shares.
For more on ERC20, see the following article.
What are ERC721 tokens?
ERC721 tokens, by contrast, are indivisible. Each token is unique and cannot be divided. This makes them suitable for representing items where uniqueness matters, such as digital art and collectibles.
For more on ERC721, see the following article.
What the proposal defines
The proposal defines how these two different types of token contracts can interact. For example, an ERC20 token transaction can trigger a change in ERC721 tokens. An ERC20 transaction could affect the issuance or transfer of ERC721 tokens.
The proposal also allows accounts to specify whether ERC721 minting and transfers should be skipped during synchronization from ERC20 to ERC721. This gives users more flexibility in managing both types of tokens.
Why does this matter?
Such interoperability could make digital asset management and trading more flexible and encourage the development of new applications and services. Examples include platforms where users purchase ERC721 collectibles with ERC20 tokens, or systems offering ERC721 rewards exclusively to holders of a particular ERC20 token.
Motivation
In this system, operations on ERC20 tokens can automatically affect ERC721 tokens, and vice versa. This enables specific applications, such as native ERC721 fractionalization. In this model, acquiring ERC20 tokens automatically triggers issuance of ERC721 tokens according to the holder's balance.
What is a dual nature token pair?
It combines a divisible ERC20 token with an indivisible ERC721 token. An operation on one token (such as a transfer) is designed to automatically affect the other.
Purpose of the proposal
The goal is to extend the capabilities of these token pairs. The proposal introduces extension interfaces for ERC20 and ERC721 tokens so that their relationship can be queried more easily. This improves the user experience by allowing decentralized exchanges and NFT marketplaces, for example, to display the relationship between the tokens.
Configurable behavior
Users can choose whether ERC721 minting and transfers should be skipped during synchronization from ERC20 to ERC721.
Applications
Because ERC20 holdings can automatically entitle users to ERC721 tokens at a specified ratio, new forms of NFT ownership and trading become possible. For example, in a design where several people share an NFT representing a work of art, their respective interests could be represented by ERC20 tokens, with NFT ownership allocated according to their token holdings.
The proposal aims to make token interactions more flexible and encourage new economic activities and applications on blockchains.
Specification
Overview
A dual nature token pair consists of an ERC20 contract (the base contract) and an ERC721 contract (the mirror contract).
ERC20 contract (base contract)
The ERC20 contract forms the base of the token pair. Its tokens are divisible and generally treated like currencies or other assets. The contract provides standard rules and functions that facilitate the division and exchange of assets.
ERC721 contract (mirror contract)
The ERC721 contract is the mirror side of the pair, where each token is unique and indivisible. It is suitable for representing items where uniqueness matters, such as digital art, collectibles, and real estate. ERC721 tokens are used to represent items with distinct ownership or scarcity in digital form.
How a dual nature token pair works
Combining these two contracts gives the pair its dual nature. Transactions or balance changes involving ERC20 tokens can affect ERC721 tokens, and vice versa. For example, holding a certain quantity of ERC20 tokens could trigger an ERC721 operation, such as minting a new unique token or changing ownership of an existing one.
The interaction between the base contract (ERC20) and mirror contract (ERC721) creates new relationships between divisible and indivisible assets. This broadens the possibilities for onchain asset management and trading.
ERC20 extension interface
The ERC20 contract must implement the following interface.
interface IERC7631Base {
/// @dev Returns the address of the mirror ERC-721 contract.
///
/// This method MAY revert or return the zero address
/// to denote that a mirror ERC-721 contract has not been linked.
///
/// If a non-zero address is returned, the returned address MUST
/// implement `IERC7631Mirror` and its `baseERC20()` method MUST
/// return the address of this contract.
///
/// Once a non-zero address has been returned, this method
/// MUST NOT revert and the returned value MUST NOT change.
function mirrorERC721() external view returns (address);
}The IERC7631Base interface is used by the ERC20 base contract in a dual nature token pair.
It defines how to identify the relationship between the ERC20 token (base contract) and its linked ERC721 token (mirror contract).
The mirrorERC721() function
- Purpose
- Returns the address of the linked mirror contract (the ERC721 contract).
- Behavior
- Linked
- If a nonzero address is returned, that address must implement
IERC7631Mirror, and itsbaseERC20()method must return the address of this ERC20 contract.
- If a nonzero address is returned, that address must implement
- Unlinked
- If the mirror contract (the ERC721 contract) has not yet been linked, this function may return the zero address or revert.
- Once a nonzero address has been returned, the function must not revert and its return value must not change.
- Linked
Why does this matter?
The interface provides a standardized way to establish and manage an explicit relationship between ERC20 and ERC721 tokens. Developers can implement dual nature token pairs more easily, and users can reliably identify the relationship between an ERC20 token and its mirror ERC721 token.
The ERC20 contract may also implement the following interface.
interface IERC7631BaseNFTSkippable {
/// @dev Emitted when the skip NFT status of `owner` is changed by
/// any mechanism.
///
/// This initial skip NFT status for `owner` can be dynamically chosen to
/// be true or false, but any changes to it MUST emit this event.
event SkipNFTSet(address indexed owner, bool status);
/// @dev Returns true if ERC-721 mints and transfers to `owner` SHOULD be
/// skipped during ERC-20 to ERC-721 synchronization. Otherwise false.
///
/// This method MAY revert
/// (e.g. contract not initialized, method not supported).
///
/// If this method reverts:
/// - Interacting code SHOULD interpret `setSkipNFT` functionality as
/// unavailable (and hide any functionality to call `setSkipNFT`).
/// - The skip NFT status for `owner` SHOULD be interpreted as undefined.
///
/// Once a true or false value has been returned for a given `owner`,
/// this method MUST NOT revert for the given `owner`.
function getSkipNFT(address owner) external view returns (bool);
/// @dev Sets the caller's skip NFT status.
///
/// This method MAY revert
/// (e.g. insufficient permissions, method not supported).
///
/// Emits a {SkipNFTSet} event.
function setSkipNFT(bool status) external;
}The IERC7631BaseNFTSkippable interface defines an option to skip ERC721 minting and transfers to a particular owner during synchronization between ERC20 and ERC721 tokens.
Users can therefore opt out of automatic ERC721 minting or transfers according to their needs.
Functions and events
-
SkipNFTSetevent- Emitted when an owner's NFT skip status changes.
- The event must be emitted whenever the status changes to
trueorfalse.
-
getSkipNFT(address owner)function- Returns whether ERC721 minting and transfers to the specified owner should be skipped.
- The function may
revertif the status is undefined or the feature is unsupported. - However, once a status has been returned for an owner, the function must not
revertfor that owner.
-
setSkipNFT(bool status)function- Sets the caller's NFT skip status.
- A successful call emits the
SkipNFTSetevent. - The function may revert if the caller lacks permission or the method is unsupported.
Why does this matter?
This interface allows users to control automatic ERC721 minting and transfers according to their preferences. For example, a user might not want ERC20 and ERC721 tokens to synchronize, or might want minting and transfers to occur only under particular conditions. This flexibility is especially useful for digital assets because it gives users finer control over their onchain holdings.
ERC721 extension interface
The ERC721 contract must implement the following interface.
interface IERC7631Mirror {
/// @dev Returns the address of the base ERC-20 contract.
///
/// This method MAY revert or return the zero address
/// to denote that a base ERC-20 contract has not been linked.
///
/// If a non-zero address is returned, the returned address MUST
/// implement `IERC7631Base` and its `mirrorERC721()` method MUST
/// return the address of this contract.
///
/// Once a non-zero address has been returned, this method
/// MUST NOT revert and the returned value MUST NOT change.
function baseERC20() external view returns (address);
}The IERC7631Mirror interface allows the ERC721 token (mirror contract) to provide information about its associated ERC20 token (base contract).
Specifically, it defines a function for the ERC721 token contract to return the address of its linked ERC20 contract.
The baseERC20() function
- Purpose
- Returns the address of the linked base contract (the ERC20 contract).
- Behavior
- Linked
- If a nonzero address is returned, that address must implement
IERC7631Base, and itsmirrorERC721()method must return the address of this ERC721 contract.
- If a nonzero address is returned, that address must implement
- Unlinked
- If the base ERC20 contract has not yet been linked, this function may return the zero address or
revert. - Once a nonzero address has been returned, the method must not revert or change its return value.
- If the base ERC20 contract has not yet been linked, this function may return the zero address or
- Linked
Why does this matter?
Through this interface, the ERC721 contract (mirror contract) can explicitly identify its associated ERC20 contract (base contract). Developers and users can easily identify and manage the relationship between ERC20 and ERC721 tokens. This also improves reliability and interoperability when implementing interactions between the two standards.
Additional Notes
This section discusses the rationale for dual nature token pairs, implementation detection, NFT skipping, implementation conventions, and linking mechanisms.
Implementation detection
The mirrorERC721 and baseERC20 methods
By returning nonzero addresses, these methods indicate that the ERC20 and ERC721 contracts implement their respective required interfaces. Consequently, ERC165 (the interface detection standard) is not needed.
For more on ERC165, see the following article.
[ERC165] Checking Whether a Contract Supports a Specific Interface
The getSkipNFT and setSkipNFT methods
These methods may revert. Because contracts compiled with Solidity or Vyper ordinarily revert on calls to undefined methods, the proposal treats contracts that do not explicitly define these methods as conforming to IERC7631BaseNFTSkippable in this respect.
NFT skipping
Default behavior
One useful pattern is for getSkipNFT to return true by default when the owner is a smart contract.
This avoids automatically minting ERC721 tokens on every ERC20 transfer to such accounts and prevents ERC20 liquidity pools from unnecessarily receiving ERC721 tokens.
Implementation conventions
Base and mirror contracts
By convention, the ERC20 contract is the base contract, allowing ERC721 token balances to be derived conveniently from ERC20 balances. However, most of the logic can be implemented in the ERC721 contract if desired.
Token synchronization logic is out of scope
The proposal does not specify token synchronization logic. This leaves room for different implementation patterns and emerging use cases, such as automatically rebasing tokens.
Linking mechanism
The linking process is unspecified
The linking process is intentionally unspecified to preserve flexibility. Developers can use any mechanism, such as linking in a constructor, using an initializer, or calling custom admin-only public methods on the two contracts. The only constraint is that once established, the pairing must be immutable, which simplifies indexing logic.
Flexibility in the linking process
Linking is the process of associating two different types of tokens (in this case, ERC20 and ERC721). This association allows activity involving one token to affect the other. The exact method for linking the tokens is deliberately not specified in detail. Developers can therefore choose the method best suited to their implementation.
Linking methods
Developers can take different technical approaches to associating tokens. Common methods include the following.
- Linking in the constructor
- Set the address of the other token contract when a token contract is created.
- Using an initializer
- Establish the association when the contract is initialized.
- This is useful in certain situations, such as with upgradeable contracts.
- Linking through custom admin-only public methods
- After deployment, only administrators can call a designated function to link the tokens.
Immutability of the link
Once the linked relationship has been established, it must be immutable. This makes the relationship between tokens easier to track and helps maintain system security. Preventing changes after the initial link improves data consistency and predictability.
This flexibility lets developers select a linking method suited to different projects and use cases. At the same time, the immutable link is intended to maintain the stability and reliability of the overall system.
Security
Synchronization access guards
Problem
Synchronization logic between the contracts in a dual nature token pair can be externally accessible, creating security risks if access is not properly controlled.
Mitigation
Synchronization methods must be strictly restricted so that only the other contract in the pair can call them. This prevents unauthorized operations by unrelated third parties.
Rare NFT sniping
Problem
Collections offering ERC721 tokens with different rarity levels risk having rare NFTs unfairly acquired by actors who scrape and exploit metadata.
Mitigation
It is recommended that ERC721 token metadata be revealed only after a token has been held by the same account for a specified period. This helps prevent misuse of metadata.
Out-of-gas denial of service (DoS)
Problem
If transferring ERC20 tokens automatically triggers ERC721 minting, transfer, or burning, the operation may incur O(n) gas costs rather than the O(1) gas costs of a typical ERC20 token transfer.
A large number of ERC721 operations could exhaust the available gas and cause a denial of service (DoS).
Mitigation
Synchronization logic, including ERC721 token ID selection, must be designed with the gas costs of ERC721 operations in mind. This helps prevent out-of-gas denial of service (DoS).
These security considerations are important to implementing and operating dual nature token pairs safely. Developers must understand the risks and apply appropriate mitigations.
Citation
vectorized (@vectorized), Thomas (@0xth0mas), Quit (@quitcrypto), Michael Amadi (@AmadiMichael), cygaar (@cygaar), Harrison (@pop-punk), "ERC-7631: Dual Nature Token Pair [DRAFT]," Ethereum Improvement Proposals, no. 7631, February 2024. [Online serial]. Available: https://eips.ethereum.org/EIPS/eip-7631.
Conclusion
This article covered ERC7631, a proposal that allows ERC20 and ERC721 tokens to affect each other, enabling flexible token design and operation.
If you have questions, feel free to reach out via a direct message on Twitter.
I also publish content on other platforms.



