What is ERC-1363? The payable token standard, and how to implement it

Covalent TeamUpdated 15 min read

ERC-1363 adds transferAndCall and approveAndCall to ERC-20, so a contract can act on a payment in the same transaction. How it works and how to build one.

ERC-1363 is the Ethereum standard for payable tokens: ERC-20 tokens that can notify the contract they pay. It adds transferAndCall, transferFromAndCall and approveAndCall to ERC-20, so sending tokens to a contract (or approving one) also calls a function on that contract, in the same transaction. The contract sees the payment and acts on it at once, instead of the user sending one transaction to approve and a second to call. It is EIP-1363, status Final.

This guide covers what the standard adds to ERC-20, the interface and how a transferAndCall runs, then the practical part: how to implement an ERC-1363 token with OpenZeppelin, how to write a contract that receives one (a vote that is cast by paying), the security rules for receivers, and how ERC-1363 activity looks in onchain data.

Why ERC-1363 exists

An ERC-20 transfer only moves a balance. The receiving contract isn't told, so it can't react. That leaves two ways to pay a contract with ERC-20 tokens, and both are awkward:

  • Approve, then call. The user approves the contract to spend their tokens, then calls a function that pulls them with transferFrom. That is two transactions, two fees and two confirmations, and it often leaves a standing allowance behind.
  • Transfer, then tell. The user transfers tokens and then calls the contract to say they did. The contract has to work out which transfer was whose, and tokens sent without the follow-up call sit in the contract with nothing recorded.

The EIP's motivation puts it plainly: there is no way to execute code after an ERC-20 transfer or approval, "so to make an action it is required to send another transaction and pay GAS twice." ERC-1363 adds a callback, modelled on ERC-721's onERC721Received: after the transfer or approval, the token calls the recipient, and the recipient's code runs in the same transaction.

ERC-20 ERC-1363
Pay a contract approve, then the contract's own function (2 transactions) transferAndCall (1 transaction)
Recipient notified No Yes, through onTransferReceived
Approve and act approve, then a second call approveAndCall (1 transaction)
transfer, transferFrom, approve Yes Yes, unchanged
Detectable on chain No standard check ERC-165 supportsInterface(0xb0202a11)

The ERC-1363 interface

An ERC-1363 token is an ERC-20 token. It keeps every ERC-20 function and event unchanged and must also implement ERC-165, so other contracts can ask whether it supports ERC-1363. On top, it adds three functions, each in two versions: with and without a bytes data argument that is passed through to the recipient.

Function What it does
transferAndCall(to, value) / (to, value, data) transfer from the caller to to, then calls onTransferReceived on to
transferFromAndCall(from, to, value) / (from, to, value, data) transferFrom using the caller's allowance, then calls onTransferReceived on to
approveAndCall(spender, value) / (spender, value, data) approve for spender, then calls onApprovalReceived on spender

Each returns true unless it reverts. The ERC-165 interface ID of the token interface is 0xb0202a11, the XOR of the six function selectors.

Contracts on the receiving end implement one of two interfaces. The EIP names them ERC1363Receiver and ERC1363Spender; OpenZeppelin calls them IERC1363Receiver and IERC1363Spender.

interface IERC1363Receiver {    // Called by the token after transferAndCall or transferFromAndCall.    // Must return 0x88a7ca5c, this function's selector, to accept the tokens.    function onTransferReceived(address operator, address from, uint256 value, bytes calldata data)        external returns (bytes4);} interface IERC1363Spender {    // Called by the token after approveAndCall.    // Must return 0x7b04a2d0, this function's selector, to accept the approval.    function onApprovalReceived(address owner, uint256 value, bytes calldata data)        external returns (bytes4);}

In onTransferReceived, operator is the address that called transferAndCall or transferFromAndCall, and from is the address whose tokens moved. They are the same for transferAndCall and can differ for transferFromAndCall, so credit from. The EIP also notes that "the token contract address is always the message sender": inside the callback, msg.sender is the token.

How a transferAndCall works

A call to transferAndCall(to, value, data) runs in this order:

  1. The token performs a normal ERC-20 transfer: balances change and a standard Transfer event is emitted.
  2. The token calls to.onTransferReceived(msg.sender, msg.sender, value, data).
  3. The recipient runs its logic (records a vote, credits a deposit, starts a subscription) and returns the onTransferReceived selector.
  4. If the recipient reverts or returns anything other than that selector, the token reverts, and the transfer in step 1 is undone with it.

That last step is what makes the pattern safe for the payer: either the tokens arrive and the recipient's logic has run, or nothing happens. OpenZeppelin's implementation also reverts when to has no code, so transferAndCall to a wallet address fails; use plain transfer for wallets.

approveAndCall follows the same shape: approve, then onApprovalReceived on the spender, which can pull the tokens with transferFrom inside the callback.

Build an ERC-1363 token

OpenZeppelin Contracts ships a maintained ERC1363 extension from version 5.1 onwards (5.0 had only the interfaces). It adds all six functions, the receiver and spender checks and the ERC-165 support to a standard OpenZeppelin ERC20. A complete token is a few lines:

// SPDX-License-Identifier: MITpragma solidity ^0.8.24; import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol";import {ERC1363} from "@openzeppelin/contracts/token/ERC20/extensions/ERC1363.sol"; // An ERC-20 with transferAndCall, transferFromAndCall and approveAndCall, plus ERC-165.contract VoteToken is ERC1363 {    constructor(uint256 initialSupply) ERC20("Vote Token", "VOTE") {        _mint(msg.sender, initialSupply);    }}

Install it with npm install @openzeppelin/contracts (5.1 or later) and compile with Solidity 0.8.24 or later in Hardhat, Foundry or Remix. Under the hood, OpenZeppelin's transferAndCall calls transfer and then ERC1363Utils.checkOnERC1363TransferReceived, which:

  • reverts with ERC1363InvalidReceiver if the recipient has no code,
  • calls onTransferReceived and reverts with ERC1363InvalidReceiver unless it returns the selector 0x88a7ca5c,
  • passes the recipient's own revert reason through if it reverted with one.

supportsInterface(0xb0202a11) returns true, so wallets and contracts can detect the token. If you write the functions yourself instead, keep that order (transfer first, then the callback) and treat any return value other than the selector as a failure.

A token that is already deployed doesn't become ERC-1363 by adding code elsewhere: the functions have to be in the token contract itself, so this is a choice made when the token is written (or, for an upgradeable proxy token, in a new implementation).

Build a receiver: token-weighted voting

The receiver is where ERC-1363 earns its keep. This poll counts a vote in the same transaction as the payment: a holder calls transferAndCall(poll, amount, abi.encode(option)), the tokens move into the poll, and onTransferReceived adds amount to that option's tally. The tokens stay locked until the poll closes, then each voter withdraws theirs.

// SPDX-License-Identifier: MITpragma solidity ^0.8.24; import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";import {SafeERC20} from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";import {IERC1363Receiver} from "@openzeppelin/contracts/interfaces/IERC1363Receiver.sol"; // A token-weighted poll. Vote by calling token.transferAndCall(poll, amount, abi.encode(option)):// the tokens arrive and the vote is counted in the same transaction. Tokens stay locked until the poll closes.contract TokenPoll is IERC1363Receiver {    using SafeERC20 for IERC20;     IERC20 public immutable token;    uint256 public immutable optionCount;    uint256 public immutable closesAt;     mapping(uint256 option => uint256 weight) public votes;    mapping(address voter => uint256 amount) public locked;     event VoteCast(address indexed voter, uint256 indexed option, uint256 weight);     error OnlyToken(address caller);    error PollClosed();    error PollOpen();    error InvalidOption(uint256 option);     constructor(IERC20 token_, uint256 optionCount_, uint256 closesAt_) {        token = token_;        optionCount = optionCount_;        closesAt = closesAt_;    }     function onTransferReceived(        address, // operator: who called transferAndCall or transferFromAndCall        address from, // whose tokens moved: the voter        uint256 value,        bytes calldata data    ) external returns (bytes4) {        // Anyone can call this function. Only the token's own callback means tokens really arrived.        if (msg.sender != address(token)) revert OnlyToken(msg.sender);        if (block.timestamp >= closesAt) revert PollClosed();        uint256 option = abi.decode(data, (uint256));        if (option >= optionCount) revert InvalidOption(option);         votes[option] += value;        locked[from] += value;        emit VoteCast(from, option, value);         // Returning anything else makes the token revert the whole transfer.        return IERC1363Receiver.onTransferReceived.selector;    }     function withdraw() external {        if (block.timestamp < closesAt) revert PollOpen();        uint256 amount = locked[msg.sender];        locked[msg.sender] = 0;        token.safeTransfer(msg.sender, amount);    }}

Deploy VoteToken first, then TokenPoll with the token's address, the number of options and a closing timestamp. What each line is for:

  • msg.sender != address(token). onTransferReceived is an ordinary external function. Without this check, anyone could call it directly with a made-up value and vote with tokens they never sent. Every receiver must check that the caller is the token (or one of the tokens) it accepts.
  • from, not operator. With transferFromAndCall, a third party moves someone else's tokens; the tokens and the vote belong to from.
  • Reverting rejects the payment. A closed poll, an unknown option or missing data (which abi.decode can't read) makes the callback revert, and the token reverts the transfer with it. The voter keeps their tokens.
  • Returning the selector accepts it. IERC1363Receiver.onTransferReceived.selector is 0x88a7ca5c.
  • Plain transfers are not votes. A holder who calls ordinary transfer(poll, amount) sends tokens without calling onTransferReceived, so nothing is counted and, in this contract, nothing is recorded for them to withdraw. Production receivers either reject such tokens in the UI or add an admin function to return them.

Call it from a dapp

From a frontend or script, encode the option as data and call transferAndCall on the token. Check ERC-165 first: a plain ERC-20 has no transferAndCall. This uses ethers v6:

import { AbiCoder, Contract } from "ethers"; const IERC1363_ID = "0xb0202a11";const TOKEN_ABI = [    "function supportsInterface(bytes4 interfaceId) view returns (bool)",    "function transferAndCall(address to, uint256 value, bytes data) returns (bool)",]; // Vote with `amount` tokens (raw units) for `option`, in one transaction.export async function vote(signer, tokenAddress, pollAddress, option, amount) {    const token = new Contract(tokenAddress, TOKEN_ABI, signer);    // A plain ERC-20 has no transferAndCall. ERC-165 tells you before you send anything.    const isPayable = await token.supportsInterface(IERC1363_ID).catch(() => false);    if (!isPayable) throw new Error(`${tokenAddress} is not an ERC-1363 token`);     const data = AbiCoder.defaultAbiCoder().encode(["uint256"], [option]);    const tx = await token.transferAndCall(pollAddress, amount, data);    return tx.wait(); // reverts as a whole if the poll rejects the vote}

The ABI above lists only the three-argument transferAndCall. With the full compiled ABI, which has both versions, ethers needs the signature to pick one: token["transferAndCall(address,uint256,bytes)"](pollAddress, amount, data).

approveAndCall and IERC1363Spender

approveAndCall is for contracts that would rather pull tokens than receive them: the token sets the allowance and then calls onApprovalReceived(owner, value, data) on the spender. The spender can call transferFrom(owner, address(this), value) inside the callback, or keep the allowance and charge it later, which suits subscriptions and metered services. The same rules apply as for receivers: check that msg.sender is the token, act on owner, and return 0x7b04a2d0 (the onApprovalReceived selector) to accept.

Use transferAndCall when the amount is known up front. Use approveAndCall when the spender decides how much to take, or takes it over time.

Use cases

The EIP lists the payments it was designed for: a token-payable crowdsale, selling services for tokens, paying invoices and making subscriptions. In practice, the pattern fits anywhere a contract has to act on an incoming ERC-20 payment:

  • Paying for something in one step. A crowdsale, a checkout or an invoice contract receives the tokens and issues what was bought (tokens, an NFT, a receipt) in the same transaction.
  • Deposits and swaps without a prior approve. A pool or exchange contract that implements onTransferReceived can treat the incoming tokens as the deposit or the swap input, with parameters such as a minimum output in data.
  • Subscriptions. With approveAndCall, the user grants an allowance and starts the subscription at once; the service pulls each period's payment.
  • Voting and staking. As in the poll above, locking tokens and recording what they are locked for happen together.

Security considerations

  • Validate the caller in every callback. onTransferReceived and onApprovalReceived can be called by anyone. Accept them only from the token contract(s) you expect, or anyone can fake a payment.
  • The callback is an external call. The token calls into the recipient after balances have changed, and the recipient's code can call other contracts in turn. Write receivers with the usual reentrancy care (update state before making further external calls), and keep in mind on the token side that the callback runs arbitrary code.
  • Allowance races still apply. The EIP warns that approveAndCall and transferFromAndCall share ERC-20's approval race: changing an allowance from one non-zero value to another lets a spender use both the old and new allowance if transactions are ordered unluckily. Set it to zero first, or use a fresh allowance per action.
  • Plain ERC-20 calls bypass the hook. transfer and transferFrom still exist and still work on ERC-1363 tokens, without any callback. A receiver can't rely on every incoming token having gone through onTransferReceived.
  • Don't assume a token is ERC-1363. Check supportsInterface(0xb0202a11) before calling transferAndCall on a token you didn't deploy.

ERC-1363 tokens in onchain data

Because an ERC-1363 token is an ERC-20, everything that reads ERC-20 data reads it unchanged. transferAndCall emits the same Transfer event as transfer, approveAndCall the same Approval event as approve, and the standard adds no events of its own. The callback is an internal call, so it leaves no log unless the receiver emits one (as TokenPoll does with VoteCast).

That means the usual endpoints of the GoldRush Foundational API cover ERC-1363 tokens with no special handling:

  • The token balance API (balances_v2) lists an ERC-1363 token in a wallet's balances like any ERC-20. Credit cost: 1 per call.
  • The ERC-20 token transfers API (transfers_v2) returns every transfer of one token in or out of an address, including those made with transferAndCall. Credit cost: 0.05 per item.
  • The contract event logs API (events/address) returns the receiver's own events, which is where what the payment did is recorded. Credit cost: 0.01 per item.

This script puts the two together for the poll above: every payment of the token into the poll, and whether it was counted as a vote. A transfer with no matching VoteCast in its transaction is a plain transfer that bypassed the hook. It needs Node.js 18 or later and an API key from the free trial.

const API = "https://api.covalenthq.com/v1";const headers = { Authorization: `Bearer ${process.env.GOLDRUSH_API_KEY}` }; // keccak256("VoteCast(address,uint256,uint256)"): topic 0 of the poll's own event.const VOTE_CAST = "0xb4cfecf70861b7b150d8337780d34fb4cbc2114b5fb1fe51a5c5fca1849f7274"; async function getAllPages(url) {    const items = [];    for (let page = 0; ; page++) {        const res = await fetch(`${url}&page-number=${page}`, { headers });        if (!res.ok) throw new Error(`${res.status} ${await res.text()}`);        const { data } = await res.json();        items.push(...data.items);        if (!data.pagination?.has_more) return items;    }} // Every payment of `token` into `receiver`: ordinary ERC-20 Transfer events, whichever function sent them.async function getPaymentsReceived(chain, receiver, token) {    const txs = await getAllPages(`${API}/${chain}/address/${receiver}/transfers_v2/?contract-address=${token}`);    return txs.flatMap((tx) =>        tx.transfers            .filter((t) => t.to_address.toLowerCase() === receiver.toLowerCase())            .map((t) => ({ tx: t.tx_hash, at: t.block_signed_at, from: t.from_address, amount: BigInt(t.delta) }))    );} // The votes the poll recorded: its own VoteCast events, decoded from the raw topics and data.async function getVotes(chain, poll, fromBlock) {    const logs = await getAllPages(        `${API}/${chain}/events/address/${poll}/?starting-block=${fromBlock}&ending-block=latest`    );    return logs        .filter((log) => log.raw_log_topics[0] === VOTE_CAST)        .map((log) => ({            tx: log.tx_hash,            voter: "0x" + log.raw_log_topics[1].slice(26),            option: Number(BigInt(log.raw_log_topics[2])),            weight: BigInt(log.raw_log_data),        }));} // node poll-activity.mjs <chain> <poll address> <token address> <poll's deployment block>const [chain, poll, token, fromBlock] = process.argv.slice(2);const payments = await getPaymentsReceived(chain, poll, token);const votes = await getVotes(chain, poll, fromBlock);const counted = new Set(votes.map((v) => v.tx));for (const p of payments) {    const note = counted.has(p.tx) ? "vote" : "plain transfer, not counted";    console.log(`${p.at}  ${p.from}  ${p.amount}  ${note}`);}

Amounts are raw token units (divide by 10^decimals to display them). The script decodes VoteCast from raw_log_topics and raw_log_data itself, because a newly deployed, unverified contract's events may come back without a decoded form. For token holder lists of any ERC-20, ERC-1363 tokens included, see the token holders guide.

ERC-1363 vs ERC-677 and ERC-777

ERC-1363 wasn't the first attempt at "transfer and notify". The EIP names ERC-223 and ERC-677 as inspirations and takes ERC-721's approach instead: leave transfer and transferFrom alone and add new functions, detectable through ERC-165.

  • ERC-677 adds a single transferAndCall(address,uint256,bytes) that calls onTokenTransfer on the recipient. It never became a final EIP, but Chainlink's LINK token uses it. It has no approveAndCall and no ERC-165 interface ID.
  • ERC-777 goes further: hooks run on every send, including plain transfers, through the ERC-1820 registry. Existing ERC-20 integrations didn't expect code to run on an ordinary transfer, which made those hooks a source of reentrancy bugs. OpenZeppelin deprecated its ERC-777 implementation and removed it in Contracts 5.0.
  • ERC-1363 keeps ERC-20's behaviour exactly as it was and makes the callback opt-in, per call. It is the one of the three that OpenZeppelin ships today.

The approve-then-call flow that ERC-1363 removes is still how most contracts take ERC-20 deposits, including ERC-4626 tokenized vaults, whose deposit pulls the asset with transferFrom.

Frequently asked questions

What is ERC-1363 in simple terms?

ERC-1363 is an extension of ERC-20 that lets a token transfer or approval also call a function on the receiving contract, in the same transaction. The token adds transferAndCall, transferFromAndCall and approveAndCall; the receiving contract implements onTransferReceived or onApprovalReceived and reacts to the payment immediately. It is EIP-1363, status Final, and is sometimes called the payable token standard.

Is ERC-1363 backward compatible with ERC-20?

Yes. An ERC-1363 token is a full ERC-20: transfer, transferFrom, approve, balanceOf and the Transfer and Approval events all work exactly as before, so wallets, exchanges and indexers that support ERC-20 support it. The new functions are additions. A token that is already deployed without them can't gain them unless it is upgradeable.

What is the difference between transferAndCall and approveAndCall?

transferAndCall moves the tokens to the recipient and then calls its onTransferReceived, so the recipient already holds the payment when its code runs. approveAndCall only sets an allowance and then calls the spender's onApprovalReceived; the spender pulls the tokens with transferFrom, now or later. Use the first for a fixed payment and the second when the spender decides the amount or charges over time.

Can I use transferAndCall to send ERC-1363 tokens to a wallet?

Not with OpenZeppelin's implementation: it reverts when the recipient has no code, because a wallet address can't run onTransferReceived. Use ordinary transfer for wallets. transferAndCall is for contracts that implement IERC1363Receiver and return its selector.

Does OpenZeppelin support ERC-1363?

Yes. OpenZeppelin Contracts has shipped an ERC1363 extension of ERC20 since version 5.1, along with the IERC1363, IERC1363Receiver and IERC1363Spender interfaces and the ERC1363Utils library that performs the receiver and spender checks. A token inherits ERC1363 and passes a name and symbol to the ERC20 constructor.

How do I track ERC-1363 token transfers?

The same way as any ERC-20. transferAndCall emits the standard Transfer event, so token balance, token transfer and event log APIs return ERC-1363 activity unchanged. To see what a payment triggered, read the receiving contract's own events, such as the VoteCast event in this guide's poll.

Next steps

Get new guides by email

New tutorials and best practices for building with blockchain data, sent as they're published.