useNetwork
Hook for accessing network data, such as current connected chain and connector chains.
import { useNetwork } from 'wagmi'
Usage
import { useNetwork } from 'wagmi'
function App() {
const { chain, chains } = useNetwork()
return (
<>
{chain && <div>Connected to {chain.name}</div>}
{chains && (
<div>Available chains: {chains.map((chain) => chain.name)}</div>
)}
</>
)
}
If you want the functionality to switch networks, check out
useSwitchNetwork
.
Return Value
{
chain?: Chain & { unsupported?: boolean }
chains: Chain[]
}