The ERC20 Token Standard dictates that functions transfer
and transferFrom
should return true
for success and false
for failure.
However, various ERC20 tokens deployed on the network have not implemented this requirement.
Subsequently, how would you go about asserting success or failure?
The only way that comes to mind is this:
uint256 prevSourceBalance = token.balanceOf(address(this));
uint256 prevTargetBalance = token.balanceOf(to);
token.transfer(to, amount);
uint256 currSourceBalance = token.balanceOf(address(this));
uint256 currTargetBalance = token.balanceOf(to);
assert(currSourceBalance == prevSourceBalance - amount);
assert(currTargetBalance == prevTargetBalance + amount);
But this verification method effectively adds a restriction which is not a part of the standard:
Function transfer
can theoretically:
- Return
true
without setting these balances correctly - Return
false
after setting these balances correctly
Is this restriction considered "legitimate enough" for me to impose it?
Otherwise, would you have any idea how else could I assert success or failure?
Thank you!!!