Skip to content

Avoid eth_chainId call when creating a WebSocketProvider #1818

Answered by ricmoo
janschmutz asked this question in Q&A
Discussion options

You must be logged in to vote

Hi @ricmoo so I figured out in the end where all these eth_chainId requests come from with the websocket provider I think. Every time a new websocket provider instance is created (E.g. onclose handler is called or similar.) there is a single eth_chainId request conducted internally. In my case this happens quite often thus the number of requests. Is this necessary internally or is there a way to perhaps disable this feature?

This is necessary, but if you know the chainId you can pass it in as the second parameter to the WebSocketProvider connector, or even passing in the .getNetwork() promise should work, like:

// Replace the current provider, but re-use the network lookup
websocket = new 

Replies: 10 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by ricmoo
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
discussion Questions, feedback and general information.
3 participants
Converted from issue

This discussion was converted from issue #1797 on July 30, 2021 15:18.