• Stars
    star
    130
  • Rank 277,575 (Top 6 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created about 6 years ago
  • Updated 5 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Reference implementation for the ERC-1363 Payable Token

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 after transferring or approving tokens to be executed.

This is an implementation of the EIP-1363 that defines a token interface for EIP-20 tokens that supports executing recipient contract code after transfer or transferFrom, or spender contract code after approve in a single transaction.

Abstract

There is no way to execute any code on a receiver or spender contract after an EIP-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 without the use of any other 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.0;

import "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 an ERC1363 compliant contract, as defined in the EIP-1363.

interface IERC1363 is IERC20, IERC165 {
    function transferAndCall(address to, uint256 amount) external returns (bool);
    function transferAndCall(address to, uint256 amount, bytes calldata data) external returns (bool);
    function transferFromAndCall(address from, address to, uint256 amount) external returns (bool);
    function transferFromAndCall(address from, address to, 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

ERC1363.sol

Implementation of an IERC1363 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);
}

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 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

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 (using Hardhat)

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.

More Repositories

1

token-generator

Create a Token in less than a minute with the most trusted Smart Contract Generator for ERC20 and BEP20. No login. No setup. No coding required.
Shell
78
star
2

solidity-linked-list

An utility library for working with sorted linked list data structures in your Solidity project.
JavaScript
70
star
3

watch-token

Create a link to your ERC20 Token or an embeddable Widget for your Website. Add your Token to DApp browsers or MetaMask.
Vue
50
star
4

eth-token-recover

TokenRecover allows to recover any ERC20 or NFT (ERC721) token sent into the contract and send them to a receiver.
JavaScript
40
star
5

solidity-starter-kit

A starter kit for Ethereum Smart Contracts development
JavaScript
27
star
6

coinmarketcap-php

A PHP wrapper for CoinMarketCap APIs
PHP
21
star
7

cryptogift

An ERC721 token and Crowdsale to buy and give away an Ethereum based Collectible Gift
JavaScript
18
star
8

vittominacori.github.io

Vittorio Minacori | Software Engineer, Blockchain & Web3, Author of ERC-1363.
Shell
8
star
9

changelly-php

A PHP wrapper for Changelly APIs
PHP
6
star
10

ethereum-badge

A simple DApp that allows you creating an Ethereum badge for your address to share or embed in your website.
Vue
4
star
11

funnychatgenerator

Create your funny chat screenshot for free. Generate WhatsApp like fake conversation online.
Twig
4
star
12

tinymce-youtube-plugin

Add YouTube video to your TinyMCE content
JavaScript
2
star
13

x-qrcode

Custom Polymer element to create QR Code.
HTML
2
star
14

speech-element

Custom Polymer element for speech synthesis and recognition.
CSS
1
star
15

flypme-php

A PHP wrapper for Flyp.me APIs
PHP
1
star
16

x-enhancer

Custom Polymer element for text enhancement.
CSS
1
star
17

messengerbank-metals

Smart Contracts for the MessengerBank Metals Token (MBM).
JavaScript
1
star
18

vuepress-plugin-facebook-pixel

VuePress Plugin for Facebook Pixel
JavaScript
1
star
19

blockchain-js

A very simple blockchain implementation with javascript.
JavaScript
1
star
20

arwebrtc

Take and share your own photo using Augmented Reality in your browser with WebRTC and JavaScript.
JavaScript
1
star