2

If run this RPC query via curl:

curl -H "Content-Type: application/json" -d '{"id":1, "jsonrpc":"2.0", "method": "state_getStorage", "params": ["0xc2261276cc9d1f8598ea4b6a74b15c2fb99d880ec681799c0cf30e8886371da9de1e86a9a8c739864cf3cc5ec2bea59fd43593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27d"]}' http://127.0.0.1:9933

The output is null when it should display the balance of the ALICE account. WHY?

{"jsonrpc":"2.0","result":null,"id":1}

Polkadot UI

3
  • I'm trying to use the examples in: shawntabrizi.com/substrate/querying-substrate-storage-via-rpc. I can't get the storage map query to work either. Why? Sep 28, 2022 at 14:28
  • The article mentions storage value Balances::FreeBalance, it was probably how balances were formerly handled. The answer below from Lana explains the new way of getting the free balance. Sep 29, 2022 at 11:05
  • ^^^ Does this mean that it is impossible to get the balance with a simple request? I can't add comments
    – f33r0
    Jul 24, 2023 at 12:08

1 Answer 1

5

The substrate-node-template allows you to query the system.account storage item, see screenshot enter image description here

The corresponding command is

curl -H "Content-Type: application/json" -d '{"id":1, "jsonrpc":"2.0", "method": "state_getStorage", "params": ["0x26aa394eea5630e07c48ae0c9558cef7b99d880ec681799c0cf30e8886371da9de1e86a9a8c739864cf3cc5ec2bea59fd43593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27d"]}' http://127.0.0.1:9933

{"jsonrpc":"2.0","result":"0x01000000000000000100000000000000dcb114568172fc0f0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000","id":1}

The frame_system declares an AccountInfo struct that details the data field of an account:

/// Information of an account.
#[derive(Clone, Eq, PartialEq, Default, RuntimeDebug, Encode, Decode)]
pub struct AccountInfo<Index, AccountData> {
    /// The number of transactions this account has sent.
    pub nonce: Index,
    /// The number of other modules that currently depend on this account's existence. The account
    /// cannot be reaped until this is zero.
    pub consumers: RefCount,
    /// The number of other modules that allow this account to exist. The account may not be reaped
    /// until this is zero.
    pub providers: RefCount,
    /// The additional data that belongs to this account. Used to store the balance(s) in a lot of
    /// chains.
    pub data: AccountData,
}

The runtime/src/lib.rs is where all of your configs are created. If you look carefully at

impl frame_system::Config for Runtime {
    ...
    type AccountData = pallet_balances::AccountData<Balance>;
    ...
}

and

impl pallet_balances::Config for Runtime {
    ...
    type AccountStore = System;
    ...

}

you will see why the system storage exposes the balances in the data, not the balances storage. Use type AccountStore = Balances; instead to leverage the usage of pallet-balances.

1
  • 1
    ...THAT'S WHY! :)
    – Lana I
    Sep 28, 2022 at 15:34

Your Answer

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

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