ethersjs 如何获取合约send方法交易的返回值,只能等到交易的收据信息

代码如下,addWorks方法返回了一个uint的数据,不知道如何获取

function addWorks(string memory _collectionName,string memory _collectionDesc,string memory _collectionUrl ) public returns(uint)

交易收据结构如下

{
    transactionHash: "0x7dec07531aae8178e9d0b0abbd317ac3bb6e8e0fd37c2733b4e0d382ba34c5d2",

    // The block this transaction was mined into
    blockHash: "0xca1d4d9c4ac0b903a64cf3ae3be55cc31f25f81bf29933dd23c13e51c3711840",
    blockNumber: 3346629,

    // The index into this block of the transaction
    transactionIndex: 1,

    // The address of the contract (if one was created)
    contractAddress: null,

    // Gas
    cumulativeGasUsed: utils.bigNumberify("42000"),
    gasUsed: utils.bigNumberify("21000"),

    // Logs (an Array of Logs)
    log: [ ],
    logsBloom: "0x00" ... [ 256 bytes of 0 ] ... "00",

    // Post-Byzantium hard-fork
    byzantium: false

    ////////////
    // Pre-byzantium blocks will have a state root:
    root: "0x8a27e1f7d3e92ae1a01db5cce3e4718e04954a34e9b17c1942011a5f3a942bf4",

    ////////////
    // Post-byzantium blocks will have a status (0 indicated failure during execution)
    // status: 1
}
请先 登录 后评论

最佳答案 2021-10-26 17:23

这个结果只能在智能合约里调用的时候才能获取到。

在前端发起交易时,只能获取到交易信息。 你要么是编写一个 view 函数,来获得结果,或者是结果写入事件,前端通过解析事件来获得结果。

请先 登录 后评论

其它 0 个回答

  • 1 关注
  • 0 收藏,3045 浏览
  • Ethereal 提出于 2021-10-26 16:00