Closed fkbenjamin closed 3 years ago
Ok... now that I think through it.
So the issue is that at block 1, there was no api.query.system.account.at
entry. So it will indeed return the current defaults. For really old just-post-genesis blocks the balances used to be stored in balances.freeBalance
, then it moved to balances.account
for a short while (< 7 days) and then into the current position at system.account
.
I'm running into the same issue on Polkadot.
Example inputs:
3134647
0xb842f533b3110bab3854343e088378af23110b560edf26111ba728b4560d6c76
12vCVEpCz81rvS23PEJQ6KBDbPWgvyVX5Q1PrgQbVvLc4i2Z
Should it be possible to query balances from all three locations with the current version of polkadot-js/api
? Or do I need to find a matching version?
In 4.16.2, both api.query.balances.freeBalance
and api.query.balances.reservedBalance
are undefined
.
Yes, so they will be undefined - since those storage locations don't exist anymore in the metadata. And the API endpoints are decorated based on the current metadata. The is the only way to solve that via #3585 - which is some way away, i.e. decorate API with historic stuff.
To query those current non-existing ones - you will need to manually construct a key, then query and then decode the values based on the types. (Until the above enhancement gos in at some point, i.e. get metadata first, decorate at that point, then only allow queries)
Hey @jacogr, thanks for clarifying. Does that mean it's currently not possible to get these historic balances from the chain?
It is in the trie, so you can.
Query the storage with the correctly constructed key and decode. (As mentioned above) Since it is not decorated and not in the current metadata the API cannot provide help here. So you basically need to do it via getStorage RPC.
So the data is there, but the API provides no helpers to get to it.
@fkbenjamin Here's a great explanation on how to use the getStorage RPC and it even happens to use Balances.FreeBalance
as an example: https://www.shawntabrizi.com/substrate/querying-substrate-storage-via-rpc/
Thanks @haikoschol , I'll check that link out! :)
As of 4.17.1
the form such as api.at(<blockHash>).query.balances.freeBalance(<address>)
will return the values
Thanks @jacogr!
One correction regarding my comment above: The changes to how balances are stored were made before Polkadot went live. That means, this issue only exists on Kusama and I was mistaken about the error I saw. The real issue was that some of the accounts I was querying simply didn't exist that far back. However, I'll have to do the same for Kusama and this will come in very handy!
This issue has been open for 21 days with no activity and is not labelled as an enhancement. It will be closed in 7 days.
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue if you think you have a related problem or query.
Following the example at https://polkadot.js.org/docs/api/examples/promise/read-storage-at/, trying to query for the balance at an old block hash (e.g. Block 1: 0xcd9b8e2fc2f57c4570a86319b005832080e0c478ab41ae5d44e23705872f5ad3 or Block 1000000: 0xb267ffd706bbb93779eab04f47c7038031657b0a863794dbdd73170e3976c3e7)) results in the following error:
I am using wss://kusama-rpc.polkadot.io/ for these queries, which is a confirmed archive node (https://guide.kusama.network/docs/kusama-endpoints/)
Polkadot API is at version 4.16.2