| Crates.io | pallet-assets |
| lib.rs | pallet-assets |
| version | 45.0.0 |
| created_at | 2020-02-28 05:51:07.050894+00 |
| updated_at | 2025-08-19 12:09:02.172781+00 |
| description | FRAME asset management pallet |
| homepage | https://paritytech.github.io/polkadot-sdk/ |
| repository | https://github.com/paritytech/polkadot-sdk.git |
| max_upload_size | |
| id | 213441 |
| size | 477,390 |
A simple, secure module for dealing with fungible assets.
The Assets module provides functionality for asset management of fungible asset classes with a fixed supply, including:
To use it in your runtime, you need to implement the assets
assets::Config.
The supported dispatchable functions are documented in the
assets::Call enum.
The assets system in Substrate is designed to make the following possible:
issue - Issues the total supply of a new fungible asset to the account of the caller of the function.transfer - Transfers an amount of units of fungible asset id from the balance of the function caller's account
(origin) to a target account.destroy - Destroys the entire holding of a fungible asset id associated with the account that called the function.Please refer to the Call enum and its associated
variants for documentation on each function.
balance - Get the asset id balance of who.total_supply - Get the total supply of an asset id.Please refer to the Pallet struct for
details on publicly available functions.
The following example shows how to use the Assets module in your runtime by exposing public functions to:
Import the Assets module and types and derive your runtime's configuration traits from the Assets module trait.
use pallet_assets as assets;
use sp_runtime::ArithmeticError;
#[frame_support::pallet]
pub mod pallet {
use super::*;
use frame_support::pallet_prelude::*;
use frame_system::pallet_prelude::*;
#[pallet::pallet]
pub struct Pallet<T>(_);
#[pallet::config]
pub trait Config: frame_system::Config + assets::Config {}
#[pallet::call]
impl<T: Config> Pallet<T> {
pub fn issue_token_airdrop(origin: OriginFor<T>) -> DispatchResult {
let sender = ensure_signed(origin)?;
const ACCOUNT_ALICE: u64 = 1;
const ACCOUNT_BOB: u64 = 2;
const COUNT_AIRDROP_RECIPIENTS: u64 = 2;
const TOKENS_FIXED_SUPPLY: u64 = 100;
ensure!(!COUNT_AIRDROP_RECIPIENTS.is_zero(), ArithmeticError::DivisionByZero);
let asset_id = Self::next_asset_id();
<NextAssetId<T>>::mutate(|asset_id| *asset_id += 1);
<Balances<T>>::insert((asset_id, &ACCOUNT_ALICE), TOKENS_FIXED_SUPPLY / COUNT_AIRDROP_RECIPIENTS);
<Balances<T>>::insert((asset_id, &ACCOUNT_BOB), TOKENS_FIXED_SUPPLY / COUNT_AIRDROP_RECIPIENTS);
<TotalSupply<T>>::insert(asset_id, TOKENS_FIXED_SUPPLY);
Self::deposit_event(Event::Issued(asset_id, sender, TOKENS_FIXED_SUPPLY));
Ok(())
}
}
}
Below are assumptions that must be held when using this module. If any of them are violated, the behavior of this module is undefined.
Config::AssetId::max_value().License: Apache-2.0