Let's say I create an ERC20 token, and I want to collect 1,000 wei commission any time it replaces hands.
Here's Zeppelin transferFrom code:
function transferFrom(
address _from,
address _to,
uint256 _value
)
public
returns (bool)
{
require(_to != address(0));
require(_value <= balances[_from]);
require(_value <= allowed[_from][msg.sender]);
balances[_from] = balances[_from].sub(_value);
balances[_to] = balances[_to].add(_value);
allowed[_from][msg.sender] = allowed[_from][msg.sender].sub(_value);
emit Transfer(_from, _to, _value);
return true;
}
Is this the right way to override it to achieve my goal?
function transferFrom(
address _from,
address _to,
uint256 _value
)
public
returns (bool)
{
require(_to != address(0));
require(_value <= balances[_from]);
require(_value <= allowed[_from][msg.sender]);
// make sure I can collect 1000 wei commission
require(msg.sender.balance >= 1000)
balances[_from] = balances[_from].sub(_value);
balances[_to] = balances[_to].add(_value);
allowed[_from][msg.sender] = allowed[_from][msg.sender].sub(_value);
// collect the commission (assume myAddress is set to my address)
myAddress.transfer(1000);
emit Transfer(_from, _to, _value);
return true;
}
And now can I assume whoever the msg.sender
is, be it a smart contract (of an exchange perhaps?) or the _to
, will have to pay additional 1000 wei on top of the gas?