0

I'm trying to parse the whole storage from a node with the encoded partial key through RPC, it seems to be doable with polkadotJS see the picture in one call.

system.account(AccountId32)

The fastest approach that we currently have, which is not an unsafe RPC call, is state.getKeys or state.getKeysPaged and then queryStorageAt.

Is there a shorter way, like the representation in polkadotJS apps under chain state system.account() include option false, to query the whole storage? Or how is this representation done?

1 Answer 1

1

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())}`);
});
2
  • Thank you for the answer. Okay, and how is this resolved to the node regarding the RPC call(s) from PolkadotJS? Is it just wrapped in multiple RPC calls? Since I'm trying to find out how I can replicate this function via RPC over our C# Substrate API? Jan 24 at 21:34
  • I have edit my answer to have how to recover with RPC calls, but the best way is how you mention with the state.getKeys
    – Alex Bean
    Jan 25 at 12:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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