Methods
This section provides an overview of the key methods available in the Chorus One Polygon SDK for staking operations.
The Chorus One SDK supports various staking operations including delegating, undelegating, withdrawing, claiming rewards, and compounding. Below, we explore each method with practical examples to help you get started.
buildApproveTx
Description
The buildApproveTx method creates a transaction to approve the StakeManager contract to spend POL tokens on behalf of the delegator.
This approval must be executed before staking if the current allowance is insufficient.
How to Use
To build an approval transaction, you need to specify the amount of POL tokens to approve. You can pass "max" for unlimited approval.
Example
const { tx } = await staker.buildApproveTx({
amount: '1000' // Approve 1000 POL
})
// Or for unlimited approval:
const { tx: unlimitedTx } = await staker.buildApproveTx({
amount: 'max'
})buildStakeTx
Description
The buildStakeTx method allows you to create a transaction for staking (delegating) POL tokens with a validator.
Staking tokens involves delegating them to a validator via their ValidatorShare contract, supporting the network's security, and in return, you earn rewards.
Note: Staking automatically claims any pending rewards in the same transaction. The ValidatorShare contract calls
_withdrawAndTransferRewardbefore executing the stake, so pending rewards are transferred to your wallet and the reward counter resets to 0.
How to Use
To build a staking transaction, you will need to specify:
delegatorAddress: The delegator's Ethereum address
validatorShareAddress: The validator's ValidatorShare contract address
amount: The amount to stake in POL
slippageBps: (Optional) Slippage tolerance in basis points (e.g., 50 = 0.5%). Used to calculate minSharesToMint automatically.
minSharesToMint: (Optional) Minimum validator shares to receive for slippage protection. Use this OR slippageBps, not both.
referrer: (Optional) Custom referrer string for tracking. Defaults to
'sdk-chorusone-staking'.
Example
In this example, we're staking 100 POL with the Chorus One validator.
buildUnstakeTx
Description
The buildUnstakeTx method creates a transaction to unstake POL tokens from a validator.
After unstaking, there is an unbonding period of approximately 80 checkpoints (around 3-4 days) before the tokens can be withdrawn.
Note: Unstaking automatically claims any pending rewards in the same transaction. The ValidatorShare contract calls
_withdrawAndTransferRewardbefore executing the unstake, so pending rewards are transferred to your wallet and the reward counter resets to 0.
How to Use
To build an unstaking transaction, you need to specify:
delegatorAddress: The address of the delegator
validatorShareAddress: The validator's ValidatorShare contract address
amount: The amount of POL to unstake
slippageBps: (Optional) Slippage tolerance in basis points (e.g., 50 = 0.5%). Used to calculate maximumSharesToBurn automatically.
maximumSharesToBurn: (Optional) Maximum validator shares willing to burn for slippage protection. Use this OR slippageBps, not both.
referrer: (Optional) Custom referrer string for tracking. Defaults to
'sdk-chorusone-staking'.
Example
In this example, we are creating an unbond request to unstake 50 POL.
buildWithdrawTx
Description
The buildWithdrawTx method creates a transaction to claim unstaked POL tokens after the unbonding period has elapsed.
You can use getUnbond() to check if the unbonding period is complete and getUnbondNonce() to get the latest unbond nonce.
Understanding Unbond Nonces
Each unstake operation creates a separate unbond request with its own nonce. Unbonds are NOT batched together.
Nonces are incremental per delegator, starting from 1
First unstake = nonce 1, second unstake = nonce 2, etc.
Each unbond has its own 80-checkpoint countdown
Withdrawals must be done separately for each nonce
Example scenario:
Day 1: Unstake 100 POL β creates unbond nonce 1 (withdrawable ~Day 4)
Day 2: Unstake 50 POL β creates unbond nonce 2 (withdrawable ~Day 5)
Day 4: You can withdraw nonce 1, but nonce 2 is still locked
Day 5: Now you can withdraw nonce 2
How to Use
To build a withdrawal transaction, you need to specify the delegator's address, the validator's ValidatorShare contract address, and the specific unbond nonce to withdraw.
Example
buildClaimRewardsTx
Description
The buildClaimRewardsTx method creates a transaction to claim accumulated delegation rewards.
The rewards are sent directly to the delegator's wallet.
How to Use
To build a claim rewards transaction, you need to specify:
delegatorAddress: The delegator's address that will receive the rewards
validatorShareAddress: The validator's ValidatorShare contract address
referrer: (Optional) Custom referrer string for tracking. Defaults to
'sdk-chorusone-staking'.
Example
buildCompoundTx
Description
The buildCompoundTx method creates a transaction to compound (restake) accumulated rewards.
This restakes your rewards back into the validator, increasing your delegation without requiring new tokens.
How to Use
To build a compound transaction, you need to specify:
delegatorAddress: The delegator's address
validatorShareAddress: The validator's ValidatorShare contract address
referrer: (Optional) Custom referrer string for tracking. Defaults to
'sdk-chorusone-staking'.
Example
getStake
Description
The getStake method retrieves the staking information for a specified delegator, including the amount of POL tokens currently staked with a specified validator.
Returns:
balance: Total staked amount formatted in POLshares: Total shares held by the delegatorexchangeRate: Current exchange rate between shares and POL
How to Use
To get staking information, you will need to provide the delegator's address and the validator's ValidatorShare contract address.
Example
getLiquidRewards
Description
The getLiquidRewards method retrieves the pending rewards available to claim for a delegator.
How to Use
To get pending rewards, you will need to provide the delegator's address and the validator's ValidatorShare contract address.
Example
getUnbondNonce
Description
The getUnbondNonce method retrieves the latest unbond nonce for a delegator.
The nonce represents the total number of unstake operations performed by the delegator. Each unstake creates a new unbond request with an incrementing nonce (starting from 1).
For example, if getUnbondNonce() returns 3n, the delegator has performed 3 unstake operations, with unbonds stored at nonces 1, 2, and 3.
How to Use
To get the unbond nonce, you will need to provide the delegator's address and the validator's ValidatorShare contract address.
Example
getUnbond
Description
The getUnbond method retrieves information about a specific unbond request.
Returns:
amount: The amount pending withdrawal in POL.isWithdrawable: Whether the unbond can be withdrawn now.shares: The shares amount pending withdrawal. Returns0nif the unbond has already been withdrawn or doesn't exist.withdrawEpoch: The epoch when the unbond was created. The unbond becomes claimable atwithdrawEpoch + withdrawalDelay.
How to Use
To get unbond information, you will need to provide the delegator's address, the validator's ValidatorShare contract address, and the specific unbond nonce to query.
Example
getUnbonds
Description
The getUnbonds method retrieves unbond request information for multiple nonces efficiently in a single RPC call.
This is more efficient than calling getUnbond() multiple times when you need to check several unbond requests.
How to Use
To get multiple unbond information, provide the delegator's address, the validator's ValidatorShare contract address, and an array of unbond nonces to query.
Example
getEpoch
Description
The getEpoch method retrieves the current checkpoint epoch from the StakeManager contract.
This can be used in combination with getWithdrawalDelay() to check if an unbonding period has elapsed.
How to Use
Call the method without any parameters to get the current epoch.
Example
getWithdrawalDelay
Description
The getWithdrawalDelay method retrieves the withdrawal delay from the StakeManager contract.
The withdrawal delay is the number of epochs that must pass after an unbond request before the funds can be withdrawn (~80 checkpoints, approximately 3-4 days).
How to Use
Call the method without any parameters to get the withdrawal delay.
Example
getAllowance
Description
The getAllowance method retrieves the current POL token allowance for the StakeManager contract.
Use this to check if approval is needed before staking.
How to Use
To get the allowance, provide the token owner's address.
Example
getExchangeRatePrecision
Description
The getExchangeRatePrecision method retrieves the exchange rate precision for a validator.
Foundation validators (ID < 8) use a precision of 100, while all other validators use 10^29. This is relevant when performing manual share/amount calculations.
How to Use
Provide the validator's ValidatorShare contract address.
Example
sign
Description
The sign method signs a transaction using the provided signer (e.g., Fireblocks, local mnemonic).
How to Use
To sign a transaction, you need to specify:
signer: A signer instance (e.g.,
FireblocksSigner,LocalSigner)signerAddress: The address of the signer
tx: The transaction to sign (from any
build*Txmethod)baseFeeMultiplier: (Optional) Multiplier applied to the base fee per gas from the latest block to determine
maxFeePerGas. Defaults to1.2.defaultPriorityFee: (Optional) Overrides the
maxPriorityFeePerGasestimated by the RPC, specified in ETH (e.g.,'0.000000001'for 1 gwei).
Example
Exported Constants
The @chorus-one/polygon package exports the following constants:
CHORUS_ONE_POLYGON_VALIDATORS
Chorus One ValidatorShare contract addresses for mainnet and testnet
NETWORK_CONTRACTS
StakeManager and staking token contract addresses per network
VALIDATOR_SHARE_ABI
ABI for the ValidatorShare contract
STAKE_MANAGER_ABI
ABI for the StakeManager contract
EXCHANGE_RATE_PRECISION
Exchange rate precision for foundation validators (100n)
EXCHANGE_RATE_HIGH_PRECISION
Exchange rate precision for non-foundation validators (10n ** 29n)
Exported Types
The following TypeScript types are exported:
PolygonNetworkConfig
Configuration for initializing PolygonStaker (network, rpcUrl)
Transaction
Transaction object returned by build*Tx methods (to, data, value)
PolygonTxStatus
Transaction status from getTxStatus (status, receipt)
StakeInfo
Staking info from getStake (balance, shares, exchangeRate)
UnbondInfo
Unbond info from getUnbond/getUnbonds (amount, isWithdrawable, shares, withdrawEpoch)
PolygonNetworks
Network type: 'mainnet' or 'testnet'
NetworkContracts
Contract addresses type (stakeManagerAddress, stakingTokenAddress)
Further Reading
For more detailed information and additional methods, please refer to the official API reference:
This guide aims to simplify the process of using the Chorus One Polygon SDK for staking operations.
Please follow the provided examples to integrate these functionalities into your applications.
Last updated
Was this helpful?