Skip to content

About

When does unstaked tez become spendable? Read-only Tezos CLI: unstake requests, finalizable cycle and time, staking history, network staked/delegated per cycle

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

stakeclock

ci Tezos · read-only · MIT · Tutorial

When does unstaked tez become spendable? stakeclock answers that for any Tezos address from the node's own view: every pending unstake request, the cycle it becomes finalizable, and the likely wall-clock time, plus anything that is already finalizable and only waiting for a finalize_unstake. It also lists the account's staking history the way TzKT records it (including the unstakes a change of delegate triggers), and the network-wide staked and delegated tez per cycle.

No keys, no wallet, no transactions: it only reads public RPC nodes and the TzKT API.

Staked and delegated tez per cycle, cycle 702 to 1410, made with stakeclock network --svg

Try it in a minute (Node 24 or newer, which runs TypeScript directly):

git clone https://github.com/apeirs/stakeclock && cd stakeclock && npm ci
node bin/stakeclock.ts tz3W7k9v3uniY1f2HQRKxymJybNvH3FgvZ5N

Why

"How long does it take to unstake?" is asked again after every protocol upgrade, and the answers are prose: Tezos Stack Exchange 6458 (May 2026) got "about 3–4 days". The real answer depends on protocol constants that keep changing (6 s blocks, one-day cycles and unstake_finalization_delay = 3 since the latest upgrades), on the cycle the request was made in, and on how fast blocks actually come. Nothing told you the date for your request.

Three more gaps it closes:

  • Finalizable is not spendable. Unstaked tez stays out of the spendable balance until a finalize_unstake is included. On 2026-11-12 one mainnet account had 53,623 tez finalizable since the start of cycle 1411 and 3.3 tez spendable. stakeclock flags it and prints the command.
  • Implicit unstakes are easy to miss. A change of delegate unstakes everything. TzKT's /v1/operations/staking doesn't list that unstake, because no staking operation was sent (tzkt#185). stakeclock history reads /v1/staking/updates and labels each update with its cause and operation hash.
  • "Is there a historical chart of total staked and delegated?" (Stack Exchange 6437, unanswered since March 2025). stakeclock network gives it per cycle as a table, CSV or SVG (the chart above).

Example output

Real output from mainnet on 2026-11-12, for a baker with one unstake request in each of the last four cycles:

$ node bin/stakeclock.ts tz3W7k9v3uniY1f2HQRKxymJybNvH3FgvZ5N
tz3W7k9v3uniY1f2HQRKxymJybNvH3FgvZ5N  mainnet, block 15780300, cycle 1411, 2026-11-12 07:51 UTC

delegate               tz3W7k9v3uniY1f2HQRKxymJybNvH3FgvZ5N
spendable                      5.004811 tez
staked                 8,121,121.540112 tez
unstaked, frozen           29,339.40498 tez
unstaked, finalizable                 0 tez

request cycle            amount  finalizable from  likely time                         state
         1408     1,127.716 tez  cycle 1412        ~2026-11-12 20:02 UTC (in 12h 10m)  frozen
         1409  16,929.89898 tez  cycle 1413        ~2026-11-13 20:25 UTC (in 1d 12h)   frozen
         1410       5,640.4 tez  cycle 1414        ~2026-11-14 20:48 UTC (in 2d 12h)   frozen
         1411      5,641.39 tez  cycle 1415        ~2026-11-15 21:11 UTC (in 3d 13h)   frozen

Rule: a request made in cycle N is finalizable from the first block of cycle N + 3 + 1
(unstake_finalization_delay = 3, protocol PsUshuai).
Times use this cycle's pace so far (6.096 s/block, 14400 blocks per cycle).
At the 6 s minimum per block, the next one could come 11m sooner.

An account whose unstaked tez is ready but not finalized:

$ node bin/stakeclock.ts tz1MNbBSJatXkjLHU3L1LR2Tpxsn4PwimoaM
tz1MNbBSJatXkjLHU3L1LR2Tpxsn4PwimoaM  mainnet, block 15780301, cycle 1411, 2026-11-12 07:52 UTC

delegate               tz1ZGYjyXgPdJ6a8EXNHmP4jZbJtEQoeRYFQ
spendable                    3.29502 tez
staked                             0 tez
unstaked, frozen                   0 tez
unstaked, finalizable  53,623.355942 tez

request cycle             amount  finalizable from  likely time  state
         1407  53,623.355942 tez  cycle 1411                     READY, needs finalize

53,623.355942 tez can be finalized now. It stays unspendable until a finalize_unstake
for this account is included. Anyone may send it (the tez always go to the staker), and the
next stake or unstake by this account finalizes it too. From a shell:
  octez-client finalize unstake for tz1MNbBSJatXkjLHU3L1LR2Tpxsn4PwimoaM

History, with the unstake a change of delegate caused (the operations list doesn't show it):

$ node bin/stakeclock.ts history tz1cg93LEsvZ7Uy64SkXpwAL7NUMZCwgZPxp --limit 3
tz1cg93LEsvZ7Uy64SkXpwAL7NUMZCwgZPxp: last 3 staking updates, newest first

time (UTC)        type                amount  cycle  baker  caused by         operation
2026-11-10 18:22  unstake  21,144.535475 tez   1409  HiTEZ  delegate changed  oo4vwncPRexGjKjY6W3xzx7zP5aPbeKbPMQZJawZ3fbg4CgTCq2
2026-06-25 09:31  stake              919 tez   1273  HiTEZ  staking op        ooXTBMbeqwWTdgXwrg9SBRXPMPCovfsbHJCBeEboGYstbsZEZAY
2026-05-26 16:41  stake              522 tez   1244  HiTEZ  staking op        op2fB5xzKtQu31SFUNneNKpZJrQEWGRkHCsG9phHrosF3Cydz4M

Network totals per cycle:

$ node bin/stakeclock.ts network --cycles 5
Network staked (#) and delegated (.) tez at the end of each cycle

cycle  end (UTC)        staked    delegated  staked %  stakers
 1406  2026-11-07  350,870,266  316,859,280      52.5     3307  #####################...................
 1407  2026-11-08  351,053,608  316,511,719      52.6     3305  #####################...................
 1408  2026-11-09  351,176,928  312,647,864      52.9     3283  #####################...................
 1409  2026-11-10  351,299,010  312,628,466      52.9     3283  #####################...................
 1410  2026-11-11  351,147,643  312,992,227      52.9     3290  #####################...................

Usage

stakeclock <address>                    staking statement: balances, unstake requests,
                                        the cycle and time each one becomes finalizable
stakeclock history <address> [--limit 20]
                                        staking updates TzKT recorded, with their cause
stakeclock network [--cycles 90] [--csv] [--svg FILE]
                                        network staked/delegated tez per cycle

--network mainnet|shadownet   (default mainnet)
--rpc URL                     RPC node (repeatable; tried in order)
--tzkt URL                    TzKT API base
--json                        machine-readable output (amounts in mutez, as strings)
--timeout MS                  per request (default 15000)

--json is the interface for scripts and bots, for example a finalization bot that only acts when finalizable is above zero. Addresses are checked (base58 checksum) before any request, so a typo fails at once. Exit codes: 0 done, 1 error (with the reason), 2 usage.

How it works

  1. One block for every read. It reads the head header first, then makes every other request against that block hash (/chains/main/blocks/<hash>/…), so a cycle boundary can't fall between two reads. Reads go one at a time, because public nodes answer bursts with HTTP 429.
  2. The protocol's own split. GET …/context/contracts/<address>/unstake_requests returns finalizable and unfinalizable requests, each with its cycle and amount.
  3. The rule, from constants. A request made in cycle N is finalizable from the first block of cycle N + unstake_finalization_delay + 1. The delay is read from …/context/constants, never hard-coded. stakeclock checks the rule against the node's split for every request it shows: if they disagree, the protocol has changed and it says so instead of printing a wrong date. The weekly CI job runs this check on recent unstakers on mainnet and Shadownet.
  4. Cycles to clock time. The earliest time assumes every remaining block at minimal_block_delay (6 s). Blocks at a later round take longer, so cycles run late: over the 30 cycles 1381 to 1410 they averaged 6.06 s per block (24h 06m to 24h 28m per cycle), about 14 minutes a day. The likely time uses the current cycle's pace so far, from the timestamp of the cycle's first block.
  5. History and network totals from TzKT. /v1/staking/updates (every change to staked and unstaked balances, whatever caused it) and /v1/statistics/cyclic (totals at the end of each cycle).

TUTORIAL.md walks through each step with curl, jq and a few lines of JavaScript.

Tests

npm test            # 40 tests offline, on recorded mainnet answers (test/fixtures)
npm run typecheck
npm run test:live   # 3 tests against mainnet and Shadownet
npm run fixtures    # re-record the fixtures from mainnet

The offline tests cover the rule against what mainnet listed at cycle 1411 (1407 finalizable, 1408 frozen), the earliest-time estimate against TzKT's projected cycle start (equal to the second), the pace estimate, block pinning, sequential reads, node fallback on timeouts and 5xx (but not on 404), the 429 retry, address checksums, exact mutez formatting past 2^53, and the CLI.

What it does not do

  • It doesn't sign or send anything. To finalize, use a wallet or `octez-client finalize unstake for `.
  • Times are estimates. A cycle starts when its first block is baked, and nobody can know that to the minute days ahead. The cycle number is exact.
  • Ghostnet was retired in 2026; the testnet preset is Shadownet. Other networks work with --rpc and --tzkt.
  • It needs a protocol that publishes unstake_finalization_delay in its constants (mainnet does). On one that doesn't, it stops with that message instead of guessing.

License

MIT, see LICENSE.

About

When does unstaked tez become spendable? Read-only Tezos CLI: unstake requests, finalizable cycle and time, staking history, network staked/delegated per cycle

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages