Previous Versionsv0.2.0Tokens

Non-Fungible Consecutive

Outdated Version

You're viewing an older version (v0.2.0) The latest documentation is available for the current version. Click here to visit latest version.

Source Code

Consecutive extension for Non-Fungible Token is useful for efficiently minting multiple tokens in a single transaction. This can significantly reduce costs and improve performance when creating a large number of tokens at once.

Usage

We’ll continue with the example from Non-Fungible Token and modify the contract so that now batches of tokens can be minted with each call to award_items. Please note any account can call award_items and we might want to implement access control to restrict who can mint.

use soroban_sdk::{contract, contractimpl, Address, Env, String};
use stellar_default_impl_macro::default_impl;
use stellar_non_fungible::{
    consecutive::{Consecutive, NonFungibleConsecutive},
    Base, ContractOverrides, NonFungibleToken,
};

#[contract]
pub struct GameItem;

#[contractimpl]
impl GameItem {
    pub fn __constructor(e: &Env) {
        Base::set_metadata(
            e,
            String::from_str(e, "www.mygame.com"),
            String::from_str(e, "My Game Items Collection"),
            String::from_str(e, "MGMC"),
        );
    }

    pub fn award_items(e: &Env, to: Address, amount: u32) -> u32 {
        // access control might be needed
        Consecutive::batch_mint(e, &to, amount)
    }

    pub fn burn(e: &Env, from: Address, token_id: u32) {
        Consecutive::burn(e, &from, token_id);
    }
}

#[default_impl]
#[contractimpl]
impl NonFungibleToken for GameItem {
    type ContractType = Consecutive;
}

// no entry-point functions required, marker impl
impl NonFungibleConsecutive for GameItem {}

On this page