WDK logoWDK documentation

Cosmos wallet API reference

Public API reference for @base58-io/wdk-wallet-cosmos version 1.0.0-beta.4.

This reference covers the public package surface published in @base58-io/wdk-wallet-cosmos@1.0.0-beta.4.

Community modules are developed and maintained independently by third-party contributors.

Tether and the WDK Team do not endorse or assume responsibility for their code, security, or maintenance. Use your own judgment and proceed at your own risk.

Repository main contains APIs that are not part of this release. Use the v1.0.0-beta.4 source tag when comparing this reference with code.

Package

FieldValue
Package@base58-io/wdk-wallet-cosmos
Version1.0.0-beta.4
Module formatESM
Default entryindex.js
Bare conditional entrybare.js
Type declarationstypes/index.d.ts
Runtime enginesNot declared in package.json
Peer dependenciesNone
WDK wallet dependency@tetherto/wdk-wallet@1.0.0-beta.8

The package export map exposes the root module and a ./package subpath for package.json. Internal files are not supported public entrypoints.

Root exports

ExportKindDescription
defaultRuntimeWalletManagerCosmos
WalletAccountCosmosRuntimeSeed-backed Cosmos account implementation
resolveChainConfig(config)RuntimeResolves registry or custom chain configuration
getAvailableChains()RuntimeReturns bundled registry names whose chain type is cosmos
isKnownChain(chainName)RuntimeChecks whether a name exists in the bundled registry
FeeRatesType onlyNormal and fast fee amounts
KeyPairType onlyPublic key and sensitive private-key fields
TransactionResultType onlyTransaction hash and fee
TransferOptionsType onlyDenomination, recipient, and amount
TransferResultType onlyTransfer hash and fee
CosmosWalletConfigType onlyInput wallet configuration
ResolvedChainConfigType onlyResolved chain configuration

WalletManagerCosmos

Constructor

new WalletManagerCosmos(seed, config?)
ParameterTypeRequiredDescription
seedstring | Uint8ArrayYesBIP-39 mnemonic or seed bytes
configCosmosWalletConfigNoChain, RPC, fee, retry, and IBC configuration

The released constructor does not accept an external signer. Named signer overloads visible on repository main are not published in 1.0.0-beta.4.

Inherited static methods

MethodReturnsDescription
WalletManagerCosmos.getRandomSeedPhrase(wordCount = 12)stringGenerates a 12- or 24-word BIP-39 mnemonic
WalletManagerCosmos.isValidSeedPhrase(seedPhrase)booleanValidates a BIP-39 mnemonic

Methods

MethodReturnsBehavior
getAccount(index = 0)Promise<WalletAccountCosmos>Derives and caches 0'/0/{index} below the chain coin type
getAccountByPath(path)Promise<WalletAccountCosmos>Derives and caches a relative suffix such as 0'/0/5
getFeeRates()Promise<FeeRates>Calculates normal and fast amounts for the fixed gas limit
dispose()voidDisposes cached accounts, zeros the manager seed bytes, and marks the manager unusable

Properties

PropertyTypeDescription
seedUint8ArrayInherited sensitive seed bytes; do not log or retain
isDisposedbooleanWhether dispose() has been called

getAccount() caches by relative derivation path. Disposing a cached account directly does not evict it from the manager; prefer disposing the manager at the end of its lifecycle.

getFeeRates()

const { normal, fast } = await manager.getFeeRates()

The returned values are deterministic fee amounts in the selected fee denomination:

  • registry configuration uses average and high gas-price tiers;
  • explicit gas-price configuration returns the same amount for both priorities;
  • final fallback uses 0.025 and 0.04;
  • all calculations use a gas limit of 200000.

The method requires at least one configured RPC endpoint but does not make an RPC request.

WalletAccountCosmos

Create accounts through WalletManagerCosmos. The exported static factory is also public:

const account = await WalletAccountCosmos.create(seed, "0'/0/0", config)

Do not call the class constructor directly. Its parameters are implementation details.

Account methods

MethodReturnsBehavior
getAddress()Promise<string>Returns the locally derived Bech32 address
getBalance(denom?)Promise<bigint>Reads one denomination; defaults to nativeDenom
getTokenBalance(denom)Promise<bigint>Alias behavior for a denomination-specific balance
getTokenBalances(denoms)Promise<Record<string, bigint>>Reads all balances and returns requested denominations that are present
quoteTransfer(options)Promise<{ fee: bigint }>Calculates a fixed-gas transfer fee without broadcasting
transfer(options)Promise<TransferResult>Sends a bank transfer or configured IBC transfer
sign(message)Promise<string>Returns a JSON-encoded ADR-36 StdSignature
verify(message, signature)Promise<boolean>Verifies ADR-36 data against this account
signTransaction(transaction)Promise<unknown>Returns a CosmJS signed TxRaw without broadcasting
quoteSendTransaction(transaction)Promise<{ fee: bigint }>Calculates a fixed-gas native-send fee
sendTransaction(transaction)Promise<TransactionResult>Signs and broadcasts a native bank send
getTransactionReceipt(hash)Promise<object>Returns the indexed transaction or throws when it is not found
toReadOnlyAccount()Never succeedsThrows because read-only accounts are not implemented
dispose()voidZeros the module-owned private-key buffer and marks the account unusable

Account properties

PropertyTypeDescription
indexnumberLast component of the full derivation path
pathstringFull path such as m/44'/118'/0'/0/0
keyPairKeyPairPublic key and the underlying sensitive private-key buffer
isDisposedbooleanWhether dispose() has been called

keyPair.privateKey exposes the account's underlying private-key bytes. Avoid using this property unless an integration requires it. Never log, serialize, or retain the value, and do not assume dispose() can erase copies held elsewhere.

Balance behavior

getBalance(), getTokenBalance(), and getTokenBalances() require RPC endpoints. Values are returned in base units.

getTokenBalances(denoms) calls the RPC all-balances query and filters it. A requested denomination with no returned balance is omitted rather than included with 0n.

Message signing

sign(message) signs UTF-8 text with ADR-36 and returns a JSON string containing the public key and base64 signature. verify():

  • binds the signature public key to this account's Bech32 address;
  • returns false for a different message or account;
  • returns false, rather than throwing, for malformed signature input.

Transaction input

signTransaction(), quoteSendTransaction(), and sendTransaction() consume the shared WDK transaction shape:

type Transaction = {
  to: string
  value: number | bigint
}

The account converts this input to one /cosmos.bank.v1beta1.MsgSend:

  • denomination is always the configured nativeDenom;
  • amount is value converted to a string;
  • memo is fixed to Transfer via WDK;
  • gas is fixed at 200000.

signTransaction() needs RPC to obtain signing context and returns a signed CosmJS TxRaw. Its generated beta declaration types the result as unknown.

sendTransaction() in 1.0.0-beta.4 accepts only the unsigned WDK transaction shape. It does not accept or broadcast the signed value returned by signTransaction().

quoteSendTransaction() ignores the transaction contents after receiving them. It checks for configured endpoints, calculates the fixed-gas fee, and applies transferMaxFee; it does not simulate or validate the transaction through RPC.

Transfer input

type TransferOptions = {
  token: string
  recipient: string
  amount: number | bigint
}
FieldMeaning
tokenCosmos denomination such as uatom or an IBC denomination
recipientDestination Bech32 address
amountInteger amount in base units

For matching Bech32 prefixes, transfer() calls a bank send. For a different prefix, it selects ibcChannels[recipientPrefix] and broadcasts IBC MsgTransfer with a fixed 600-second timestamp timeout.

transfer() checks transferMaxFee only after the bank or IBC operation has been signed and broadcast. A transfer can succeed on-chain and then throw the fee-limit error. Call quoteTransfer(), enforce an application limit, and validate the operation before transfer().

quoteTransfer() checks that an IBC channel mapping exists for a different prefix. It does not query RPC, simulate gas, validate the sender balance, or prove that the channel is active.

Transaction receipts

getTransactionReceipt(hash) performs one StargateClient.getTx() lookup. It returns the raw indexed transaction object when found. When the transaction is not yet indexed or does not exist, it throws:

Transaction not found: <hash>

The method does not poll.

CosmosWalletConfig

FieldTypeRequiredResolved behavior
chainNamestringNoSelects bundled registry metadata; unknown names throw
rpcEndpointsstring[]NoReplaces registry endpoints when non-empty
retryCountnumberNoDefaults to 3 retry rounds
retryDelaynumberNoDefaults to 150 milliseconds
addressPrefixstringNoRegistry prefix or cosmos
nativeDenomstringNoFirst registry fee denomination or uatom
coinTypenumberNoRegistry SLIP-44 value or 118
gasPricestringNoCompact amount and denomination such as 0.025uatom
transferMaxFeenumber | bigintNoQuote limit and post-broadcast transfer() check
ibcChannelsRecord<string, { sourceChannel: string }>NoIBC source channels keyed by destination prefix

See Configuration for precedence and safety details.

ResolvedChainConfig

resolveChainConfig() returns:

FieldType
rpcEndpointsstring[]
retryCountnumber
retryDelaynumber
addressPrefixstring
nativeDenomstring
coinTypenumber
gasPricestring | undefined
gasPriceStep{ low: number, average: number, high: number, denom: string } | undefined
transferMaxFeenumber | bigint | undefined
chainIdstring | undefined
prettyNamestring | undefined
ibcChannelsRecord<string, { sourceChannel: string }> | undefined

Helper functions

resolveChainConfig(config?)

Returns registry-backed or custom resolved configuration. An unknown chainName throws and instructs the caller to use custom configuration.

getAvailableChains()

Returns chain names whose bundled registry entry has chainType === 'cosmos'.

isKnownChain(chainName)

Returns whether any bundled registry entry has the supplied name. It does not test RPC reachability.

Error and lifecycle behavior

  • Invalid mnemonic and derivation paths reject account creation.
  • RPC-backed methods throw when the endpoint list is empty.
  • Most Cosmos ABCI, JSON-RPC validation, funds, gas, sequence, and signing errors are not retried.
  • Network-shaped errors can fall back or retry. A write error can therefore have an ambiguous on-chain outcome.
  • Every account operation except toReadOnlyAccount() checks disposal state; the read-only method always throws its unsupported error.
  • dispose() makes manager and account methods unusable, but it cannot revoke seed or key copies held by application code.

See Handle errors for safe write and recovery guidance.

On this page