Skip to content

Instantly share code, notes, and snippets.

@gaia
Last active March 21, 2019 17:44
Show Gist options
  • Save gaia/4da4718f0ab060d0ad69f62ea2c4f840 to your computer and use it in GitHub Desktop.
Save gaia/4da4718f0ab060d0ad69f62ea2c4f840 to your computer and use it in GitHub Desktop.
Tezos; query balance at end of cycle
#!/bin/bash
# USAGE: script.sh cyclenumber
# EXAMPLE: balance-at-cycle.sh 80
# REQUIRES: bc
# Note that rewards and bond are released on the last block of a cycle.
# For this reason, the amount you get here is the amount at the end of the cycle entered.
# So if you want to find out the balance at the beggining of cycle 80, you'd enter 79 in this script
# See this answer for more info:
# https://tezos.stackexchange.com/questions/840/how-to-find-a-bakers-balance-available-for-bond-at-the-beginning-of-old-cycles/842#842
# Enter your path to tezos-client here, without a trailing slash
tc="/home/tezos/tezos/tezos-client".
#Enter the address for which you want to see the balance here
address="youraddresshere"
# This gives you cleaner output. Comment it out then log off/log in to see the warning.
export TEZOS_CLIENT_UNSAFE_DISABLE_DISCLAIMER=Y
cycle=$1
let level=cycle*4096
balance=$($tc rpc get "/chains/main/blocks/$level/context/contracts/$address/balance" | bc)
xtzbalance=$(($balance/1000000))
echo "$xtzbalance XTZ at block $level in cycle $cycle"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment