switchEtherNetwork

The switchEtherNetwork function expects a chainId in HEX base. You can parse a decimal id using the parse nano-module.

import { switchEtherNetwork } from "@forta/usemetamask"
const RIKEBY_ID = "0x4"
function SwitchToRinkeby() {
return (
<Button onClick={() => switchEtherNetwork(RIKEBY_ID)}>
Switch Network
</Button>
)
}

Example using a decimal chainId using the parse nano-module.

import { switchEtherNetwork, parse } from "@forta/usemetamask"
const RIKEBY_ID = oarse.toHex(4) // 0x4
function SwitchToRinkeby() {
return (
<Button onClick={() => switchEtherNetwork(RIKEBY_ID)}>
Switch Network
</Button>
)
}