How do we use the balances pallet instead of the system pallet to store the balances

Viewed 666

If we take a look at the polkadot js documentation we can see the following note: This is only used in the case that this pallet is used to store balances. Now how do we use the balances pallet to store the balances? because we also have the api.query.system.account function instead of api.query.balances.account

1 Answers

You can configure this in your Frame System and Pallet Balances Config trait.

By in our examples we use the following which places the balances in the System Pallet:

impl frame_system::Config for Runtime {
    /// The basic call filter to use in dispatchable.
    type BaseCallFilter = ();
    /// Block & extrinsics weights: base values and limits.
    type BlockWeights = BlockWeights;
    
    /* -- snip -- */

    /// The data to be stored in an account.
--> type AccountData = pallet_balances::AccountData<Balance>;
    /// Weight information for the extrinsics of this pallet.
    type SystemWeightInfo = ();
    /// This is used as an identifier of the chain. 42 is the generic substrate prefix.
    type SS58Prefix = SS58Prefix;
}

impl pallet_balances::Config for Runtime {
    type MaxLocks = MaxLocks;
    /// The type for recording an account's balance.
    type Balance = Balance;
    /// The ubiquitous event type.
    type Event = Event;
    type DustRemoval = ();
    type ExistentialDeposit = ExistentialDeposit;
--> type AccountStore = System;
    type WeightInfo = pallet_balances::weights::SubstrateWeight<Runtime>;
}

I have put an arrow over the relevant fields.

If you want to store the balances in the balances pallet itself, you can simply change those two lines to the following:

/// Store no extra data in the Frame System pallet.
type AccountData = ();

and

use frame_support::traits::StorageMapShim;

...

/// Store the balance information in the Balances pallet.
type AccountStore = StorageMapShim<
    pallet_balances::Account<Runtime>,
    frame_system::Provider<Runtime>,
    AccountId,
    pallet_balances::AccountData<Balance>,
>;
Related