Hook - useChains
- required provider: ChainProvider from either
@cosmos-kit/reactor@cosmos-kit/react-lite
To use
useChainswithChainProviderfrom@cosmos-kit/react-lite, propertywalletModalmust be provided. Or you can chooseChainProviderfrom@cosmos-kit/react, which providesDefaultModal. Or you can useuseChainWalletinstead.
- parameters:
- chainNames:
ChainName[] - sync:
boolean=true
- chainNames:
parameter
syncmeans whether to synchronize connection and disconnection to all other activated chainWallets.
- return type: Record<ChainName, ChainContext>
Usage
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' }
</Button>
<table className="table-fixed font-mono">
<thead>
<tr>
<th className="w-80">Code</th>
<th>Value</th>
</tr>
</thead>
<tbody>
<tr>
<td>chains.cosmoshub.address</td>
<td>{chains.cosmoshub.address}</td>
</tr>
<tr>
<td>chains.osmosis.address</td>
<td>{chains.osmosis.address}</td>
</tr>
<tr>
<td>chains.stargaze.address</td>
<td>{chains.stargaze.address}</td>
</tr>
<tr>
<td>chains.juno.address</td>
<td>{chains.juno.address}</td>
</tr>
<tr>
<td>chains.akash.address</td>
<td>{chains.akash.address}</td>
</tr>
</tbody>
</table>
</div>;
}