New to Solidity...

Is it possible to have a fee for transfers of an ERC20 Token in Ether? The fee would be 0.000001 Ether per transfer. Each time the ERC20 Token is sent to another user, the fee in Ether would be sent to a contract. Source example of how to transfer the fee in ether would be most helpful.

(note: this question does not pertain to gas fees. This refers to an additional fee in Ether for transfers of an ERC20 Token.)

  • ERC20 is a standard, nothing prevents you from overloading its functions. Apr 10 '18 at 7:45

You can see the specifications set out by the ERC-20 standard here.

For the relevant functions, transfer and transferFrom, there is no mention of mutability restrictions (or for any other function).

If you made these functions payable, and required that the value be 0.000001 ETH, it probably wouldn't be breaching the ERC-20 standard (as laid out by this document).

  • Can a payable function implement a non-payable function? Apr 10 '18 at 6:16
  • What do you mean by implement? A payable function can call a non-payable function. There is no mention in the standard of restrictions against being payable, and presumably if it were restricted they would have used the explicit nonpayable modifier. Apr 10 '18 at 6:25
  • The EIP20 is an interface which has functions which the interface implementation must implement. transfer is one of those functions so the implementing contract has to have a transfer function with the same signature. If a payable function can implement the function in the interface, then my answer is incorrect. But I couldn't find much info about this :( Apr 10 '18 at 6:29
  • Actually this is a good point, if the payable modifier is added to a function will the signature be different? I suspect it will, which probably means you're right. Apr 10 '18 at 6:31
  • No, adding payable doesn't change the function hash. The function hash is simply the hash of transfer(address,uint256) (or bytes4(keccak256("transfer(address,uint256)")), which is 0xa9059cbb), no return values, modifiers or mutability are considered for the function hash.
    – norganna
    Apr 10 '18 at 11:31

As per the ERC20 standard(https://theethereum.wiki/w/index.php/ERC20_Token_Standard), the answer is no.

But nothing stops you from extending the functionality. Extending it simply means that it has extra functionality on top of regular ERC20 functionality - users have to know about the extra functionality to be able to use it.

Here's one pretty standard implementation of a ERC20 token: https://github.com/ConsenSys/Tokens/blob/master/contracts/eip20/EIP20.sol If we look at the transfer function, we can add a similar function for example like this:

function transferWithFee(address _to, uint256 _value) public payable returns (bool success) {
        require(balances[msg.sender] >= _value);
        // require some amount of ether to be included in the transaction.
        require(msg.value >= 123);
        balances[msg.sender] -= _value;
        balances[_to] += _value;
        Transfer(msg.sender, _to, _value);
        return true;

All Ether sent to the function stays in the contract. Also you probably want to do something nasty to the original transfer function so people don't just use that but use this new function: you can for example just implement it as:

function transfer(address _to, uint256 _value) public returns (bool success) {
        return false;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.