Cosmos Kit
- useChains

Hook - useChains

  • required provider: ChainProvider from either @cosmos-kit/react or @cosmos-kit/react-lite

To use useChains with ChainProvider from @cosmos-kit/react-lite, property walletModal must be provided. Or you can choose ChainProvider from @cosmos-kit/react, which provides DefaultModal. Or you can use useChainWallet instead.

  • parameters:
    • chainNames: ChainName[]
    • sync: boolean = true

parameter sync means whether to synchronize connection and disconnection to all other activated chainWallets.


export default function () {
  const chains = useChains(['cosmoshub', 'osmosis', 'stargaze', 'juno', 'akash']);
  const connected = Object.values(chains).every(chain => chain.isWalletConnected);
  const { connect, openView } = chains.cosmoshub;
  // Notice: calling chains.chainName.connect() will connect to all 5 chains above.
  return <div className="space-y-4">
    <Button onClick={() => connected ? openView() : connect() }>
      { connected ? 'Disconnect' : 'Connect' }
    <table className="table-fixed font-mono">
          <th className="w-80">Code</th>