Package Exports
- erc-payable-token/test/introspection/SupportsInterface.behavior
- erc-payable-token/test/token/ERC1363/ERC1363.behaviour
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (erc-payable-token) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
ERC-1363 Payable Token
ERC-1363 allows to implement an ERC-20 token that can be used for payments.
This is an implementation of the ERC-1363 Payable Token that defines a token interface for ERC-20 tokens that supports executing recipient code after transfer or transferFrom, or spender code after approve.
Abstract
There is no way to execute code after an ERC-20 transfer or approval (i.e. making a payment), so to make an action it is required to send another transaction and pay GAS twice. ERC-1363 makes token payments easier and working without the use of any other listener. It allows to make a callback after a transfer or approval in a single transaction.
There are many proposed uses of Ethereum smart contracts that can accept ERC-20 payments.
Examples could be:
- to create a token payable crowdsale
- selling services for tokens
- paying invoices
- making subscriptions
For these reasons it was named as "Payable Token".
Anyway you can use it for specific utilities or for any other purposes who require the execution of a callback after a transfer or approval received.
Install
npm install erc-payable-tokenUsage
pragma solidity ^0.7.0;
import "erc-payable-token/contracts/token/ERC1363/ERC1363.sol";
contract MyToken is ERC1363 {
constructor (string memory name, string memory symbol) ERC1363(name, symbol) {}
// your stuff
}Code
This repo contains:
IERC1363
Interface for a Payable Token contract as defined in ERC-1363 Payable Token.
interface IERC1363 is IERC20, IERC165 {
function transferAndCall(address recipient, uint256 amount) external returns (bool);
function transferAndCall(address recipient, uint256 amount, bytes calldata data) external returns (bool);
function transferFromAndCall(address sender, address recipient, uint256 amount) external returns (bool);
function transferFromAndCall(address sender, address recipient, uint256 amount, bytes calldata data) external returns (bool);
function approveAndCall(address spender, uint256 amount) external returns (bool);
function approveAndCall(address spender, uint256 amount, bytes calldata data) external returns (bool);
}ERC1363
Implementation of an IERC1363 interface.
IERC1363Receiver
Interface for any contract that wants to support transferAndCall or transferFromAndCall from ERC1363 token contracts.
interface IERC1363Receiver {
function onTransferReceived(address operator, address sender, uint256 amount, bytes calldata data) external returns (bytes4);
}IERC1363Spender
Interface for any contract that wants to support approveAndCall from ERC1363 token contracts.
interface IERC1363Spender {
function onApprovalReceived(address sender, uint256 amount, bytes calldata data) external returns (bytes4);
}ERC1363Payable
Implementation proposal of a contract that wants to accept ERC1363 payments. It intercepts what is the ERC1363 token desired for payments and throws if another is sent.
It emits a TokensReceived event to notify the transfer received by the contract.
It also implements a transferReceived function that can be overridden to make your stuffs within your contract after a onTransferReceived.
It emits a TokensApproved event to notify the approval received by the contract.
It also implements a approvalReceived function that can be overridden to make your stuffs within your contract after a onApprovalReceived.
ERC1363PayableCrowdsale
As example: an Implementation of a classic token Crowdsale, but paid with ERC1363 tokens instead of ETH.
Development
Install dependencies
npm installLinter
Use Solhint
npm run lint:solUse ESLint
npm run lint:jsUse Eslint and fix
npm run lint:fixUsage (using Truffle)
Open the Truffle console
npm run truffle:consoleCompile
npm run truffle:compileTest
npm run truffle:testUsage (using Hardhat)
Open the Hardhat console
npm run hardhat:consoleCompile
npm run hardhat:compileTest
npm run hardhat:testCode Coverage
npm run hardhat:coverageLicense
Code released under the MIT License.