Skip to content
Solidity Contract that allows anyone trustless pay fees for anyone
Branch: master
Clone or download
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
contracts Add target to signed data to avoid different tokens replay attack Apr 25, 2018
flow-typed First commit Apr 24, 2018
migrations First commit Apr 24, 2018
scripts First commit Apr 24, 2018
test Add target to signed data to avoid different tokens replay attack Apr 25, 2018
.babelrc First commit Apr 24, 2018
.gitignore First commit Apr 24, 2018
.solcover.js
.soliumignore First commit Apr 24, 2018
.soliumrc.json First commit Apr 24, 2018
.travis.yml First commit Apr 24, 2018
README.md Add target to signed data to avoid different tokens replay attack Apr 25, 2018
package-lock.json First commit Apr 24, 2018
package.json First commit Apr 24, 2018
truffle.js First commit Apr 24, 2018

README.md

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

You can’t perform that action at this time.