Methods
This section provides an overview of the key methods available in the Chorus One SDK for staking on the Solana network.
The Chorus One SDK supports a range of staking operations including staking, unstaking, and withdrawing rewards. Below, we explore each method with practical examples to help you get started.
buildStakeTx
Description
The buildStakeTx method helps you create a transaction for staking tokens with a validator. Staking tokens involves locking them up to support the network's security and operations, and in return you earn rewards.
How to Use
To build a staking transaction, you need to specify the amount to stake, the stake owner's address (your wallet), and the validator's address where you want to stake your tokens.
Example
import { CHORUS_ONE_SOLANA_VALIDATOR } from '@chorus-one/solana'
const { tx } = await staker.buildStakeTx({
ownerAddress: '3Ps2hwsgGMSuqxAwjcGJHiEpMsSTZcxrCGprHgxWkfma',
validatorAddress: CHORUS_ONE_SOLANA_VALIDATOR,
amount: '1' // 1 SOL
})In this example, we are staking 1 SOL with a specified validator. The Solana Stake Account is created automatically, unless you pass the stakeAccountAddress argument.
buildUnstakeTx
Description
The buildUnstakeTx method allows you to create a transaction for unstaking tokens from a validator.
Unstaking involves deactivating your staked tokens, during which they enter an unbonding period. On the Solana network, the unbonding period typically lasts for one epoch, which is approximately 2.5 days. However, the exact duration can vary depending on when the unstaking request is made within the current epoch. During this period, your tokens are not earning rewards and cannot be transferred, as they are in the process of being released from staking.
After the unbonding period, the tokens will become available to withdraw.
How to Use
To build an unstaking transaction, you need to provide the stake account and it's owner (your wallet address).
Example
Here, we're unstaking all the SOL on the stake account.
buildWithdrawStakeTx
Description
The buildWithdrawStakeTx method allows you to create a transaction to withdraw the unbonded stake from a Solana staking account.
How to Use
To build a stake withdrawal transaction, you need to provide the stake account and it's owner address (your wallet address).
Example
Here, we are withdrawing all SOL from a stake account to the wallet owner's address.
To withdraw a specifc amount pass the amount arugment.
buildCreateStakeAccountTx
Description
The buildCreateStakeAccountTx method allows you to create a new Solana Stake Account.
How to Use
To build a new create staking account transaction, you will need to provide the owner address (your wallet) and the amount of SOL to transfer.
Example
Here, we are creating a new staking account with a balance of 1 SOL, which is being transfered from the owner's address (your wallet).
buildMergeStakesTx
Description
The buildMergeStakesTx method allows you to combine two stake accounts into one.
How to Use
To build a merge stakes transaction, you will need to provide the owner address (your wallet), the stake account source address, and the destination where the funds will be transferred to.
Example
Here, we are merging a source account stake into a different destination account. Please note, after this transaction, the source account will cease to exist.
buildSplitStakesTx
Description
The buildSplitStakesTx method allows you to split one stake account into two separate accounts.
How to Use
To build a split stake transaction, you will need to provide the owner's address (your wallet), the stake account address that is in use, and the amount of SOL you wish to split and transfer to new stake account.
Example
Here, we are substracting 1 SOL from the source stake account and transferring into a newly created stake account.
getStake
Description
The getStake method retrieves the staking information from a delegator.
This includes the amount of tokens currently staked with a validator.
How to Use
To get staking information, you need to provide the delegator's address (your wallet), and optionally the validator's address. If the validator's address is not provided, the method returns rewards from all validators.
You can also specify the status of the staker. Default is 'active'.
Example
In this example, we're retrieving the staked balance for a given delegator and validator.
Further Reading
For more detailed information and additional methods, please refer to the official API reference:
Last updated
Was this helpful?