怎么验证交易是否成功

xiaoxiao2021-02-27  179

一般是通过event来查看的

event mylog(uint code); function test() { … mylog(0); } 发起交易后,根据eth.getTransactionReceipt()检索,结果大致如下 { “jsonrpc”:“2.0”, “id”:1, “result”:{ “blockHash”:“0xde5d1584b86db40a4ea64b8474f7b6d2c693f18ead347202f3c03a0d9904c672”, “blockNumber”:“0x186f”, “contractAddress”:null, “cumulativeGasUsed”:“0x92e79”, “from”:“0xe5684e632668d1bf0a84a60d98b3e7230695f568”, “gasUsed”:“0x10531”, “logs”:[ { “address”:“0xee1b3f3a4e5f2b2d3029b6b65f3684e73b437447”, “blockHash”:“0xde5d1584b86db40a4ea64b8474f7b6d2c693f18ead347202f3c03a0d9904c672”, “blockNumber”:“0x186f”, “data”:“0x0000000000000000000000000000000000000000000000000000000000000000”, “logIndex”:“0x8”, “topics”:[], “transactionHash”:“0x58a16df942e3fb4f7d3476c9c8af05b95368960eb43cafdb9c3ecac1c4e0d59a”, “transactionIndex”:“0x0” } ], “root”:“be061b18e7f402e4f1348e345316101c2939967ea5276564e0a698bc63c07de0”, “to”:“0xee1b3f3a4e5f2b2d3029b6b65f3684e73b437447”, “transactionHash”:“0x58a16df942e3fb4f7d3476c9c8af05b95368960eb43cafdb9c3ecac1c4e0d59a”, “transactionIndex”:“0x8” } }

如果返回结果中log节点不为空,且data的值为0,则说明合约中的test函数执行成功了。

转载请注明原文地址: https://www.6miu.com/read-15161.html

最新回复(0)