Skip to content

feat: add a page for ERC1363 #15235

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion public/content/developers/docs/standards/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ More detailed information on these different types and categories can be found i

- [ERC-20](/developers/docs/standards/tokens/erc-20/) - A standard interface for fungible (interchangeable) tokens, like voting tokens, staking tokens or virtual currencies.
- [ERC-223](/developers/docs/standards/tokens/erc-223/) - A fungible tokens standard that makes tokens behave identical to ether and supports token transfers handling on the recipients side.
- [ERC-1363](https://eips.ethereum.org/EIPS/eip-1363) - Defines a token interface for ERC-20 tokens that supports executing recipient code after transfer or transferFrom, or spender code after approve.
- [ERC-1363](/developers/docs/standards/tokens/erc-1363/) - An extension interface for ERC-20 tokens that supports executing callback on recipient contracts in a single transaction.
- [ERC-721](/developers/docs/standards/tokens/erc-721/) - A standard interface for non-fungible tokens, like a deed for artwork or a song.
- [ERC-2309](https://eips.ethereum.org/EIPS/eip-2309) - A standardized event emitted when creating/transferring one, or many non-fungible tokens using consecutive token identifiers.
- [ERC-4400](https://eips.ethereum.org/EIPS/eip-4400) - Interface extension for EIP-721 consumer role.
Expand Down
213 changes: 213 additions & 0 deletions public/content/developers/docs/standards/tokens/erc-1363/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,213 @@
---
title: ERC-1363 Payable Token Standard
description: ERC-1363 is an extension interface for ERC-20 tokens that supports executing custom logic on a recipient contract after transfers, or on a spender contract after approvals, all within a single transaction.
lang: en
---

## Introduction {#introduction}

### What is ERC-1363? {#what-is-erc1363}

ERC-1363 is an extension interface for ERC-20 tokens that supports executing custom logic on a recipient contract after transfers, or on a spender contract after approvals, all within a single transaction.

### Differences from ERC-20 {#erc20-differences}

Standard ERC-20 operations like `transfer`, `transferFrom` and `approve`, do not allow code execution on the recipient or spender contract without a separate transaction.
This introduces complexity in UI development and friction on adoption because users must wait for the first transaction to be executed and then submit the second one.
They must also pay GAS twice.

ERC-1363 makes fungible 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 or spender contract, after a transfer or an approval, in a single transaction.

## Prerequisites {#prerequisites}

To better understand this page, we recommend you first read about:

- [Token standards](/developers/docs/standards/tokens/)
- [ERC-20](/developers/docs/standards/tokens/erc-20/)

## Body {#body}

ERC-1363 introduces a standard API for ERC-20 tokens to interact 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.

There are many proposed uses of smart contracts that can accept ERC-20 callbacks.

Examples could be:

- **Crowdsales**: tokens sent trigger instant reward allocation.
- **Services**: payment activates service access in one step.
- **Invoices**: tokens settle invoices automatically.
- **Subscriptions**: approving annual rate activates subscription within the first month’s payment.

For these reasons it was originally named **"Payable Token"**.

The callback behavior further expands its utility, enabling seamless interactions like:

- **Staking**: tokens transferred trigger automatic locking in a staking contract.
- **Voting**: tokens received register votes in a governance system.
- **Swapping**: token approvals activate swap logic in a single step.

ERC-1363 tokens can be used for specific utilities in all cases that require a callback to be executed after a transfer or an approval received.
ERC-1363 is also useful for avoiding token loss or token locking in smart contracts by verifying the recipient's ability to handle tokens.

Unlike other ERC-20 extension proposals, ERC-1363 doesn't override the ERC-20 `transfer` and `transferFrom` methods and defines the interfaces IDs to be implemented maintaining backward compatibility with ERC-20.

From [EIP-1363](https://eips.ethereum.org/EIPS/eip-1363):

### Methods {#methods}

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.

```solidity
pragma solidity ^0.8.0;

/**
* @title ERC1363
* @dev An extension interface for ERC-20 tokens that supports executing code on a recipient contract
* after `transfer` or `transferFrom`, or code on a spender contract after `approve`, in a single transaction.
*/
interface ERC1363 is ERC20, ERC165 {
/*
* NOTE: the ERC-165 identifier for this interface is 0xb0202a11.
* 0xb0202a11 ===
* bytes4(keccak256('transferAndCall(address,uint256)')) ^
* bytes4(keccak256('transferAndCall(address,uint256,bytes)')) ^
* bytes4(keccak256('transferFromAndCall(address,address,uint256)')) ^
* bytes4(keccak256('transferFromAndCall(address,address,uint256,bytes)')) ^
* bytes4(keccak256('approveAndCall(address,uint256)')) ^
* bytes4(keccak256('approveAndCall(address,uint256,bytes)'))
*/

/**
* @dev Moves a `value` amount of tokens from the caller's account to `to`
* and then calls `ERC1363Receiver::onTransferReceived` on `to`.
* @param to The address to which tokens are being transferred.
* @param value The amount of tokens to be transferred.
* @return A boolean value indicating the operation succeeded unless throwing.
*/
function transferAndCall(address to, uint256 value) external returns (bool);

/**
* @dev Moves a `value` amount of tokens from the caller's account to `to`
* and then calls `ERC1363Receiver::onTransferReceived` on `to`.
* @param to The address to which tokens are being transferred.
* @param value The amount of tokens to be transferred.
* @param data Additional data with no specified format, sent in call to `to`.
* @return A boolean value indicating the operation succeeded unless throwing.
*/
function transferAndCall(address to, uint256 value, bytes calldata data) external returns (bool);

/**
* @dev Moves a `value` amount of tokens from `from` to `to` using the allowance mechanism
* and then calls `ERC1363Receiver::onTransferReceived` on `to`.
* @param from The address from which to send tokens.
* @param to The address to which tokens are being transferred.
* @param value The amount of tokens to be transferred.
* @return A boolean value indicating the operation succeeded unless throwing.
*/
function transferFromAndCall(address from, address to, uint256 value) external returns (bool);

/**
* @dev Moves a `value` amount of tokens from `from` to `to` using the allowance mechanism
* and then calls `ERC1363Receiver::onTransferReceived` on `to`.
* @param from The address from which to send tokens.
* @param to The address to which tokens are being transferred.
* @param value The amount of tokens to be transferred.
* @param data Additional data with no specified format, sent in call to `to`.
* @return A boolean value indicating the operation succeeded unless throwing.
*/
function transferFromAndCall(address from, address to, uint256 value, bytes calldata data) external returns (bool);

/**
* @dev Sets a `value` amount of tokens as the allowance of `spender` over the caller's tokens
* and then calls `ERC1363Spender::onApprovalReceived` on `spender`.
* @param spender The address which will spend the funds.
* @param value The amount of tokens to be spent.
* @return A boolean value indicating the operation succeeded unless throwing.
*/
function approveAndCall(address spender, uint256 value) external returns (bool);

/**
* @dev Sets a `value` amount of tokens as the allowance of `spender` over the caller's tokens
* and then calls `ERC1363Spender::onApprovalReceived` on `spender`.
* @param spender The address which will spend the funds.
* @param value The amount of tokens to be spent.
* @param data Additional data with no specified format, sent in call to `spender`.
* @return A boolean value indicating the operation succeeded unless throwing.
*/
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 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 totalSupply() external view returns (uint256);
function balanceOf(address account) external view returns (uint256);
function allowance(address owner, address spender) external view returns (uint256);
}

interface ERC165 {
function supportsInterface(bytes4 interfaceId) external view returns (bool);
}
```

A smart contract that wants to accept ERC-1363 tokens via `transferAndCall` or `transferFromAndCall` **MUST** implement the `ERC1363Receiver` interface:

```solidity
/**
* @title ERC1363Receiver
* @dev Interface for any contract that wants to support `transferAndCall` or `transferFromAndCall` from ERC-1363 token contracts.
*/
interface ERC1363Receiver {
/**
* @dev Whenever ERC-1363 tokens are transferred to this contract via `ERC1363::transferAndCall` or `ERC1363::transferFromAndCall`
* by `operator` from `from`, this function is called.
*
* NOTE: To accept the transfer, this must return
* `bytes4(keccak256("onTransferReceived(address,address,uint256,bytes)"))`
* (i.e. 0x88a7ca5c, or its own function selector).
*
* @param operator The address which called `transferAndCall` or `transferFromAndCall` function.
* @param from The address which are tokens transferred from.
* @param value The amount of tokens transferred.
* @param data Additional data with no specified format.
* @return `bytes4(keccak256("onTransferReceived(address,address,uint256,bytes)"))` if transfer is allowed unless throwing.
*/
function onTransferReceived(address operator, address from, uint256 value, bytes calldata data) external returns (bytes4);
}
```

A smart contract that wants to accept ERC-1363 tokens via `approveAndCall` **MUST** implement the `ERC1363Spender` interface:

```solidity
/**
* @title ERC1363Spender
* @dev Interface for any contract that wants to support `approveAndCall` from ERC-1363 token contracts.
*/
interface ERC1363Spender {
/**
* @dev Whenever an ERC-1363 tokens `owner` approves this contract via `ERC1363::approveAndCall`
* to spend their tokens, this function is called.
*
* NOTE: To accept the approval, this must return
* `bytes4(keccak256("onApprovalReceived(address,uint256,bytes)"))`
* (i.e. 0x7b04a2d0, or its own function selector).
*
* @param owner The address which called `approveAndCall` function and previously owned the tokens.
* @param value The amount of tokens to be spent.
* @param data Additional data with no specified format.
* @return `bytes4(keccak256("onApprovalReceived(address,uint256,bytes)"))` if approval is allowed unless throwing.
*/
function onApprovalReceived(address owner, uint256 value, bytes calldata data) external returns (bytes4);
}
```

## Further reading {#further-reading}

- [ERC-1363: Payable Token Standard](https://eips.ethereum.org/EIPS/eip-1363)
- [ERC-1363: GitHub Repo](https://github.com/vittominacori/erc1363-payable-token)
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ When ERC-20 tokens are sent to a smart contract that is not designed to handle E
3. No built-in handling
- The ERC-20 standard does not include a mandatory function for receiving contracts to implement, leading to a situation where many contracts are unable to manage incoming tokens properly

Some alternative standards have come out of this issue such as [ERC-223](/developers/docs/standards/tokens/erc-223)
Some alternative standards have come out of this issue such as [ERC-223](/developers/docs/standards/tokens/erc-223) or [ERC-1363](/developers/docs/standards/tokens/erc-1363).

## Further reading {#further-reading}

Expand All @@ -175,5 +175,6 @@ Some alternative standards have come out of this issue such as [ERC-223](/develo
## Other fungible token standards {#fungible-token-standards}

- [ERC-223](/developers/docs/standards/tokens/erc-223)
- [ERC-1363](/developers/docs/standards/tokens/erc-1363)
- [ERC-777](/developers/docs/standards/tokens/erc-777)
- [ERC-4626 - Tokenized vaults](/developers/docs/standards/tokens/erc-4626)
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ Puede encontrar información más detallada sobre estos diferentes tipos y categ

- [ERC-20](/developers/docs/standards/tokens/erc-20/): Una interfaz para tokens fungibles (intercambiables), como tokens de votación, tokens de staking o monedas virtuales.
- [ERC-223](/developers/docs/standards/tokens/erc-223/): Estándar de tokens fungibles que hace que los tokens se comporten idénticos a ether y admite el manejo de transferencias de tokens en el lado del destinatario.
- [ERC-1363](https://eips.ethereum.org/EIPS/eip-1363): Define una interfaz de token para los tokens ERC que soporta la ejecución del código del destinatario después de la transferencia o transferFrom, o código spender después de la aprobación.
- [ERC-1363](/developers/docs/standards/tokens/erc-1363/): Define una interfaz de token para los tokens ERC que soporta la ejecución del código del destinatario después de la transferencia o transferFrom, o código spender después de la aprobación.
- [ERC-721](/developers/docs/standards/tokens/erc-721/): Una interfaz para tokens no fungibles (NFT), como un deed de una obra de arte o una canción.
- [ERC-2309](https://eips.ethereum.org/EIPS/eip-2309): Un evento estandarizado emitido al crear/transferir uno, o muchos tokens no fungibles usando identificadores consecutivos de token.
- [ERC-4400](https://eips.ethereum.org/EIPS/eip-4400): Extensión de interfaz para el rol de consumidor EIP-721.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ Cuando se envían tokens ERC-20 a un contrato inteligente que no está diseñado
3. No hay forma de manejo incorporada
- El estándar ERC-20 no incluye una función obligatoria para la implementación de los contratos de recepción, lo que lleva a una situación en la que muchos contratos no pueden administrar los tokens entrantes correctamente

Algunos estándares alternativos han surgido como resultado de este problema, como [ERC-223](/developers/docs/standards/tokens/erc-223)
Algunos estándares alternativos han surgido como resultado de este problema, como [ERC-223](/developers/docs/standards/tokens/erc-223) o [ERC-1363](/developers/docs/standards/tokens/erc-1363).

## Leer más {#further-reading}

Expand All @@ -168,5 +168,6 @@ Algunos estándares alternativos han surgido como resultado de este problema, co
## Otros estándares de tokens fungibles {#fungible-token-standards}

- [ERC-223](/developers/docs/standards/tokens/erc-223)
- [ERC-1363](/developers/docs/standards/tokens/erc-1363)
- [ERC-777](/developers/docs/standards/tokens/erc-777)
- [ERC-4626: bóvedas tokenizadas](/developers/docs/standards/tokens/erc-4626)
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ incomplete: true

- [ERC-20](/developers/docs/standards/tokens/erc-20/) - یک رابط استاندارد برای توکن‌های تعویضپذیر (قابل تعویض)، مانند توکن‌های رای‌گیری، توکن‌های شرط‌بندی یا ارزهای مجازی می باشد.
- [ERC-223](/developers/docs/standards/tokens/erc-223/) - نوعی استاندارد توکن تعویض پذیر است که رفتاری مشابه اتر دارد و از انتقال توکن هایی که در سمت گیرنده مدیریت می شوند، پشتیبانی می کند.
- [ERC-1363](https://eips.ethereum.org/EIPS/eip-1363) - یک رابط برقراری ارتباط با توکن، برای توکن‌های ERC-20 توصیف می‌کند که از اجرای کد گیرنده پس از اجرای انتقال یا «انتقال از» و یا اجرای کد ارسال کننده پس از تایید، پشتیبانی می‌کند.
- [ERC-1363](/developers/docs/standards/tokens/erc-1363/) - یک رابط برقراری ارتباط با توکن، برای توکن‌های ERC-20 توصیف می‌کند که از اجرای کد گیرنده پس از اجرای انتقال یا «انتقال از» و یا اجرای کد ارسال کننده پس از تایید، پشتیبانی می‌کند.
- [ERC-721](/developers/docs/standards/tokens/erc-721/) - یک رابط استاندارد برای توکن‌های تعویض ناپذیر، مانند یک سند برای اثر هنری یا یک آهنگ است.
- [ERC-2309](https://eips.ethereum.org/EIPS/eip-2309) - یک رویداد استاندارد شده که هنگام ساخت یا انتقال یک یا چندین توکن تعویض ناپذیر، با استفاده از IDهای متوالی، اجرا و اطلاع رسانی می‌شود.
- [ERC-4400](https://eips.ethereum.org/EIPS/eip-4400) - افزونه‌ای برای نقش مصرف کننده در رابط EIP-721.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ print("Addr Balance:", addr_balance)
3. بدون مدیریت داخلی
- استاندارد ERC-20 دارای یک تابع اجباری برای اجرای دریافت قراردادها نیست، که این امر منجر به وضعیتی می‌شود که بسیاری از قراردادها قادر به مدیریت صحیح توکن‌های دریافتی نیستند

برخی استانداردهای جایگزین بر این مشکل فائق آمده‌اند، مانند [ERC-223](/developers/docs/standards/tokens/erc-223)
برخی استانداردهای جایگزین بر این مشکل فائق آمده‌اند، مانند [ERC-223](/developers/docs/standards/tokens/erc-223) [ERC-1363](/developers/docs/standards/tokens/erc-1363)

## اطلاعات بیشتر {#further-reading}

Expand All @@ -168,5 +168,6 @@ print("Addr Balance:", addr_balance)
## سایر استانداردهای توکن قابل تعویض {#fungible-token-standards}

- [ERC-223](/developers/docs/standards/tokens/erc-223)
- [ERC-1363](/developers/docs/standards/tokens/erc-1363)
- [ERC-777](/developers/docs/standards/tokens/erc-777)
- [ERC-4626 - خزانه‌های توکنیزه شده](/developers/docs/standards/tokens/erc-4626)
Loading