ERC-4521 An ERC-20-style transfer function for NFTs (721/20-compatible transfer)

Stagnant · NFTs & multi-token · created 2021-12-13

A standard that adds an ERC-20-style transfer() function to ERC-721 NFT contracts, allowing NFTs to be transferred by wallets and contracts built only for ERC-20.

Why it is needed

The ERC-721 standard defines only transferFrom() and safeTransferFrom() as functions for sending NFTs, and does not include the transfer() function found in ERC-20 tokens. However, many wallets and contracts are built to call transfer() when sending or receiving tokens. As a result, if an NFT is mistakenly sent to a contract designed to handle only ERC-20, that contract has no way to call transfer(), and the NFT ends up stuck inside it. This also makes integration cumbersome for developers building services that handle both ERC-20 and NFTs, since they must write separate transfer logic for each token type.

What to implement

In depth

Function signature

transfer(address to, uint256 tokenId) follows the same signature as ERC-20's transfer(address,uint256), but interprets the second parameter as a specific tokenId rather than an amount. Its return type is also bool success, matching ERC-20.

Reuse of the Transfer event

The specification states that the result of calling ERC-4521's transfer() MUST emit the same Transfer event described in ERC-721. It does not introduce a new event, instead reusing the existing ERC-721 event tracking framework.

Mandatory bool return value

Implementers must include the same bool return value as ERC-20 in ERC-4521's transfer(). Otherwise it is incompatible with existing contracts written against the ERC-20 interface, and an NFT could get stuck in such a contract unless safeTransfer is used.

Order of operations in the reference implementation

The reference implementation first checks whether msg.sender is ownerOf[tokenId] (reverting with NOT_OWNER if not), then decrements balanceOf[msg.sender] and increments balanceOf[to] using unchecked arithmetic. It then deletes getApproved[tokenId], updates ownerOf[tokenId] to to, emits the Transfer event, and returns true for success.

Backward compatibility

This EIP states that it introduces no known backward compatibility issues. Because it simply adds a transfer() function to the existing ERC-721 interface, existing methods (transferFrom, safeTransferFrom) remain unchanged.

Required standard and proposal status

This proposal requires ERC-721 and takes the form of a simple extension to ERC-721 contracts. However, this proposal is in Stagnant status, meaning discussion has stalled and is no longer progressing.

Things to watch out for

Original ERC · ← ERCs