1

In ethers.js is there any way I can check whether a hash is mined and confirmed so that I know it is not reverted and valid?

-1

In order to know whether a transaction (transactionHash) has been mined and confirmed, the following steps are required:

  1. Get the transaction receipt
  2. Check whether the transaction has been included in a block i.e. the blockNumber is not null

Below is the code snippet for achieving this:

const isTransactionMined = async(transactionHash) => {
    const txReceipt = await provider.getTransactionReceipt(transactionHash);
    if (txReceipt.blockNumber) {
        return txReceipt;
    }
}

In this way you can check whether the transaction has been mined.

| improve this answer | |
  • Close, but no banana. This does not take into account that txReceipt itself may be null. I just ran a version of this solution and ended up with Cannot read property 'blockNumber' of null. – Cliff Hall Apr 15 at 22:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.