Skip to content

Conversation

mcmire
Copy link
Contributor

@mcmire mcmire commented Sep 4, 2025

In order to initialize the state of the StreamProvider, metamask_getProviderState must be called. In the extension, the current implementation of this RPC method retrieves the network version of the currently selected network via net_version and returns it along with other information. This creates a problem, however. Because the StreamProvider must be initialized in order to load the UI, if the network is slow or unresponsive, then users will see an infinite spinner until the request is resolved.

To fix this, we inform the RPC method that the StreamProvider is being initialized. The idea is that for this special case, the extension will opt not to make a request for the network version, returning "loading". For requests for metamask_getProviderState outside of StreamProvider this will not be the case and the network version will be retrieved as usual.

This means that StreamProvider will not have a network version initially. However, while they do expect metamask_getProviderState to return a networkVersion property, neither BaseProvider nor StreamProvider seem to do anything with it (unlike MetaMaskInpageProvider, which tracks it and allows dapps to read it).


Related to MetaMask/metamask-extension#34214.

Also see MetaMask/metamask-extension#35516 where this parameter is being used.

In order to initialize the state of the StreamProvider,
`metamask_getProviderState` must be called. In the extension, the
current implementation of this RPC method retrieves the network version
of the currently selected network via `net_version` and returns it along
with other information. This creates a problem, however. Because the
StreamProvider must be initialized in order to load the UI, if the
network is slow or unresponsive, then users will see an infinite spinner
until the request is resolved.

To fix this, we inform the RPC method that the StreamProvider is being
initialized. The idea is that for this special case, the extension will
opt not to make a request for the network version, returning "loading".
For requests for `metamask_getProviderState` outside of StreamProvider
this will not be the case and the network version will be retrieved as
usual.

This means that StreamProvider will not have a network version
initially. However, while they do expect `metamask_getProviderState` to
return a `networkVersion` property, neither BaseProvider nor
StreamProvider seem to do anything with it (unlike
MetaMaskInpageProvider, which tracks it and allows dapps to read it).
@mcmire mcmire marked this pull request as ready for review September 4, 2025 20:02
@mcmire mcmire requested a review from a team as a code owner September 4, 2025 20:02
@mcmire mcmire changed the title Pass isInitializingStream to metamask_getProviderState Pass isInitializingStreamProvider to metamask_getProviderState Sep 5, 2025
Copy link
Contributor

@cryptodev-2s cryptodev-2s left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants