Icon SunFilledIcon MoonStars

Icon LinkNetworks

Icon LinkGet the Current Network

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

const networkInfo = await fuel.network();
console.log("Network ", networkInfo);

Icon LinkAdding custom Network

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

await fuel.addNetwork(network);

Icon LinkListening for Network Changes

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

const handleNetworkChange = (network: FuelProviderConfig) => {
  setNetwork(network);
};
 
useEffect(() => {
  fuel?.on(fuel.events.network, handleNetworkChange);
 
  return () => {
    fuel?.off(fuel.events.network, handleNetworkChange);
  };
}, [fuel]);

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

Was this page helpful?