The wallet_switchEthereumChain is a RPC call quite used in application, it would be useful to add a dedicated method for it. See the MetaMask doc for more information.
The goal of this method would only to be a wrapper around the ethereum.request({ method: "wallet_switchEthereumChain", params: [{ chainId }] }) promise, it would be declared in the MetaMaskProvider and exposed through the context.
If the provider is still in the initialisation phase or if MetaMask is unavailable (statuses unavailable and initializing, the method should log a warn and resolve, in the same spirit than the connect method.
A possible signature could be
// chainId must be of the form of a hex string, i.e. "0x12"
(chainId: string) => Promise<void>
Acceptance criteria
The new method is added and available with useMetaMask and useConnectedMetaMask
Tests are added
README is updated with either a dedicated part for it or either added in some way in the current descriptions
Description
The
wallet_switchEthereumChain
is a RPC call quite used in application, it would be useful to add a dedicated method for it. See the MetaMask doc for more information.The goal of this method would only to be a wrapper around the
ethereum.request({ method: "wallet_switchEthereumChain", params: [{ chainId }] })
promise, it would be declared in theMetaMaskProvider
and exposed through the context.If the provider is still in the initialisation phase or if MetaMask is unavailable (statuses
unavailable
andinitializing
, the method should log a warn and resolve, in the same spirit than theconnect
method.A possible signature could be
Acceptance criteria
useMetaMask
anduseConnectedMetaMask