Skip to content

JsonRpcProvider pollingInterval option is not used in tx.wait() #4644

@PierreJeanjacquot

Description

@PierreJeanjacquot

Ethers Version

[email protected]

Search Terms

JsonRpcProvider, pollingInterval

Describe the Problem

The pollingInterval option of JsonRpcProvider is not used for transaction wait(), instead a default 4000 ms value is used.

It may be linked to the pollingInterval value being hardcoded in the constructor.

this.#pollingInterval = 4000;

this fix in provider-jsonrpc.ts seems to do the trick but I did not check the other impacts:

export class JsonRpcApiPollingProvider extends JsonRpcApiProvider {
    #pollingInterval;
    constructor(network, options) {
        super(network, options);

        this.#pollingInterval = options.pollingInterval ?? 4000; // use option when it exists
    }

Also I'm not sure why 4000 is hardcoded as the value is available in defaultOptions.pollingInterval

Code Snippet

import { JsonRpcProvider, Wallet } from "ethers";

// The following snippet can be tested on a hardhat or anvil node with a 1s blocktime.

const provider = new JsonRpcProvider("http://localhost:8545", undefined, {
  pollingInterval: 1000,
});

const wallet = new Wallet(process.env.PRIVATE_KEY).connect(provider);

console.log("provider.pollingInterval", provider.pollingInterval);
// provider.pollingInterval 4000
console.log(
  'provider._getOption("pollingInterval")',
  provider._getOption("pollingInterval")
);
// provider._getOption("pollingInterval") 1000

const tx = await wallet.sendTransaction({ to: wallet.address, data: "0x" });
console.time("tx");
await tx.wait();
console.timeEnd("tx");
// tx: 4.094s

Contract ABI

No response

Errors

No response

Environment

No response

Environment (Other)

No response

Metadata

Metadata

Assignees

Labels

bugVerified to be an issue.fixed/completeThis Bug is fixed or Enhancement is complete and published.v6Issues regarding v6

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions