Non-Fungible Consecutive
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},
Balance, Base, ContractOverrides, NonFungibleToken, TokenId,
};
#[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: TokenId) -> TokenId {
// access control might be needed
Consecutive::batch_mint(e, &to, amount)
}
pub fn burn(e: &Env, from: Address, token_id: TokenId) {
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 {}