VGLoic / metamask-react

A simple Context provider and consumer hook in order to provide a simple API for interacting with MetaMask in the browser
MIT License
136 stars 24 forks source link

Add method for the wallet_switchEthereumChain RPC call #23

Closed VGLoic closed 2 years ago

VGLoic commented 2 years ago

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 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

github-actions[bot] commented 2 years ago

:tada: This issue has been resolved in version 2.4.0 :tada:

The release is available on:

Your semantic-release bot :package::rocket: