⌘K

Icon SunFilledIcon MoonStars
Networks

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.

Icon LinkWith React

In a react app you can use the useChain hook as shown below to get information about the current chain.

import { useChain } from '@fuel-wallet/react';
// ...
const { chain } = useChain();
console.log(chain.name);
// beta-4