Skip to main content

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.

danger

⚠️ 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.

info

The bee.stake namespace covers depositing stake, reading the staked, withdrawable and minimum deposit amounts, withdrawing surplus stake, checking the node's status in the redistribution game, and pausing its participation. 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 deposit must be at least the minimum reported by bee.stake.getMinimumDeposit, otherwise Bee rejects it with 400. The method returns null when the node cannot determine the minimum, for example when the price oracle is unavailable.

import { Bee, BZZ } from '@ethersphere/bee-js'

const bee = new Bee('http://localhost:1633')

async function main() {
const minimum = await bee.stake.getMinimumDeposit()
console.log('Minimum deposit:', minimum ? `${minimum.toDecimalString()} BZZ` : 'unknown')

// 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:

Minimum deposit: 10.0000000000000000 BZZ
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,
"enabled": true,
"hasCommittedThisRound": false,
"hasRevealedThisRound": false
}

For details on interpreting these values, refer to the staking status section of the Bee documentation.

Pause Redistribution​

bee.stake.setRedistributionEnabled turns the node's participation in new redistribution rounds on or off, and returns the resulting state. The current state is reported in the enabled field of bee.stake.getRedistributionState().

import { Bee } from '@ethersphere/bee-js'

const bee = new Bee('http://localhost:1633')

async function main() {
const enabled = await bee.stake.setRedistributionEnabled(false)
console.log('Redistribution enabled:', enabled)
}

main().catch(console.error)

Example output:

Redistribution enabled: false
note

The setting is not persisted. Participation is enabled again when the node restarts.

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)
note

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.

💬 Get Help