简体   繁体   中英

Web3.js: Get return value from contract method execution

I have ERC-20 token smart-contract which methods I call using sendSignedTransaction from web3.js. After I know transaction is succesfully mined I need to check contract method execution result. How do I do it if all I have is transaction hash?

Example: method transferFrom(from, to, tokens) returns true or false depending on whether transferring was successful. So if I try to transfer 100 tokens from empty wallet, contract method will return false .

Upd: Okay, as I understood there is no way of determining method outcome using txHash after transaction is mined and confirmed. Then which ways exists to handle this case? How can I make sure that tokens were transferred?

您可以在合同代码内部发出一个事件(实际上在ERC20标准中始终存在一个转移事件),然后在web3js内部,使用以下代码行读取所有事件,直到最新的代码块为止:

Events = Contract.eventName({}, {fromBlock: 0, toBlock: 'latest'});

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