Staking
Operating a Bee full node and staking BZZ makes you eligible to participate in the redistribution game — a mechanism for earning additional BZZ by sharing disk space with the Swarm network. This guide shows how to use bee-js to deposit stake and check your node's staking status.
⚠️ Important: Committed stake is non-refundable. Only the surplus above the amount your node has committed to the redistribution game can be withdrawn, using bee.stake.withdrawSurplus.
The bee.stake namespace covers depositing stake, reading the staked and withdrawable amounts, withdrawing surplus stake, and checking the node's status in the redistribution game. Reserve doubling is configured on the node itself rather than through bee-js.
For a complete guide to the requirements and configuration for staking, refer to the Bee documentation.
Stake BZZ
To stake, use the bee.stake.deposit method. It accepts either a BZZ instance or a value in PLUR, the smallest unit of BZZ (like wei in Ethereum). The BZZ utility class simplifies conversion from a decimal string to PLUR. The initial deposit must be at least 10 BZZ.
import { Bee, BZZ } from '@ethersphere/bee-js'
const bee = new Bee('http://localhost:1633')
async function main() {
// Convert 10 BZZ to PLUR
const amount = BZZ.fromDecimalString('10')
const txHash = await bee.stake.deposit(amount)
console.log('Stake deposited. Transaction hash:', txHash.toHex())
}
main().catch(console.error)
Example output:
Stake deposited. Transaction hash: e1b86eebc54b465d84ab278da94a387e9786076557ab8f3fe04ba1b52dc065c8
A successful staking transaction will return the transaction hash which you can look up on a blockchain explorer like Gnosisscan.
Check Staking Status
After staking, you can confirm the deposited amount and monitor your node’s participation in the redistribution game:
import { Bee } from '@ethersphere/bee-js'
const bee = new Bee('http://localhost:1633')
async function main() {
const stake = await bee.stake.get()
const redistributionState = await bee.stake.getRedistributionState()
console.log('Current staked amount:', stake.toDecimalString(), 'BZZ')
console.log('\nRedistribution State:')
console.log(JSON.stringify(redistributionState, null, 2))
}
main().catch(console.error)
Example output:
Current staked amount: 10.0000000000000001 BZZ
Redistribution State:
{
"minimumGasFunds": {
"state": "274506772500000"
},
"hasSufficientFunds": true,
"isFrozen": false,
"isFullySynced": true,
"phase": "claim",
"round": 261311,
"lastWonRound": 0,
"lastPlayedRound": 0,
"lastFrozenRound": 0,
"lastSelectedRound": 0,
"lastSampleDurationSeconds": 0,
"block": 39719372,
"reward": {
"state": "0"
},
"fees": {
"state": "0"
},
"isHealthy": true
}
For details on interpreting these values, refer to the staking status section of the Bee documentation.
Withdraw Surplus Stake
Stake above the amount your node has committed to the redistribution game can be withdrawn back to the node wallet. Check how much is withdrawable first:
import { Bee } from '@ethersphere/bee-js'
const bee = new Bee('http://localhost:1633')
async function main() {
const withdrawable = await bee.stake.getWithdrawable()
console.log('Withdrawable stake:', withdrawable.toDecimalString(), 'BZZ')
const txHash = await bee.stake.withdrawSurplus()
console.log('Withdrawal transaction hash:', txHash.toHex())
}
main().catch(console.error)
bee.stake.migrate() withdraws the entire stake, and only works while the staking contract is paused for migration to a new contract. It is not a way to exit staking under normal conditions.