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 examines ERC-677, a proposal that combines ERC-20 compatibility with recipient notification functionality inspired by ERC-223.

This explanation is based on the following proposal.

https://eips.ethereum.org/EIPS/eip-677

For other Ethereum improvement proposals, see the following page.

The original article describes ERC-677 as a proposal discussed on GitHub rather than a formally adopted ERC standard. The discussion had been closed when the article was written. Treat the interface as a proposed convention rather than a finalized standard.

Overview

The proposal adds a transferAndCall function to ERC-20 tokens. It transfers tokens to a contract and passes additional data, allowing the recipient to perform an operation after receiving the tokens.

For an introduction to ERC-20, see the following article.

https://chaldene.net/erc20

Motivation

In a conventional ERC-20 workflow, transferring tokens to a contract that must act on the payment can require multiple steps.

  1. Call approve on the ERC-20 contract to authorize the recipient contract to spend tokens.
  2. Notify the recipient contract that it has been authorized.
  3. The recipient contract transfers the tokens and performs the associated processing.

This two- or three-step workflow can be inefficient and inconvenient for users.

ERC-223 was designed to address related problems. Its transfer behavior includes receiver checks for contract recipients. Changing the behavior of an existing transfer interface, however, can introduce compatibility issues with contracts that do not implement the necessary callback.

ERC-223 checks whether a recipient contract can receive tokens. The original article describes the receiver callback as tokenReceived. See the ERC-223 article for more details.

ERC-223: ERC-20 Tokens with Receiver Checks

ERC-677 proposes providing similar functionality without changing the existing ERC-20 transfer function.

It introduces transferAndCall(address receiver, uint amount, bytes data), which transfers tokens to the recipient and calls its onTokenTransfer function with additional data.

The function resembles ERC-223's transfer(address,uint256,bytes), but its distinct name separates the callback-enabled operation from an ordinary transfer.

This preserves the existing ERC-20 interface while offering additional transfer functionality. Contracts that support ERC-223 receiver conventions can implement those separately.

Specification

Token Contract

js
function transferAndCall(address receiver, uint amount, bytes data) returns (bool success)

The token contract uses ERC-20 transfer functionality to transfer tokens to the address specified by receiver.

It then emits a Transfer(address, address, uint256, bytes) event and calls the recipient contract's onTokenTransfer function with the following parameters.

  • sender: Address that sent the tokens.
  • amount: Quantity of tokens transferred.
  • data: Additional data, such as information describing the purpose of the transfer.

Token Recipient Contract

js
function onTokenTransfer(address from, uint256 amount, bytes data) returns (bool success)

The recipient implements this function to receive notification of the token transfer within the same transaction.

Compatibility

The proposal is designed to retain compatibility with the ERC-20 interface.

New tokens and contracts can implement transferAndCall, while existing contracts can continue using the approve and transferFrom workflow without adopting the new function.

Implementation

An implementation is available in the following repository.

Conclusion

ERC-677 proposes an ERC-20-compatible transfer method that also notifies a recipient contract and passes additional data. Its separate function name allows ordinary ERC-20 transfers to remain unchanged.