Balances Module

The Balances module provides functionality for handling accounts and balances. - balances::Trait - Call - Module

Overview

The Balances module provides functions for: - Getting and setting free balances. - Retrieving total, reserved and unreserved balances. - Repatriating a reserved balance to a beneficiary account that exists. - Transferring a balance between accounts (when not reserved). - Slashing an account balance. - Account creation and removal. - Managing total issuance. - Setting and managing locks.

Terminology

The Balances module provides implementations for the following traits. If these traits provide the functionality that you need, then you can avoid coupling with the Balances module. - Currency: Functions for dealing with a fungible assets system. - ReservableCurrency: Functions for dealing with assets that can be reserved from an account. - LockableCurrency: Functions for dealing with accounts that allow liquidity restrictions. - Imbalance: Functions for handling imbalances between total issuance in the system and account balances. Must be used when a function creates new funds (e.g. a reward) or destroys some funds (e.g. a system fee). - IsDeadAccount: Determiner to say whether a given account is unused.

Interface

Dispatchable Functions

The following examples show how to use the Balances module in your custom module.

Examples from the FRAME

The Contract module uses the Currency trait to handle gas payment, and its types inherit from Currency: rust use frame_support::traits::Currency; pub type BalanceOf<T> = <<T as Config>::Currency as Currency<<T as frame_system::Config>::AccountId>>::Balance; pub type NegativeImbalanceOf<T> = <<T as Config>::Currency as Currency<<T as frame_system::Config>::AccountId>>::NegativeImbalance; The Staking module uses the LockableCurrency trait to lock a stash account's funds: rust use frame_support::traits::{WithdrawReasons, LockableCurrency}; use sp_runtime::traits::Bounded; pub trait Config: frame_system::Config { type Currency: LockableCurrency<Self::AccountId, Moment=Self::BlockNumber>; } fn update_ledger<T: Config>( controller: &T::AccountId, ledger: &StakingLedger<T> ) { T::Currency::set_lock( STAKING_ID, &ledger.stash, ledger.total, WithdrawReasons::all() ); // <Ledger<T>>::insert(controller, ledger); // Commented out as we don't have access to Staking's storage here. }

Genesis config

The Balances module depends on the GenesisConfig.

Assumptions