Mint an NFT
Pre-requirements
Before you can mint an NFT, you will need to:
Mint an NFT
This example will connect to
a node you defined as the API_ENDPOINT
constant. Afterwards, the example will request a Bech32 address, if you don't
have one the example will take care of generating it.
Create a Hot Wallet
The example will later create a hot wallet and request funds from the
faucet defined as the FAUCET
constant.
Create the Output
Once the generated wallet has outputs to mint the NFT, it will define an
INftOutput object. The amount
property is set to 0
, as you need to
calculate the required storage deposit using the
TransactionHelper.getStorageDeposit(output, rentStructure)
function, which takes any of the allowed OutputTypes.
Create the Transaction Essence
Once you have created the output, you should create the
ITransactionEssence, which will include the output
. The example will then use the
ITransactionEssence
to generate the essenceHash
using the
TransactionHelper.getTransactionEssenceHash(essence)
function.
Create the Transaction Payload
With the created the transaction essence, you are now able to create the ISignatureUnlock which will be used to create the ITransactionPayload.
Submit the Block
Once you have created the transaction payload, you can create the IBlock and submit it using the SingleNodeClient.blockSubmit(blockPartial) function.
Example Code
loading...
Expected Output
Target address (Bech32 encoded) where to mint the NFT or leave empty and we will generate an address for you:
Target Address:
Seed cacc64919fd9b8b7990c8e8c579ed3e0269a101b3fa9186ae6b65edf865791ee
Address Ed25519 0xd6135c19e0f364ce3a6fe8e943a1c7ee921acb1d6a1226000e4a0345b61f5407
Address Bech32 rms1qrtpxhqeurekfn36dl5wjsapclhfyxktr44pyfsqpe9qx3dkra2qwq3y5z4
Sender Address:
Seed d4c0da7c0990e28036cba5807894aee23daa2ffabbfadcbfbc9ac639b2bf49c0
Address Ed25519 0xea5b53136d6d423ed4679bfb7eb7e517d853992162b139d7eb5f69a61c6344af
Address Bech32 rms1qr49k5cnd4k5y0k5v7dlkl4hu5tas5uey93tzwwhad0knfsuvdz27rvts06
Try # 1 : fetching basic output for address rms1qr49k5cnd4k5y0k5v7dlkl4hu5tas5uey93tzwwhad0knfsuvdz27rvts06
Didn't find any, retrying soon...
Try # 2 : fetching basic output for address rms1qr49k5cnd4k5y0k5v7dlkl4hu5tas5uey93tzwwhad0knfsuvdz27rvts06
OutputId: 0x5334dd8c3c3096285424bbd7ff7e5d4897bbf0cb110ecbba0f1315400384f7860000
To be consumed output: {
type: 3,
amount: '1000000000',
unlockConditions: [ { type: 0, address: [Object] } ]
}
Input: {
type: 0,
transactionId: '0x5334dd8c3c3096285424bbd7ff7e5d4897bbf0cb110ecbba0f1315400384f786',
transactionOutputIndex: 0
}
Required Storage Deposit of the NFT output: 270500
Submitted blockId is: 0x510e56623975f19290445856f0c852b6504524741de58a50e77dd9cb2e9e09c5
Check out the transaction at https://explorer.alphanet.iotaledger.net/alphanet/block/0x510e56623975f19290445856f0c852b6504524741de58a50e77dd9cb2e9e09c5
Done
Related How Tos
You can explore the libraries NFT minting functionalities with the NFT collection code example.