简体   繁体   English

如何判断ERC20令牌转移是否成功?

[英]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. 我整理了一些代码以使用web3.js 1.0.0-beta46发送一些令牌,然后决定尝试发送比我钱包里更多的令牌。 to my great surprise the transaction send succeeded and I got a txid, but of course the transfer failed 令我惊讶的是,交易发送成功,并且我收到了txid,但当然转移失败了

here's the attempt (on Ropsten): 这是尝试(在Ropsten上):

https://ropsten.etherscan.io/tx/0xaf2708dcc9b86b7cca0076e329a1e81fc28fdc4a97765b0a79544ec0685cfa69 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: etherscan仅表示:

ERC-20 Token Transfer Error (Unable to locate Corresponding Transfer Event Logs), Check with Sender ERC-20令牌传输错误(无法找到相应的传输事件日志),请与发送方联系

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. 现在,关于失败的转账,在阅读合同后,我注意到,如果资金不足,您简单地返回false即可进行有效交易。 What you should do is revert the transactions using require to make the checks. 您应该做的是使用require进行检查以还原交易。 That way an invalid transaction will be reverted by the EVM which will be recognized by etherscan and show that the transaction failed. 这样,EVM将还原无效的事务,该事务将被etherscan识别并显示事务失败。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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