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

eth_chainId called on every rpc call with WebSocketProvider #4441

Closed
qqqllppp opened this issue Oct 28, 2023 · 2 comments
Closed

eth_chainId called on every rpc call with WebSocketProvider #4441

qqqllppp opened this issue Oct 28, 2023 · 2 comments
Assignees
Labels
enhancement New feature or improvement. fixed/complete This Bug is fixed or Enhancement is complete and published. v6 Issues regarding v6

Comments

@qqqllppp
Copy link

qqqllppp commented Oct 28, 2023

Ethers Version

6.8.0

Search Terms

WebSocketProvider, eth_chainId

Describe the Problem

eth_chainId is being called on every eth_call type rpc call with WebSocketProvider. This is very wasteful on third-party node provider. Running in NodeJS environment. I have read all the eth_chainId related issues in ethersjs but no luck.

Code Snippet

import { Contract, WebSocketProvider } from "ethers";

const provider = new WebSocketProvider(
    `THIRD_PARTY_WSS_URL`,
    1
  );

const ct = new Contract(
    "0xb4e16d0168e52d35cacd2c6185b44281ec28c9dc",
    abi,
    provider
);

await ct.getReserves(); 
// An example of an eth_call method call. 
// Third-party node provider registers both eth_chainId and eth_call 
// every time the method is called. I only want eth_call to be registered.

Contract ABI

[
{
    "constant": true,
    "inputs": [],
    "name": "getReserves",
    "outputs": [
      { "internalType": "uint112", "name": "_reserve0", "type": "uint112" },
      { "internalType": "uint112", "name": "_reserve1", "type": "uint112" },
      {
        "internalType": "uint32",
        "name": "_blockTimestampLast",
        "type": "uint32"
      }
    ],
    "payable": false,
    "stateMutability": "view",
    "type": "function"
  },
]

Errors

No response

Environment

Ethereum (mainnet/ropsten/rinkeby/goerli), node.js (v12 or newer)

Environment (Other)

No response

@qqqllppp qqqllppp added investigate Under investigation and may be a bug. v6 Issues regarding v6 labels Oct 28, 2023
@ricmoo ricmoo added on-deck This Enhancement or Bug is currently being worked on. next-patch Issues scheduled for the next arch release. labels Nov 1, 2023
@ricmoo
Copy link
Member

ricmoo commented Nov 1, 2023

Agreed, I thought I had made that change before, but maybe that was in a previous version or an experimental branch.

I’m adding automatic re-subscription currently, and I think it makes sense to only request chain ID on a when the WebSocket connection is not over the same transport instance; so on initial connection, on re-connect and the intermediate getLogs calls between disconnect and re-connect to backfill the intermediate events before resuming the filter events.

@ricmoo ricmoo added the minor-bump Planned for the next minor version bump. label Nov 11, 2023
ricmoo added a commit that referenced this issue Nov 27, 2023
@ricmoo
Copy link
Member

ricmoo commented Nov 27, 2023

This has been fixed in 6.9.0 along with a few other useful staticNetwork features, such as passing true to auto-detect the network, but then prevent future calls.

Please try it out and let me know if you have any issues.

Thanks! :)

@ricmoo ricmoo closed this as completed Nov 27, 2023
@ricmoo ricmoo added enhancement New feature or improvement. fixed/complete This Bug is fixed or Enhancement is complete and published. and removed investigate Under investigation and may be a bug. on-deck This Enhancement or Bug is currently being worked on. minor-bump Planned for the next minor version bump. next-patch Issues scheduled for the next arch release. labels Nov 27, 2023
Woodpile37 pushed a commit to Woodpile37/ethers.js that referenced this issue Jan 14, 2024
Woodpile37 pushed a commit to Woodpile37/ethers.js that referenced this issue Jan 14, 2024
Woodpile37 pushed a commit to Woodpile37/ethers.js that referenced this issue Jan 14, 2024
rrw-zilliqa added a commit to Zilliqa/ethers.js that referenced this issue Apr 29, 2024
* docs: fixed typo in jsdocs for Wallet.createRandom (ethers-io#4461)

* admin: added diff scripts for build page

* admin: updated dist files

* Added safe and finalized provider events (ethers-io#3921).

* tests: bumped Node versions for testing (ethers-io#4451)

* admin: style fix (ethers-io#4356)

* More robust FallbackProvider broadcast (ethers-io#4186, ethers-io#4297, ethers-io#4442).

* Account for provider config weight when kicking off a request in FallbackProvider (ethers-io#4298).

* Fixed ParamType formatting causing bad tuple full and minimal ABI output (ethers-io#4329, ethers-io#4479).

* Added Base network to AlchemyProvider (ethers-io#4384).

* Add auto-detected static network support to providers and allow customizing socket provider options (ethers-io#4199, ethers-io#4418, ethers-io#4441).

* Use provider-specified suggested priority fee when available, otherwise fallback onto existing logic of 1 gwei (ethers-io#4463).

* admin: updated dist files

* admin: update changelog after build-clean

* docs: Fixed some grammar in getting-started (ethers-io#4486, ethers-io#4487, ethers-io#4488)

* Fix uncatchable issue when sending transactions over JSON-RPC and provide some retry-recovery for missing v (ethers-io#4513).

* admin: update dist files

* Fix Base58 padding for string representation of binary data (ethers-io#4527).

* admin: updated dist files

* Limit decoded result imflation ratio from ABI-encoded data (ethers-io#4537).

* admin: updated dist files

* Better debugging output on fetch errors.

* docs: added StaticJsonRpcProvider to migration docs

* Fixed typo in Error string (ethers-io#4539).

* Fix EIP-712 type aliases for uint and int (ethers-io#4541).

* Added additional sepolia testnets.

* Updated third-party provider network URLs (ethers-io#4542).

* admin: updated dist files

* Fixed normalization and abstracted EIP-712 Array parsing (ethers-io#4541).

* admin: updated dist files

* tests: added testing for correct thrid-party URLs

* Updated thrid-part provider URLs for QuickNode.

* tests: rename test suite to follow naming convention

* admin: updated dist files

* Normalize EIP-712 types before computing the payload (ethers-io#4541).

* tests: add tests for EIP-712 payload aliases

* admin: updated dist files

---------

Co-authored-by: Richard Moore <me@ricmoo.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or improvement. fixed/complete This Bug is fixed or Enhancement is complete and published. v6 Issues regarding v6
Projects
None yet
Development

No branches or pull requests

2 participants