Mint Multiple NFTs Using the ERC1155 Standard | by Sandnc.eth | Jun, 2022

A hands-on instance

Picture from Unsplash

In my previous article, I talked about some tips and ideas so as to add perform modifiers for timed transitions, reentrancy guards, and withdrawing funds.

Nonetheless, this was accomplished through drag and drop code snippets.

On this article, I’ll present you the way to create an ERC1155 NFT contract that makes use of all these items.

An ERC1155 commonplace lets you mint a number of copies of a singular NFT token id. Which makes it fairly helpful for decentralized gaming purposes the place gamers would go about minting swords, magic potions, livery, and so on.

The code I’ll current right here will be copy-pasted in ETH-Remix to play with the assorted features.

I intentionally disregarded the batch mint perform as an train for the reader.

Open zeppelin has actually good documentation breaking down their ERC1155 commonplace which is in direct distinction to the ERC721 commonplace the place an NFT token can solely have 1 copy.

In brief, an ERC1155 NFT is identical as an ERC721 NFT when the allowed mint amount is the same as ‘1’.

ETH-Remix display screen seize

Listed here are all of the perform modifiers we’ll use. Coated in my previous article.

When utilizing ETH-Remix, be sure to enter your costs utilizing double quotes so the enter is taken in as a string.

Instance: For ‘1 ether’ , use “1000000000000000000”.

You then’ll want some method to preserve monitor of your NFT reserves and cease minting upon exhausting the reserves. The ERC1155 will handle the NFT balances of the customers.

You possibly can monitor the NFT reserves by pushing them into an array of sort struct NFTInfo. You possibly can then create a getter perform for a similar that returns a sort (NFTInfo).

Under is the constructor for this contract. I’ve supplied instance inputs to embed within the code, making it simpler to deploy and take a look at the contract with out having to enter the constructor arguments every time.

In case you select to take action, merely remark out the constructor arguments for ids_, prices_, maxAmounts_, beneficiary and devAddress_.

The following essential perform is the guts of the contract. Because it permits a consumer account to mint NFTs. The consumer account is allowed to mint NFTs so long as they’ve sufficient funds, not an invalid tackle, and the NFT reserves for the tokenID haven’t been exhausted.

The total contract code will be discovered on my Github so that you can play with in an IDE of your alternative.

That’s it for now and hope this helped you in your understanding of the way to mint NFTs utilizing the ERC1155 commonplace.

As an train for the reader, I’ve disregarded the batch mint perform. The batchMint() ought to permit a consumer account to mint copies of a number of tokenIDs and needs to be attainable to implement with minor modifications to the mintSingle() perform.

More Posts