0

As per ERC20 specification transfer returns bool:

function transfer(address _to, uint256 _value) returns (bool success);

I would prefer my token contract transfer() to revert on failure and return true on success. This way I would not have to worry that any of my contracts relying on my ERC20 is properly doing require(myToken.transfer(...))

Would this cause any issue for 3rd party contracts / applications ? Is there any which relies on a transfer which fails but they still want to perform something?

An alternative would be to create an additional safeTransfer function which calls transfer internally with require but it convolutes the tokenContract.

0

There are existing ERC20 token deployments that throw and others that return false. The guiding philosophy of atomic transactions however, is to 'if fail, fail early and fail fast' so the standard preferences throw/revert on a false conditions.

From the standard...

The function SHOULD throw if the _from account balance does not have enough tokens to spend.

Note Transfers of 0 values MUST be treated as normal transfers and fire the Transfer event.

  • Also you have to consider that some contracts never check the return value and they would assume the transfer was successful if no exception was throw. – Ismael Dec 19 '17 at 16:07

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.