Cosmos
Wallet Standard
Method | Parameters | Return Value | Description |
---|---|---|---|
connect | chainId?: string | Promise<void> | Connect to the wallet |
disconnect | None | Promise<void> | Disconnect from the wallet |
getAccount | chainId: string | Promise<{address: string, pubkey: Uint8Array}> | Get account info for the specified chain |
getOfflineSignerAuto | chainId: string | Promise<OfflineAminoSigner | OfflineDirectSigner> | Get an offline signer |
signArbitrary | chainId: string, signer: string, data: string | Promise<StdSignature> | Sign arbitrary data |
signDirect | chainId: string, signer: string, signDoc: SignDoc | Promise<DirectSignResponse> | Direct signing |
signAmino | chainId: string, signer: string, signDoc: StdSignDoc | Promise<AminoSignResponse> | Amino signing |
sendTx | chainId: string, tx: Uint8Array, mode: BroadcastMode | Promise<Uint8Array> | Send transaction |
Supported Shains
Chain | Chain ID | Description |
---|---|---|
MANTRA | mantra-mainnet-1 | A DeFi and staking protocol in the Cosmos ecosystem, focusing on compliant finance and cross-chain asset liquidity management. |
Celestia | celestia-mainnet-1 | Pioneering modular blockchain specializing in data availability layers to provide scalable infrastructure for other chains. |
Coreum | coreum-mainnet-1 | Enterprise-grade blockchain supporting WASM smart contracts, emphasizing interoperability and financial compliance. |
Saga | saga-mainnet-1 | Application-specific chain protocol for gaming/entertainment, offering one-click chain deployment and horizontal scalability. |
Cosmos Hub | cosmoshub-4 | Core hub of the Cosmos ecosystem, enabling cross-chain interoperability via IBC protocol. Native token: ATOM. |
Xion | xion-mainnet-1 | User-centric universal abstraction layer, providing end-to-end abstraction for accounts, fees, and interactions. |
Nillion | nil-chain-mainnet-1 | Privacy-focused compute network leveraging non-blockchain architecture (NMC) for high-speed confidential data processing. |
Osmosis | osmosis-1 | Leading DEX in Cosmos, specializing in cross-chain liquidity and innovative AMM mechanisms. |
Connect to Bitget Wallet
Provider
const provider = window.bitkeep && window.bitkeep.keplr;
Account
get account info, such as address or public and so on
Usage
getKey(chainId: string): Promise<{
// Name of the selected Wallet.
name: string;
algo: string;
pubKey: Uint8Array;
address: Uint8Array;
bech32Address: string;
}>
Try It
Enable
Usage
enable(chainId: string): Promise<void>
Try It
Account Change Event
监听账户变化事件。
Usage
provider.on('keplr_keystorechange', () => {
console.log('账户已变化')
})
Sign Message
- Signs arbitrary data using the specified account and chain ID.
- Commonly used for off-chain signing (e.g., user authentication or authorization).
Usage
interface StdSignature {
signature: string; // The actual signature string (typically base64-encoded)
pub_key: {
type: string; // The type of public key (e.g., "tendermint/PubKeySecp256k1")
value: string; // The base64-encoded public key value
};
}
/**
* Verifies a previously generated signature against the original data and signer.
* @param chainId - The chain ID used during signing
* @param signer - The Bech32 address of the signer
* @param data - The original data that was signed
* @param signature - The StdSignature object to verify
* @returns A promise that resolves to a boolean indicating whether the signature is valid
*/
function verifyArbitrary(
chainId: string,
signer: string,
data: string | Uint8Array,
signature: string
): Promise<boolean> {
// Implementation goes here
}
/**
* @param chainId - The chain ID (e.g., "cosmoshub-4")
* @param signer - The Bech32 address of the account performing the signature
* @param data - The raw data to be signed (as a string or byte array)
* @returns Promise<StdSignature> - A promise that resolves to a StdSignature object containing the signature and public key
*/
function signArbitrary(
chainId: string,
signer: string,
data: string | Uint8Array
): Promise<StdSignature> {
// Implementation goes here
}
Try It import from “@codes/Cosmos/SignArbitrary”;
Transaction
SignAmino
signAmino is a method used to sign transactions using the Amino JSON format, which is a legacy serialization format used in the Cosmos ecosystem (especially with older Cosmos SDK versions and wallets like Keplr).
Usage
// Represents a single unit of currency and its amount
interface Coin {
denom: string; // The unit of currency (e.g., "uatom")
amount: string; // The amount (as a string to support large integers)
}
// Represents the fee information for a transaction
interface StdFee {
amount: readonly Coin[]; // Array of fee amounts
gas: string; // Gas limit
granter?: string; // (Optional) Address of the fee granter
payer?: string; // (Optional) Address of the fee payer
}
// Represents an Amino message used in signing documents
interface AminoMsg {
type: string; // The type of the message (e.g., "cosmos-sdk/MsgSend")
value: any; // The actual message content (object structure depends on the message type)
}
// Represents the full document to be signed in Amino JSON format
interface StdSignDoc {
chain_id: string; // Chain ID
account_number: string; // Account number of the signer
sequence: string; // Sequence number for preventing replay
fee: StdFee; // Fee information
msgs: readonly AminoMsg[]; // Array of messages
memo: string; // Optional memo field for notes
timeout_height?: string; // (Optional) Timeout height for transaction expiration
}
interface SignAminoResponse {
signed: StdSignDoc,
signature: {
signature: string,
pub_key: {
type: string,
value: string
}
}
}
function signAmino(
chainId: string,
signer: string,
signDoc: StdSignDoc
): Promise<SignAminoResponse>
Try It
SignDirect
Params
signDirect(chainId:string, signer:string, signDoc: {
/** SignDoc bodyBytes */
bodyBytes?: Uint8Array | null;
/** SignDoc authInfoBytes */
authInfoBytes?: Uint8Array | null;
/** SignDoc chainId */
chainId?: string | null;
/** SignDoc accountNumber */
accountNumber?: Long | null;
}): Promise<DirectSignResponse>
Usage
import { TxBody, AuthInfo, SignerInfo, Fee } from 'cosmjs-types/cosmos/tx/v1beta1/tx'
import {MsgSend} from 'cosmjs-types/cosmos/bank/v1beta1/tx'
import {Any} from 'cosmjs-types/google/protobuf/any'
function getBodyBytes(from, to, v) {
const msgSend = MsgSend.fromPartial({
fromAddress: from,
toAddressL: to,
amount: [{ denom: "uosmo", amount: v}]
});
const msgSendAny = Any.fromPartial({
typeUrl: "/cosmos.bank.v1beta1.MsgSend",
value: MsgSend.encode(msgSend).finish()
});
const txBody = TxBody.fromPartial({
messages: [msgSendAny],
memo: "test",
timeoutHeight: '0',nonCriticalExtensionOptions: []
});
return TxBody.encode(txBody).finish();
}
function getAuthInfoBytes(pubKey, sequence) {
const pubKeyAny = Any.fromPartial({
typeUrl: '/cosmos.crypto.secp256k1.PubKey',
value: pubKey
})
const signerInfo = SignerInfo.fromPartial({
publicKey: pubKeyAny,
modeInfo: { single: { mode: 1 } },
sequence: sequence
})
const feeValue = Fee.fromPartial({
amount: [{ denom: "uosmo", amount: "600" }],
gasLimit: '200000',
"granter": "",
"payer": ""
})
const authInfo = AuthInfo.fromPartial({ signerInfos: [signerInfo], fee: feeValue })
return AuthInfo.encode(authInfo).finish()
}
interface SignAminoResponse {
signed: StdSignDoc,
signature: {
signature: string,
pub_key: {
type: string,
value: string
}
}
}
const signDoc = {
bodyBytes: getBodyBytes(),
authInfoBytes: authInfoBytes(),
chainId: 'osmosis-1',
accountNumber: '' //
}
function signDirect(
chainId: string,
signer: string,
signDoc
): Promise<SignAminoResponse>
Try It
SignDirectAux
SignDirectAux
interface
Attribute | Type | Description |
---|---|---|
bodyBytes | Uint8Array | Protobuf serialized representation of TxBody , matching TxRaw (required) |
chainId | string | Unique identifier of the target chain to prevent signature replay attacks (required) |
accountNumber | bigint | Account number in the state (required) |
signDirectAux is a variant signing method API. It allows the wallet to sign a transaction but does not return a complete signature object. Instead, it returns partial signature data. This is particularly useful for multi-signature (multi-sig) accounts, as they require multiple different signers to sign the transaction separately before combining the signatures.
Similar to CosmJS OfflineDirectSigner’s signDirect, but bitkeep signDirect requires chain-id as a mandatory parameter. Signs Proto-encoded StdSignDoc.
sendTx
Request Transaction Broadcast
sendTx(
chainId: string,
tx: Uint8Array,
mode: BroadcastMode
): Promise<Uint8Array>;