CosmosStaker
This class provides the functionality to stake, unstake, redelegate, and withdraw rewards for Cosmos-based blockchains.
It also provides the ability to retrieve staking information and rewards for a delegator.
Table of contents
Constructors
Methods
Constructors
constructor
β’ new CosmosStaker(params): CosmosStaker
This creates a new CosmosStaker instance.
Parameters
params
Object
Initialization parameters
params.rpcUrl
string
RPC URL (e.g. https://celestia.chorus.one:443) Please note that :port is required
params.lcdUrl
string
LCD URL (e.g. https://celestia-lcd.chorus.one:443) Please note that :port is required
params.bechPrefix
string
Address prefix (e.g. celestia)
params.denom
string
Coin denom (e.g utia)
params.denomMultiplier
string
Multiplier to convert the base coin unit to its smallest subunit (e.g., 1000000 for 1 TIA = 1000000 utia)
params.gas
number | "auto"
Default TX gas (e.g 200000). If set to "auto", the gas will be automatically estimated via RPC node.
params.extraGas?
number
(Optional) Additional "buffer" gas to be added to the gas limit (sometimes the gas estimation is not accurate, so this is a way to add a buffer)
params.fee?
string
(Optional) Override with a fixed fee (e.g "5000" for "5000 uatom" or "0.005 ATOM")
params.isEVM?
boolean
(Optional) Use different address derivation logic for EVM compatible chains (e.g. evmos, zetachain)
Returns
An instance of CosmosStaker.
Methods
getAddressDerivationFn
βΈ getAddressDerivationFn(params): (publicKey: Uint8Array, _derivationPath: string) => Promise<string[]>
This static method is used to derive an address from a public key.
It can be used for signer initialization, e.g. FireblocksSigner or LocalSigner.
Parameters
params
Object
Parameters for the address derivation
params.bechPrefix
string
Address prefix (e.g. celestia)
params.isEVM?
boolean
(Optional) Use different address derivation logic for EVM compatible chains (e.g. evmos, zetachain)
Returns
fn
Returns an array containing the derived address.
βΈ (publicKey, _derivationPath): Promise<string[]>
Parameters
publicKey
Uint8Array
_derivationPath
string
Returns
Promise<string[]>
init
βΈ init(): Promise<void>
Initializes the CosmosStaker instance and connects to the blockchain.
Returns
Promise<void>
A promise which resolves once the CosmosStaker instance has been initialized.
buildStakeTx
βΈ buildStakeTx(params): Promise<{ tx: EncodeObject }>
Builds a staking (delegation) transaction.
Parameters
params
Object
Parameters for building the transaction
params.delegatorAddress
string
The delegator (wallet) address to stake from
params.validatorAddress
string
The validator address to stake to
params.amount
string
The amount to stake, specified in base units of the native token (e.g. ATOM for Cosmos or TIA for Celestia)
Returns
Promise<{ tx: EncodeObject }>
Returns a promise that resolves to a Cosmos staking transaction.
buildUnstakeTx
βΈ buildUnstakeTx(params): Promise<{ tx: EncodeObject }>
Builds an unstaking (undelegate) transaction.
Parameters
params
Object
Parameters for building the transaction
params.delegatorAddress
string
The delegator (wallet) address that is unstaking
params.validatorAddress
string
The validator address to unstake from
params.amount
string
The amount to unstake, specified in base units of the native token (e.g. ATOM for Cosmos or TIA for Celestia)
Returns
Promise<{ tx: EncodeObject }>
Returns a promise that resolves to a Cosmos unstaking transaction.
buildRedelegateTx
βΈ buildRedelegateTx(params): Promise<{ tx: EncodeObject }>
Builds a redelegation transaction.
This allows a wallet to redelegate staked assets to a different validator without unstaking.
Parameters
params
Object
Parameters for building the transaction
params.delegatorAddress
string
The delegator (wallet) address
params.validatorSrcAddress
string
The source validator address to redelegate from
params.validatorDstAddress
string
The destination validator address to redelgate to
params.amount
string
The amount to redelegate, specified in base units of the native token (e.g. ATOM for Cosmos or TIA for Celestia)
Returns
Promise<{ tx: EncodeObject }>
Returns a promise that resolves to a Cosmos redelegation transaction.
buildWithdrawRewardsTx
βΈ buildWithdrawRewardsTx(params): Promise<{ tx: EncodeObject }>
Builds a withdraw (claim) rewards transaction.
Parameters
params
Object
Parameters for building the transaction
params.delegatorAddress
string
The delegator (wallet) address
params.validatorAddress
string
The validator address to withdraw (claim) rewards from
Returns
Promise<{ tx: EncodeObject }>
Returns a promise that resolves to a Cosmos withdraw (claim) rewards transaction.
getStake
βΈ getStake(params): Promise<{ balance: string }>
Retrieves the staked balance for a specified delegator.
Parameters
params
Object
Parameters for the request
params.delegatorAddress
string
The delegator (wallet) address
params.validatorAddress?
string
(Optional) The validator address to gather staking information from
Returns
Promise<{ balance: string }>
Returns a promise that resolves to the staking information for the specified delegator.
getUnbondingStake
βΈ getUnbondingStake(params): Promise<{ balance: string }>
Retrieves the unbonding balance for a specified delegator.
Parameters
params
Object
Parameters for the request
params.delegatorAddress
string
The delegator (wallet) address
params.validatorAddress?
string
(Optional) The validator address to gather staking information from
Returns
Promise<{ balance: string }>
Returns a promise that resolves to the unbonding information for the specified delegator.
getBalance
βΈ getBalance(params): Promise<{ balance: string }>
Retrieves the delegator's available balance.
Parameters
params
Object
Parameters for the request
params.delegatorAddress
string
The delegator (wallet) address
Returns
Promise<{ balance: string }>
Returns a promise that resolves to the available balance for the specified delegator.
getRewards
βΈ getRewards(params): Promise<{ rewards: string }>
Retrieves the rewards data for a specified delegator.
Parameters
params
Object
Parameters for the request
params.delegatorAddress
string
The delegator (wallet) address
params.validatorAddress?
string
The validator address to gather rewards data from
params.denom?
string
(Optional) The rewards coin denominator (default is the network denom)
params.denomMultiplier?
string
(Optional) The rewards coin denom multiplier (default is the network denom multiplier)
Returns
Promise<{ rewards: string }>
Returns a promise that resolves to the rewards data for the specified delegator.
sign
βΈ sign(params): Promise<{ signedTx: Uint8Array }>
Signs a transaction using the provided signer.
Parameters
params
Object
Parameters for the signing process
params.signer
Signer
Signer instance
params.signerAddress
string
The address of the signer
params.tx
EncodeObject
The transaction to sign
params.memo?
string
An optional memo to include with the transaction
Returns
Promise<{ signedTx: Uint8Array }>
A promise that resolves to an object containing the signed transaction.
broadcast
βΈ broadcast(params): Promise<DeliverTxResponse>
This method is used to broadcast a signed transaction to the Cosmos network.
Parameters
params
Object
Parameters for the broadcast
params.signedTx
Uint8Array
The signed transaction to be broadcasted
Returns
Promise<DeliverTxResponse>
Returns a promise that resolves to the response of the transaction that was broadcast to the network.
getTxStatus
βΈ getTxStatus(params): Promise<CosmosTxStatus>
Retrieves the status of a transaction using the transaction hash.
Parameters
params
Object
Parameters for the transaction status request
params.txHash
string
The transaction hash to query
Returns
Promise<CosmosTxStatus>
A promise that resolves to an object containing the transaction status.
Last updated
Was this helpful?