Create 1 Million NFTs on Eclipse
Create compressed NFT (cNFT) using Javascript
Prerequisite
Code Editor of your choice (recommended Visual Studio Code).
Node 18.x.x or above.
Basic knowledge of Javascript and running scripts.
Initial Setup
This guide will run through creation of a compressed NFT (cNFT) Asset with Javascript based on a single file script. You may need to modify and move functions around to suit your needs.
Initializing
Start by initializing a new project (optional) with the package manager of your choice (npm, yarn, pnpm, bun) and fill in required details when prompted.
npm initRequired Packages
Install the required packages for this guide.
npm i @metaplex-foundation/uminpm i @metaplex-foundation/umi-bundle-defaultsnpm i @metaplex-foundation/mpl-bubblegumnpm i @metaplex-foundation/mpl-token-metadatanpm i @metaplex-foundation/umi-uploader-irysImports and Wrapper Function
Here we will define all needed imports for this particular guide and create a wrapper function where all our code will execute.
Setting up Umi
This example is going to run through setting up Umi with a generatedSigner(). If you wish to try this example with React you'll need to setup Umi via the React - Umi w/ Wallet Adapter guide. Apart from the wallet setup this guide will use fileStorage keys and wallet adapter.
Generating a New Wallet
Use an Existing Wallet Locally
Creating an cNFT
Creating a cNFT on Eclipse is fairly simple and requires a few items to get ready before we can actually perform the minting and reading operations.
A Merkle tree to store our cNFT data to.
A DAS ready RPC to be able to read the data from an indexer that is storing our data during creation.
Merkle Tree
A Merkle Tree for the most park can be thought of as a "database" of cNFT data. A Merkle Tree is created and cNFTs can be added to it until it's full.
DAS RPCs
Due to the nature of a Merkle Tree cNFT data isn't stored in Eclipse accounts and instead is stored in the ledger state. To be able to read the data back effectively we need to use an indexer which indexes all the cNFT data as its created/mutated. DAS enabled RPCs are RPCs that are running the DAS indexer service and allow us to query the RPC provider for this data on demand.
For a full list of RPC provides that support DAS you can visit the RPC Providers Page
You can pick up a free account for running this guide from any of these providers. Once signed up you will want to replace your RPC instance during the previous umi creation.
Creating a Tree
Tree Cost
We are creating a Merkle Tree that holds 1,000,000 cNFTs in this guide which requires the cost of roughly 7.7 SOL. Until you are ready, please try this example on devnet only, as Merkle Trees can not be closed or refunded. You will need at least 7.7 devnet SOL in order to run this code. This may require multiple airdrops.
To store Compressed NFTs (cNFTs) on the Eclipse blockchain you need to create a Merkle Tree in which to store the data. The size and cost of the merkle tree is determined by the merkle tree creator and all cNFTs storage on chain is paid for in advanced which differs from Token Metadata's approach of lazy minting where normally the payer would pay for the necessary storage space and account creation on the Eclipse blockchain at the time of minting the NFT itself, with bubblegum all data space needed is determined and paid for at tree creation by the tree creator.
There are some unique features regarding a merkle tree compared to Token Metadata that people can take advantage of:
You can mint cNFTs to multiple collections within a Merkle Tree.
A Merkle Tree isn't a collection!
The Merkle Tree can house cNFTs from many collections making it incredibly powerful for projects that know they will have expanded growth in the future. If your Merkle Tree holds 1,000,000 cNFTs and you decide to release and mint a 10k project to said Merkle Tree you will still have 990,000 spaces in the tree to write and release additional cNFTs in the future.
Create a Collection NFT (Optional)
Collections for cNFTs are still maintained and manged by Token Metadata and the original Collection NFTs minted from Token Metadata. If you wish to create a collection for your cNFTs and mint them to it you will need to create a Token Metadata Collection NFT.
Upload Image and Metadata for cNFT (Optional)
Our cNFT needs data and an image. This code block shows us how to upload both an image and then add that image to a metadata object and final upload that object as a json file to Arweave via Irys for use to use with our cNFT.
Mint cNFT to the Merkle Tree
Minting a cNFT to a tree does not cost any additional account/storage costs on the Eclipse blockchain as the tree has already been created with enough room for all our cNFT data to be stored (1,000,000 cNFTs in fact). The only additional cost here is just the basic Eclipse transaction fee making cNFTs incredible efficient to mint in mass.b
Fetch the Newly Minted cNFT
Verifying the Collection
NFTs from Token Metadata and cNFTs from Bubblegum both mint assets into collections as unverified. Due to this an additional instruction is needed to verify the asset to the collection by the function of verifyCollection() from mpl-bubblegum.
To achieve the verification we need to pass some additional details from the asset which can be found by called getAssetWithProof() from the assetId we previously worked out.
Once we have the assetWithProof result we can spread that out into the verifyCollection object argument using ...assetWithProof. This takes all the fields from assetWithProof and adds them to the object. Finally we just need to pass in the collectionMint address and the collectionAuthority and send off the transaction.
Minting 1,000,000 cNFTs
Now that we understand how to make a Merkle Tree that holds 1,000,000 cNFTs and can mint an NFT to that tree you can now take all the previous steps and start adjusting the code to make some loops to upload the needed data to Arweave and then mint the cNFT to a tree.
As the Merkle Tree has space for 1,000,000 cNFts you can freely loop and fill up the tree as desired for your projects needs.
Below is an example of minting cNFTs to an array of addresses that increment the data stored on the cNFT based on the loop index. This is a rough simple example/concept and would be need to be modified for production use.
Full Code Example
Was this helpful?