Mint Plutus NFT
Mint NFT that ensure the token name is incremented by a counter
This NFT minting script enables users to mint NFTs with an automatically incremented index, which increases by one for each newly minted NFT.
To facilitate this process, the first step is to set up a one-time minting policy by minting an oracle token. This oracle token is essential as it holds the current state and index of the NFTs, acting as a reference for the minting sequence.
With each new NFT minted, the token index within the oracle is incremented by one, ensuring a consistent and orderly progression in the numbering of the NFTs.
There are 3 actions available to interact with this smart contract:
- Setup Oracle: Mint one-time minting policy to set up the oracle
- Mint Token: Mint NFT that ensures the token name is incremented by a counter
- Get Oracle Data: Fetch the current oracle data to get the current NFT index and other information
Install package
First you can to install the @meshsdk/contracts
package:
Both on-chain and off-chain codes are open-source and available on Mesh Github Repository.
Setup Oracle
First, we need to set up a one-time minting policy by minting an oracle token. This oracle token is essential as it holds the current state and index of the NFTs, acting as a reference for the minting sequence.
We need to provide 2 parameters to setup the oracle, the price of the NFT in lovelace and the collection name. The collection name is used when initializing MeshPlutusNFTContract
which is used to derive the script CBOR. The price of the NFT in lovelace is used in setupOracle()
function which will be added into the oracle token.
The setupOracle()
function will return a transaction CBOR and aparamUtxo
. The paramUtxo
will be used in the minting transaction of the NFT, so it is important to store it. Here is an example of the paramUtxo
:
The transaction CBOR can be signed and submitted using the following code:
Mint one time minting policy to set up the oracle
Connect wallet to run this demo
Mint Token
This NFT minting script enables users to mint NFTs with an automatically incremented index, which increases by one for each newly minted NFT.
To facilitate this process, you must provide the paramUtxo
that contains the output index and transaction hash of the NFT minting policy.
The mintPlutusNFT()
function mints an NFT with asset metadata, which is a JSON object containing the NFT metadata. You can use the getOracleData()
function to fetch the oracle data, which includes the current NFT index. This index will be helpful if you need to define the NFT name and its metadata. Here is an example of the how we can define the asset metadata:
The mintPlutusNFT()
function will return a transaction object that can be signed and submitted using the following code:
Mint an NFT with asset metadata
Connect wallet to run this demo
Get Oracle Data
Getting the oracle data is essential to fetch the current NFT index.
To facilitate this process, you must provide the paramUtxo
that contains the output index and transaction hash of the NFT minting policy.
The getOracleData()
function will return the current oracle data.
Fetch the current oracle data to get the current NFT index and other information
Connect wallet to run this demo