I am trying to add some extra functionality to my NFT minting dApp and check if a mint/transaction is actually succesful before executing a certain line of code. But i cant really connect the dots on this.
I found alot of examples to get the status by using the txn hash, but one first has to obtain this transaction hash right? Is there a way of obtaining the txn hash after starting up/confirming the transaction? This is the actual code where i send the transaction to the mint method in my contract:
const mint = async function (amount) {
const id = await ethereum.request({ method: 'eth_chainId' });
if (mintAcc != "")
{
var totalCost = WEI_COST * amount;
// if an account is present
if (mintAcc.length > 0 && id == CHAIN_ID) {
contract.methods.mint(amount).send({
from: mintAcc[0],
to: CONTRACT_ADDRESS,
value: String(totalCost),
});
}
} else {
alert("Connect wallet first")
}
}
What should i add to obtain the transaction hash/id after actually sending the mint method to track its status if its mined or not?
The reason im asking this is because im using an allowlist stored in a map which holds the value how many mints a specific adress can claim. After the claim took place i want to remove the persons adress so they cannot claim again.
The send() method returns a PromiEvent type that you can handle events on. One of these events is transactionHash
Code example:
contract.methods.mint(amount).send({
from: mintAcc[0],
to: CONTRACT_ADDRESS,
value: String(totalCost),
}).on("transactionHash", function(hash) {
console.log(hash);
});
Docs: https://web3js.readthedocs.io/en/v1.7.3/web3-eth-contract.html#methods-mymethod-send