Hook - useChain
- required provider: ChainProvider from either
@cosmos-kit/react
or@cosmos-kit/react-lite
To use
useChain
withChainProvider
from@cosmos-kit/react-lite
, propertywalletModal
must be provided. Or you can chooseChainProvider
from@cosmos-kit/react
, which providesDefaultModal
. Or you can useuseChainWallet
instead.
- parameters:
- chainName:
ChainName
( =string
); - sync:
boolean
=true
- chainName:
parameter
sync
means whether to synchronize connection and disconnection to all other activated chainWallets.
- return type: ChainContext
Type - ChainContext
Properties
Name | Description | Type | Default |
---|---|---|---|
chain | chain registry information | Chain | - |
assets | chain assets information | AssetList | undefined | undefined |
wallet | current selected wallet registry information | Wallet | undefined | undefined |
logoUrl | chain logo url | string | undefined | undefined |
address | chain address from current selected wallet | string | undefined | undefined |
username | username from current selected wallet | string | undefined | undefined |
message | error/warn/info message | string | undefined | undefined |
status | wallet status | WalletStatus | Disconnected |
isWalletDisconnected | if status === 'Disconnected' | boolean | true |
isWalletConnecting | if status === 'Connecting' | boolean | false |
isWalletConnected | if status === 'Connected' | boolean | false |
isWalletRejected | if status === 'Rejected' | boolean | false |
isWalletNotExist | if status === 'NotExist' | boolean | false |
isWalletError | if status === 'Error' | boolean | false |
Methods
Name | Description | Parameters | Return Type | Is Async |
---|---|---|---|---|
openView | open modal | - | void | N |
closeView | close modal | - | void | N |
connect | connect wallet | wallet?: WalletName | void | Y |
disconnect | disconnect current selected wallet | - | void | Y |
getRpcEndpoint | return rpc endpoint, isLazy explanation is here | isLazy?: boolean | string | ExtendedHttpEndpoint | Y |
getRestEndpoint | return rest endpoint, isLazy explanation is here | isLazy?: boolean | string | ExtendedHttpEndpoint | Y |
getStargateClient | - | - | StargateClient | Y |
getCosmWasmClient | - | - | CosmWasmClient | Y |
getSigningStargateClient | always validate endpoint in method | - | SigningStargateClient | Y |
getSigningCosmWasmClient | always validate endpoint in method | - | SigningCosmWasmClient | Y |
getNameService | get name service object supported on provided chain | - | NameService | Y |
estimateFee | if type is undefined , default using SigningStargateClient | messages: EncodeObject[] ,type?: CosmosClientType ,memo?: string ,multiplier?: number | StdFee | Y |
sign | using cosmjs . if type is undefined , default using SigningStargateClient | messages: EncodeObject[] ,fee?: StdFee ,memo?: string ,type?: CosmosClientType | TxRaw | Y |
broadcast | if type is undefined , default using SigningStargateClient | signedMessages: TxRaw ,type?: CosmosClientType , | DeliverTxResponse | Y |
signAndBroadcast | if type is undefined , default using SigningStargateClient | messages: EncodeObject[] ,fee?: StdFee ,memo?: string ,type?: CosmosClientType , | DeliverTxResponse | Y |
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 aschainId
corresponding to hook argumentchainName
. If you want to directly use wallet client methods, choose hookuseWalletClient
instead.
Name | Description | Parameters | Return Type | Is Async |
---|---|---|---|---|
setDefaultSignOptions | - | options: SignOptions | void | N |
enable | - | - | void | Y |
getAccount | - | - | WalletAccount | Y |
getOfflineSigner | prioritize returning preferredSignType (in ChainProvider properties, by default amino ) corresponding signer if it is available, otherwise return signer that is provided. | - | OfflineSigner | Y |
getOfflineSignerAmino | - | - | OfflineAminoSigner | N |
getOfflineSignerDirect | - | - | OfflineDirectSigner | N |
signAmino | - | signer: string ,signDoc: StdSignDoc ,signOptions?: SignOptions | AminoSignResponse | Y |
signDirect | - | signer: string ,signDoc: StdSignDoc ,signOptions?: SignOptions | DirectSignResponse | Y |
sendTx | - | tx: Uint8Array ,mode: BroadcastMode | Uint8Array | Y |
Advanced
Used for deeper dive into the chain and wallet related objects
Name | Description | Type | Default |
---|---|---|---|
chainWallet | current chainWallet | ChainWalletBase | undefined | undefined |
walletRepo | wallet repository, you can get all the chainWallets from this repo | WalletRepo | - |