To detect the current network the user's wallet is connected to, use the network()
method on the window.fuel
object.
1const networkInfo = await fuel.network();
2console.log("Network ", networkInfo);
To add custom Network, use the wallet.addNetwork
method and pass in the Network
you want to add.
1await fuel.addNetwork(network);
To listen to network events, you can use the fuel.events.network
event.
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.