To query the balance for a specific account as you said the method to be used is getStorage
and to query all like the UI is doing is with getKeys
.
I do recommend to read this blog from Shawn: Querying Substrate Storage via RPC and use this UI Substrate Utilities tool to create the hashes and decode the result.
The steps for your case would be:
util_crypto.xxhashAsHex("System", 128)
> "0x26aa394eea5630e07c48ae0c9558cef7"
util_crypto.xxhashAsHex("Account", 128)
> "0xb99d880ec681799c0cf30e8886371da9"
And you query with the combined storage key: 0x26aa394eea5630e07c48ae0c9558cef7b99d880ec681799c0cf30e8886371da9
curl -H "Content-Type: application/json" -d '{"id":1, "jsonrpc":"2.0", "method": "state_getKeys", "params": ["0x26aa394eea5630e07c48ae0c9558cef7b99d880ec681799c0cf30e8886371da9"]}' http://localhost:9933
On the other hand using PolkadotJS you can query the whole storage as you are doing with the option false in your image from the PolkadotJS app using entries()
. See an example below:
const wsProvider = new WsProvider('ws://127.0.0.1:9944');
const api = await ApiPromise.create({ provider: wsProvider });
const allEntries = await api.query.system.account.entries();
allEntries.forEach(([{ args: [accountId] }, balance]) => {
console.log(`${accountId}: Balance: ${JSON.stringify(balance.toHuman())}`);
});