Crate pallet_balances[][src]

Balances Pallet

The Balances pallet provides functionality for handling accounts and balances.

Overview

The Balances pallet provides functions for:

Terminology

Implementations

The Balances pallet provides implementations for the following traits. If these traits provide the functionality that you need, then you can avoid coupling with the Balances pallet.

Interface

Dispatchable Functions

Usage

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

Examples from the FRAME

The Contract pallet uses the Currency trait to handle gas payment, and its types inherit from Currency:

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 pallet uses the LockableCurrency trait to lock a stash account’s funds:

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 pallet depends on the GenesisConfig.

Assumptions

Re-exports

pub use weights::WeightInfo;
pub use pallet::*;

Modules

pallet
weights

Autogenerated weights for pallet_balances

Structs

AccountData

All balance information for an account.

BalanceLock

A single lock on a balance. There can be many of these on an account and they “overlap”, so the same balance is frozen by multiple locks.

NegativeImbalance

Opaque, move-only struct with private fields that serves as a token denoting that funds have been destroyed without any equal and opposite accounting.

PositiveImbalance

Opaque, move-only struct with private fields that serves as a token denoting that funds have been created without any equal and opposite accounting.

Enums

Reasons

Simplified reasons for withdrawing balance.