NXT balance using API

Hi,

I am trying to retrieve the NXT balance of my account at different periods of time (for example, what was the balance on 01/01/2016, on 26/03/2016, etc...).
I thought I could use the getBalance request to do it. But I have the following message errors when using different arguments :

  • height: 606876 => errorDescription": "Historical data as of height 606876 not available."
  • requireLastBlock: 9452046396716025388 => "errorDescription": "Current last block is different"

(I am using the API console from the NRS wallet 1.12.2).

Am I doing something wrong ? Is there another way to get the account's balance ?

Thanks.

Not directly. You can query the state for some blocks back because we store all changes up to 720 blocks by default which is the maximum rollback the blockchain can perform. After that the tables are trimmed of historical data, otherwise the amount of information would be huge.

There are several ways to get that information. If you just want to be able to access historical data form a single account maybe you can configure the ledger to keep all records for you account or accounts. Take a look at the nxt.ledgerAccounts and nxt.ledgerTrimKeep configuration properties.

This worked perfectly, thanks a lot.
However, I had to re-download the complete blockchain from the NRS wallet so that the ledger could display the transactions, which of course took a lot of time...

A faster way (found here) is to download a copy of the blockchain (for example from the Jelurida website) and once it is synced, run the scan option on the API console.
This also takes some time, but far less from the previous option.

You could have triggered the rescan without downloading the database from Jelurida's site. Even faster. :wink:

Glad that it helped.