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)
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.