Docs Icon ChevronRight For Developers Icon ChevronRight Networks

Networks

Get the Current Network

To detect the current network the user's wallet is connected to, use the network() method on the window.fuel object.

Network.tsx Icon Link
1const networkInfo = await fuel.network();
2console.log("Network ", networkInfo);

Adding custom Network

To add custom Network, use the wallet.addNetwork method and pass in the Network you want to add.

AddNetwork.tsx Icon Link
1await fuel.addNetwork(network);

Listening for Network Changes

To listen to network events, you can use the fuel.events.network event.

Network.tsx Icon Link
1const handleNetworkChange = (network: FuelProviderConfig) => {
2  setNetwork(network);
3};
4
5useEffect(() => {
6  fuel?.on(fuel.events.network, handleNetworkChange);
7
8  return () => {
9    fuel?.off(fuel.events.network, handleNetworkChange);
10  };
11}, [fuel]);

Switch the network in your wallet to see the event triggered.