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);
To add custom Network, use the wallet.addNetwork
method and pass in the Network
you want to add.
await fuel.addNetwork(network);
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.