0

I'm trying to get a transaction once mining is done without a random timeout. I've checked similar questions but they aren't conclusive enough.

How do I get a transaction receipt once the mining is done?

Full code on Github.

try {
     ethereum
     .request({
      method: "eth_sendTransaction",
               params: [tx],
              })
             .then( 
              async (result) => 
              {
              let nftTxn = await nftContract.safeMint;
              console.log("Minting... please wait");
              const transactionReceipt = await web3.eth.getTransactionReceipt(result);
              await transactionReceipt.wait; //cannot await because of null
              if (transactionReceipt!=null) {
                console.log(`Mined... ${transactionReceipt}`);
              } else { console.log(`error`) }; //getting this
})

1 Answer 1

0

I think your question is partially answered here: How to wait until transaction is confirmed web3.js? This shows how to wait for a TX to be mined by periodically checking the output of getTransactionReceipt(...) untill it returns a value that is not null.

Also, I think there might be an issue with the following line:

let nftTxn = await nftContract.safeMint;

I think the method safeMint is not being called and is not making any transaction.

1
  • Thank you very much for your help. I was forced to use the interval solution in order to move forward, maybe, I'll be adding some function in my contract to get it in the cleanest way. If somebody wants to see my code, you can do it in my repo. Commented Feb 26, 2022 at 2:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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