This thread is intended to be the official EIP-1363 discussions link.
Abstract
ERC-1363 is an extension interface for ERC-20 tokens that supports executing code on a recipient contract after transfers, or code on a spender contract after approvals, in a single transaction.
The following standard allows for the implementation of a standard API for tokens interaction with smart contracts after transfer
, transferFrom
or approve
.
This standard provides basic functionality to transfer tokens, as well as allow tokens to be approved so they can be spent by another on-chain third party, and then make a callback on the receiver or spender contract.
The following are functions and callbacks introduced by this EIP:
transferAndCall
andtransferFromAndCall
will call anonTransferReceived
on aERC1363Receiver
contract.approveAndCall
will call anonApprovalReceived
on aERC1363Spender
contract.
Motivation
There is no way to execute code on a receiver/spender contract after an ERC-20 transfer
, transferFrom
or approve
so, to perform an action, it is required to send another transaction.
This introduces complexity in UI development and friction on adoption as users must wait for the first transaction to be executed and then submit the second one. They must also pay GAS twice.
This proposal aims to make tokens capable of performing actions more easily and working without the use of any off-chain listener.
It allows to make a callback on a receiver/spender contract, after a transfer or an approval, in a single transaction.
Tokens defined by this EIP can be used for specific utilities in all cases that require a callback to be executed after a transfer or an approval received.
This EIP is also useful for avoiding token loss or token locking in contracts by verifying the recipient contract’s ability to handle tokens.
Specification
Smart contracts implementing the ERC-1363 standard MUST implement all of the functions in the ERC1363
interface, as well as the ERC20
and ERC165
interfaces.
pragma solidity ^0.8.0;
interface ERC1363 is ERC20, ERC165 {
function transferAndCall(address to, uint256 value) external returns (bool);
function transferAndCall(address to, uint256 value, bytes calldata data) external returns (bool);
function transferFromAndCall(address from, address to, uint256 value) external returns (bool);
function transferFromAndCall(address from, address to, uint256 value, bytes calldata data) external returns (bool);
function approveAndCall(address spender, uint256 value) external returns (bool);
function approveAndCall(address spender, uint256 value, bytes calldata data) external returns (bool);
}
interface ERC20 {
event Transfer(address indexed from, address indexed to, uint256 value);
event Approval(address indexed owner, address indexed spender, uint256 value);
function totalSupply() external view returns (uint256);
function balanceOf(address account) external view returns (uint256);
function transfer(address to, uint256 value) external returns (bool);
function transferFrom(address from, address to, uint256 value) external returns (bool);
function approve(address spender, uint256 value) external returns (bool);
function allowance(address owner, address spender) external view returns (uint256);
}
interface ERC165 {
function supportsInterface(bytes4 interfaceId) external view returns (bool);
}
A contract that wants to accept ERC-1363 tokens via transferAndCall
or transferFromAndCall
MUST implement the ERC1363Receiver
interface:
interface ERC1363Receiver {
function onTransferReceived(address operator, address from, uint256 value, bytes calldata data) external returns (bytes4);
}
A contract that wants to accept ERC-1363 tokens via approveAndCall
MUST implement the ERC1363Spender
interface:
interface ERC1363Spender {
function onApprovalReceived(address owner, uint256 value, bytes calldata data) external returns (bytes4);
}
Full specification in the official Final ERC-1363 page.
Reference implementation and test cases can be found here.