PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Thursday, July 28, 2022

[FIXED] How to get a transaction receipt once minting is done

 July 28, 2022     blockchain, ethereum, reactjs, web3js     No comments   

Issue

I'm building the front end of my NFT Minting DApp using React.

I'm trying to print in the console the URL to etherscan/hash once the transaction has been minted, but rather I got the log when the transaction has started, so, it isn't already available in etherscan.

I've checked other sites but no one is conclusive enough.

How to get the transaction receipt once the minting process has been done?

try {
      ethereum
        .request({
          method: "eth_sendTransaction",
          params: [tx],
        })
        .then(
          
          async (result) => 
          {
          let nftTxn = await nftContract.safeMint;
          console.log("Minting... please wait");
          web3.eth.getTransactionReceipt(result)
          .then(console.log(`Mined, see transaction: https://ropsten.etherscan.io/tx/${result}`));
          }
        )

Solution

Finally, I did it. I decided to use interval. Source: here

if (result!=null){
            const interval = setInterval(()=>{
              console.log("Attempting to get transaction receipt...");
              web3.eth.getTransactionReceipt(result, function(err, rec){
                if (rec) {
                  console.log(`See transaciton in https://ropsten.etherscan.io/tx/${rec.transactionHash}`);
                  clearInterval(interval);
                } else {
                  console.log(err);
                }
              });
            }, 1000); 
          }


Answered By - appBegginer
Answer Checked By - Candace Johnson (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing