'How can I mint multiple NFT copies based on NEP-171 standard?

i'm actualy minting tokens like this:

self.tokens.mint(token_id.clone(),account.clone(),Some(token_metadata.clone())

this are the params that i use to minting new tokens:

'{"token_id":next_tokenid_counter,"account": "'dokxo.testnet'", "token_metadata": { "title": "Some titile", "description": "Some description", "media": "","extra":"","copies":copies_number}}'

then only can minting one token with metadata info but only exist one token

and im looking if exist a method in Near/Rust like solidity's method to minting copies's n number: ex.

_mintBatch(address to, uint256[] ids, uint256[] amounts, bytes data)

any suggestions or examples for this?



Solution 1:[1]

The easiest implementation is probably to pre-mint all the tokens in the series.

I don't know RUST, so my example will be in AssemblyScript, and I will call the method nft_mint_series (you can call it whatever you want):

following the NEP-171 (and NEP-177 for metadata) standard. We can do something like the following example implementation. I will assume that you have a mint function, which it looks like you already have.

nft_mint_series will do one thing, which is to call the nft_mint function for all copies. You MUST change the id of each token, but everything else you do is up to the implementation and logic you want. I also change the title of each token in the method. Though this example is in AssemblyScript, I think it shouldn't be too difficult to find an equivalent in Rust, as it's a simple for loop.

@nearBindgen
export class Contract {
// Example implementation of how we can mint multiple copies of an NFT
// Return type is optional. I added it to make it easier to test the function
 nft_mint_series(
    to: string,
    id: string,
    copies: i32,
    metadata: TokenMetadata
  ): Token[] { 
    const seriesName = metadata.title; // Store the title in the metadata to change name for each token's metadata.
    const tokens: Token[] = [];
    for (let i = 0; i < copies; i++) {
      const token_id = id + ':' + (i + 1).toString(); // format -> id:edition

      // (optional) Change the title (and other properties) in the metadata
      const title = seriesName + ' #' + (i + 1).toString(); // format -> Title #Edition
      metadata.title = title;
      tokens.push(this.nft_mint(token_id, to, metadata));
    }
    return tokens;
  }
}

The example above is just one simple and straight forward way, and is not necessary how it should be created in a real application.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 John