I'm working on a DAPP that connects to a smart contract through Web3 and MetaMask. I'm calling a claim method on the contract as follows:
try {
const claimRes = await batchClaimTokenRewards(tokensArray, weeksArray);
console.log('claim response: ', claimRes);
this.getNftDataFromContract();
} catch(error) {
console.log('claim error: ', error);
}
The batchClaimTokenRewards function is imported from another file, here's that function as well:
export async function batchClaimTokenRewards(tokensArray:string[], weeksArray:string[]) {
return distributionContract.methods.batchClaimTokenRewards(tokensArray, [weeksArray]).send({from: web3.utils.toChecksumAddress('<metamask address>')});
}
From my understanding, the .send() method called on the contract instance should return a promise, which I should be able to await
, however, the line where I'm trying to console.log claimRes
is never reached, even as MetaMask shows the transaction as completed. The catch()
expression is never reached either. When I log claimRes without using await
on the promise, I get a <pending>
promise in the Chrome console that remains in the <pending>
state and never gets resolved, again, even as MetaMask itself reports the transaction as completed. What can I do to reliably get confirmation of a completed transaction?