Company logo
  • Jobs
  • Bootcamp
  • About Us
  • For professionals
    • Home
    • Jobs
    • Courses
    • Questions
    • Teachers
    • Bootcamp
  • For business
    • Home
    • Our process
    • Plans
    • Assessments
    • Payroll
    • Blog
    • Calculator

0

52
Views
Web3 .send() method promise remains <pending>

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?

7 months ago ยท Juan Pablo Isaza
Answer question
Find remote jobs