Cosmos Kit
Hooks
- useChain

Hook - useChain

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

To use useChain 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:
    • chainName: ChainName ( = string );
    • sync: boolean = true

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

Type - ChainContext

Properties

NameDescriptionTypeDefault
chainchain registry informationChain-
assetschain assets informationAssetList | undefinedundefined
walletcurrent selected wallet registry informationWallet | undefinedundefined
logoUrlchain logo urlstring | undefinedundefined
addresschain address from current selected walletstring | undefinedundefined
usernameusername from current selected walletstring | undefinedundefined
messageerror/warn/info messagestring | undefinedundefined
statuswallet statusWalletStatusDisconnected
isWalletDisconnectedif status === 'Disconnected'booleantrue
isWalletConnectingif status === 'Connecting'booleanfalse
isWalletConnectedif status === 'Connected'booleanfalse
isWalletRejectedif status === 'Rejected'booleanfalse
isWalletNotExistif status === 'NotExist'booleanfalse
isWalletErrorif status === 'Error'booleanfalse

Methods

NameDescriptionParametersReturn TypeIs Async
openViewopen modal-voidN
closeViewclose modal-voidN
connectconnect walletwallet?: WalletNamevoidY
disconnectdisconnect current selected wallet-voidY
getRpcEndpointreturn rpc endpoint, isLazy explanation is hereisLazy?: booleanstring | ExtendedHttpEndpointY
getRestEndpointreturn rest endpoint, isLazy explanation is hereisLazy?: booleanstring | ExtendedHttpEndpointY
getStargateClient--StargateClientY
getCosmWasmClient--CosmWasmClientY
getSigningStargateClientalways validate endpoint in method-SigningStargateClientY
getSigningCosmWasmClientalways validate endpoint in method-SigningCosmWasmClientY
getNameServiceget name service object supported on provided chain-NameServiceY
estimateFeeif type is undefined, default using SigningStargateClientmessages: EncodeObject[],
type?: CosmosClientType,
memo?: string,
multiplier?: number
StdFeeY
signusing cosmjs. if type is undefined, default using SigningStargateClientmessages: EncodeObject[],
fee?: StdFee,
memo?: string,
type?: CosmosClientType
TxRawY
broadcastif type is undefined, default using SigningStargateClientsignedMessages: TxRaw,
type?: CosmosClientType,
DeliverTxResponseY
signAndBroadcastif type is undefined, default using SigningStargateClientmessages: EncodeObject[],
fee?: StdFee,
memo?: string,
type?: CosmosClientType,
DeliverTxResponseY

Properties from Wallet Client

| Name | Description | Type | Default | | ---------------------- | ----------- | ------------------ | ---------- | ----------- | | qrUrl | - | Mutable\<string\> | undefined | undefined | | appUrl | - | Mutable\<AppUrl\> | undefined | undefined | | defaultSignOptions | - | SignOptions | as below |

defaultSignOptions:

{
    preferNoSetFee: false,
    preferNoSetMemo: true,
    disableBalanceCheck: true,
  };

Methods from Wallet Client

These methods are equal to wallet client methods with argument chainId assigned as chainId corresponding to hook argument chainName. If you want to directly use wallet client methods, choose hook useWalletClient instead.

NameDescriptionParametersReturn TypeIs Async
setDefaultSignOptions-options: SignOptionsvoidN
enable--voidY
getAccount--WalletAccountY
getOfflineSignerprioritize returning preferredSignType (in ChainProvider properties, by default amino) corresponding signer if it is available, otherwise return signer that is provided.-OfflineSignerY
getOfflineSignerAmino--OfflineAminoSignerN
getOfflineSignerDirect--OfflineDirectSignerN
signAmino-signer: string,
signDoc: StdSignDoc,
signOptions?: SignOptions
AminoSignResponseY
signDirect-signer: string,
signDoc: StdSignDoc,
signOptions?: SignOptions
DirectSignResponseY
sendTx-tx: Uint8Array,
mode: BroadcastMode
Uint8ArrayY

Advanced

Used for deeper dive into the chain and wallet related objects

NameDescriptionTypeDefault
chainWalletcurrent chainWalletChainWalletBase | undefinedundefined
walletRepowallet repository, you can get all the chainWallets from this repoWalletRepo-

Examples

fetch address (opens in a new tab)

fetch balance & send tokens (opens in a new tab)