11

Is there a RPC in Tezos-client, that allows to query the Balance of a KT1 account cycle by cycle?

I've tried it with this (TzScan Public-Node RPC):

https://mainnet-node.tzscan.io/<block_id>/context/contracts/KT1XPU4EYP12ubNPjZwPDa8ydcPxUQ9JtpNC/balance

but I am not sure what <block_id> means and also not sure if this RPC leads me to my Result.

12

<block_id> - is a hash or a level of the block at which you ask for balance.

If you want to get a simple balance at the specific point in the cycle:

(this is pseudocode, I hope you figure it out)

var cycle = 60;

var p1 = (cycle * 4096 + 1) + 0; //beginning of the cycle
var p2 = (cycle * 4096 + 1) + 4095; //end of the cycle

var balance_at_p1 = get('/chains/main/blocks/{p1}/context/contracts/KT1.../balance');
var balance_at_p2 = get('/chains/main/blocks/{p2}/context/contracts/KT1.../balance');

But if you are trying to get a balance for calculating delegation rewards:

At first you should find the snapshot block that was used to count the rolls. Then use this block to get the balance like above.

var cycle = 60;
var cycle_lvl = cycle * 4096 + 1;

var snapshot = get('/chains/main/blocks/{cycle_lvl}/context/raw/json/cycle/{cycle}');

var snapshot_block = ((cycle - 7) * 4096 + 1) + (snapshot.roll_snapshot + 1) * 256 - 1;

var balance = get('/chains/main/blocks/{snapshot_block}/context/contracts/KT1.../balance');
8

You can use TzScan API for this: /v3/balance_history/KT1..., the documentation is here: balance history doc. For example https://api6.tzscan.io/v3/balance_history/KT1GgUJwMQoFayRYNwamRAYCvHBLzgorLoGo

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.