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?

2 Answers 2


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 && txReceipt.blockNumber) {
        return txReceipt;

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

  • 1
    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, 2020 at 22:24

Now its:

    const txnCheck = async (txnHash) => {

        const provider = new ethers.providers.Web3Provider(ethereum);
        signer = provider.getSigner();
        let txn_test = await provider.getTransaction(txnHash);
        if (txn_test) {
            if (txn_test.blockNumber) {
                console.log("txn_test: ");
                return txn_test

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.