简体   繁体   中英

How to tell if an ERC20 token transfer succeeded?

I've cobbled together some code to send some tokens using web3.js 1.0.0-beta46 and then decided to try to send more token than I had in my wallet. to my great surprise the transaction send succeeded and I got a txid, but of course the transfer failed

here's the attempt (on Ropsten):

https://ropsten.etherscan.io/tx/0xaf2708dcc9b86b7cca0076e329a1e81fc28fdc4a97765b0a79544ec0685cfa69

now my question: how can I tell when the transfer succeeded? or for that matter how can I get the error message? etherscan merely indicates:

ERC-20 Token Transfer Error (Unable to locate Corresponding Transfer Event Logs), Check with Sender

The most simple and straightforward way would be to check the balances of sender and receiver before and after the transfer.

Now about the failed transfer, after reading the contract I noticed that in the event of insufficient funds you simple return false, which makes a valid transaction. What you should do is revert the transactions using require to make the checks. That way an invalid transaction will be reverted by the EVM which will be recognized by etherscan and show that the transaction failed.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM