Git Product home page Git Product logo

feeless's Introduction

Feeless

Build Status Coverage Status

Solidity Contract that allows anyone trustless pay fees for anyone

Installation

  1. Install truffle globally with npm install -g truffle
  2. Install ganache-cli globally with npm install -g ganache-cli
  3. Install local packages with npm install
  4. Run ganache in separate terminal scripts/rpc.sh
  5. Run tests with npm test

On macOS you also need to install watchman: brew install watchman

Usage

  1. Inherit your smart contract from Feeless smaert contract
  2. Add feeless modifier for any methods you wanna allow to call indirectly
  3. Use msgSender instead of msg.sender in these methods and methods internally called by them

For example token smart contract allowing to delegate transfers:

contract MyToken is StandardToken, Feeless {

    string public constant symbol = "XXX";
    string public constant name = "MyToken";
    uint8 public constant decimals = 18;
    string public constant version = "1.0";

    function transfer(address _to, uint256 _value) public feeless returns (bool) {
        balances[msgSender] = balances[msgSender].sub(_value);
        balances[_to] = balances[_to].add(_value);
        Transfer(msgSender, _to, _value);
        return true;
    }

}

Now you can delegate anyone to perform your (wallet1) transaction:

const target = myToken.options.address;
const nonce = await myToken.methods.nonces(wallet1).call();
const data = await myToken.methods.transfer(wallet2, 5 * 10**18).encodeABI();
const hash = web3.utils.sha3(target + data.substr(2) + web3.utils.toBN(nonce).toString(16,64));
const sig = await web3.eth.accounts.sign(hash, wallet1PrivateKey);

Now receiver (wallet2) is able to pay transaction fees for sender (wallet1):

await myToken.performFeelessTransaction(wallet1, target, data, nonce, sig).send({ from: wallet2 });

Future

  • Do not have replay-protection, delegated call can be performed in multiple chains (networks). To implement protection we need to introduce block.chain_id variable to EVM: ethereum/EIPs#901
  • Wanna get rid of msgSender by adding something like target.authorizedcall(data, nonce, sig) to EVM: ethereum/EIPs#1035

feeless's People

Contributors

k06a avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.