首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >代码示例:如何在发送事务之前获取事务哈希

代码示例:如何在发送事务之前获取事务哈希
EN

Ethereum用户
提问于 2021-09-14 16:21:08
回答 2查看 2.9K关注 0票数 0

我知道他们可能是网上的例子,但他们并没有真正解决我的问题。

所以让我们说,我有下面的代码:

代码语言:javascript
运行
复制
  this.factoryContract = new ethers.Contract(
    "factoryContractAddress",
    "factoryContractABI",
    signer
  );

  this.factoryContract.createChild()// how can I get transaction hash instead of waiting for it inside the "then(){}" callback?
    .then(()=>{/*do things here**/});
    .catch(()=>{/*do things here**/});
EN

回答 2

Ethereum用户

回答已采纳

发布于 2021-09-15 09:11:25

我想我找到了你想要的但不确定。

代码语言:javascript
运行
复制
async function creatChildContract(){
   tx = await this.factoryContract.createChild();
   tx.hash //returns hash of the transaction which user just signed.
}
票数 1
EN

Ethereum用户

发布于 2021-09-15 13:46:05

终于找到了我的问题的答案:

代码语言:javascript
运行
复制
async function creatChildContract(){
    this.factoryContract.createChild()
    .then((log)=>{
        console.log(log.hash);
        // here you can access the transaction hash before it is mined
        // you do not have to wait, once the transaction is confirmed, the hash is available.
    });
    .catch(()=>{/*do things here**/})
})
票数 1
EN
页面原文内容由Ethereum提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://ethereum.stackexchange.com/questions/109922

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档