Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Block.getTransaction always throws "no such tx" error #4867

Open
dumbeng opened this issue Oct 23, 2024 · 1 comment
Open

Block.getTransaction always throws "no such tx" error #4867

dumbeng opened this issue Oct 23, 2024 · 1 comment
Assignees
Labels
investigate Under investigation and may be a bug. v6 Issues regarding v6

Comments

@dumbeng
Copy link

dumbeng commented Oct 23, 2024

Ethers Version

6.13.4

Search Terms

provider

Describe the Problem

When using block.getTransaction("{0xTxHash}"), this will always fail due to a comparison issue in the Block class at src/providers/provider.ts.

 async getTransaction(indexOrHash: number | string): Promise<TransactionResponse> {
        // Find the internal value by its index or hash
        let tx: string | TransactionResponse | undefined = undefined;
        if (typeof(indexOrHash) === "number") {
            tx = this.#transactions[indexOrHash];

        } else {
            const hash = indexOrHash.toLowerCase();
            for (const v of this.#transactions) {
                if (typeof(v) === "string") {
                    if (v !== hash) { continue; }
                    tx = v;
                    break;
                } else {
                    if (v.hash === hash) { continue; } // <== This should be v.hash !== hash
                    tx = v;
                    break;
                }
            }
        }
        if (tx == null) { throw new Error("no such tx"); }
        // ...
}

But it's kind of weird that I cannot reproduce this in the playground, but this error happens every time when I run the code locally. Btw I can create a PR for this if needed.

Code Snippet

The following code should reproduce the issue:

await (await provider.getBlock(2000000, true)).getTransaction('0xc55e2b90168af6972193c1f86fa4d7d7b31a29c156665d15b9cd48618b5177ef')

Contract ABI

No response

Errors

The error is `no such tx`

Environment

node.js (v12 or newer)

Environment (Other)

No response

@dumbeng dumbeng added investigate Under investigation and may be a bug. v6 Issues regarding v6 labels Oct 23, 2024
@jasonandjay
Copy link

This is indeed a bug, we will fix it immediately.

Thank you for your feedback🫡

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
investigate Under investigation and may be a bug. v6 Issues regarding v6
Projects
None yet
Development

No branches or pull requests

4 participants
@ricmoo @jasonandjay @dumbeng and others