@0xsequence/connect
Version:
Connect package for Sequence Web SDK
38 lines • 1.66 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.useChain = void 0;
const wagmi_1 = require("wagmi");
/**
* Hook for retrieving chain configuration information from wagmi's chain configurations
*
* This hook provides functionality to:
* - Get the configuration for the currently connected chain
* - Get the configuration for a specific chain by ID
* - Access chain-specific details like name, network configuration, RPC URLs, and block explorers
*
* The hook is commonly used in conjunction with other Sequence hooks to access chain-specific
* information when working with transactions, indexer clients, or network-specific features.
*
* @see {@link https://docs.sequence.xyz/sdk/web/hooks/useChain} for more detailed documentation.
*
* @param chainId - Optional chain ID to get configuration for a specific chain. If not provided, returns the current chain's configuration.
* @returns Chain configuration object for the specified or current chain, or undefined if not found
*
* @example
* ```tsx
* // Get current chain configuration
* const currentChain = useChain();
* console.log('Current chain name:', currentChain?.name);
*
* // Get configuration for a specific chain
* const ethereumChain = useChain(1); // Ethereum Mainnet
* console.log('Ethereum chain details:', ethereumChain);
* ```
*/
const useChain = (chainId) => {
const chains = (0, wagmi_1.useChains)();
const currentChainId = (0, wagmi_1.useChainId)();
return chains.find(chain => (chainId ? chain.id === chainId : chain.id === currentChainId));
};
exports.useChain = useChain;
//# sourceMappingURL=useChain.js.map