JSPM

  • Created
  • Published
  • Downloads 34
  • Score
    100M100P100Q85843F
  • License MIT

ERC-1363 Payable Token Implementation

Package Exports

  • erc-payable-token/test/introspection/SupportsInterface.behavior
  • erc-payable-token/test/introspection/SupportsInterface.behavior.js

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

NPM Package CI Coverage Status MIT licensed

ERC-1363 allows to implement an ERC-20 smart token.

It means that we can add a callback to be executed after transferring or approving tokens.

This is an implementation of the EIP-1363 that defines an 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.

Abstract

There is no way to execute any code on a receiver or spender contract after an ERC-20 transfer, transferFrom or approve so, to make an action, it is required to send another transaction.

This introduces complexity on UI development and friction on adoption because users must wait for the first transaction to be executed, and then send the second one. They must also pay GAS twice.

This proposal aims to make tokens capable of performing actions more easily and working with contracts without the use of any other external listener. It allows to make a callback on a receiver or spender contract, after a transfer or an approval, in a single transaction.

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

Examples could be

  • to create a token payable crowdsale
  • selling services for tokens
  • paying invoices
  • making subscriptions

For these reasons it was originally named "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-token

Usage

pragma solidity ^0.8.20;

import {ERC1363} from "erc-payable-token/contracts/token/ERC1363/ERC1363.sol";

contract MyToken is ERC1363 {

    constructor(string memory name, string memory symbol) ERC20(name, symbol) {
        // your stuff
    }

  // your stuff
}

Code

This repo contains:

IERC1363

IERC1363.sol

Interface of the ERC1363 standard as defined in the EIP-1363.

interface IERC1363 is IERC20, IERC165 {
    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);
}

IERC1363Errors

IERC1363Errors.sol

Interface of the ERC1363 custom errors following the ERC-6093 rationale.

ERC1363

ERC1363.sol

Implementation of the ERC1363 interface.

IERC1363Receiver

IERC1363Receiver.sol

Interface for any contract that wants to support transferAndCall or transferFromAndCall from ERC1363 token contracts.

interface IERC1363Receiver {
    function onTransferReceived(address spender, address sender, uint256 amount, bytes calldata data) external returns (bytes4);
}

IERC1363Spender

IERC1363Spender.sol

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);
}

ERC1363Holder

ERC1363Holder.sol

Implementation of IERC1363Receiver and IERC1363Spender that will allow a contract to receive ERC1363 token transfers or approval.

IMPORTANT: When inheriting this contract, you must include a way to use the received tokens or spend the allowance, otherwise they will be stuck.

ERC1363Payable

ERC1363Payable.sol

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 stuff 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 stuff within your contract after a onApprovalReceived.

ERC1363PayableCrowdsale

ERC1363PayableCrowdsale.sol

As example: an Implementation of a classic token Crowdsale, but paid with ERC1363 tokens instead of ETH.

ERC1363MethodCallReceiver

ERC1363MethodCallReceiver.sol

As example: a contract allowing to test passing methods via abi encoded function call.

Code Analysis

Development

Install dependencies

npm install

Usage

Open the console

npm run console

Compile

npm run compile

Test

npm test

Code Coverage

npm run coverage

Linter

Check Solidity files

npm run lint:sol

Check JS/TS files

npm run lint:js

Fix JS and Solidity files

npm run lint:fix

License

Code released under the MIT License.