0

I know their might be examples online, but they do not really solve my issue.

So let us say I have the code below:

  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**/});
2
  • What do you mean by "before sending transaction"?! Before user confirm it or being mined?! Sep 14 at 22:47
  • Before it is mined. I mean just after it is signed by the user but before sending it to the blockchain to be mined.
    – YulePale
    Sep 15 at 2:15
1

I guess I found what you want But not sure.

async function creatChildContract(){
   tx = await this.factoryContract.createChild();
   tx.hash //returns hash of the transaction which user just signed.
}
4
  • No, I do not want to await for the transaction to be mined.
    – YulePale
    Sep 15 at 13:13
  • No, this await is waiting for user to sign the transaction, not transaction to be mined! Sep 15 at 15:59
  • My bad. You are right. :) Thank you.
    – YulePale
    Sep 16 at 3:17
  • No problem, my friend. Best regards. Sep 16 at 8:21
0

Finally found an answer to my problem:

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**/})
})

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.