Assets Module

A simple, secure module for dealing with fungible assets.

Overview

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.

Terminology

Goals

The assets system in Substrate is designed to make the following possible:

Interface

Dispatchable Functions

Please refer to the Call enum and its associated variants for documentation on each function.

Public Functions

Please refer to the Pallet struct for details on publicly available functions.

Usage

The following example shows how to use the Assets module in your runtime by exposing public functions to:

Prerequisites

Import the Assets module and types and derive your runtime's configuration traits from the Assets module trait.

Simple Code Snippet

```rust use palletassets as assets; use spruntime::ArithmeticError;

[frame_support::pallet]

pub mod pallet { use super::; use frame_support::pallet_prelude::; use framesystem::palletprelude::*;

#[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(())
    }
}

} ```

Assumptions

Below are assumptions that must be held when using this module. If any of them are violated, the behavior of this module is undefined.

Related Modules

License: Apache-2.0