Mint a Capsule NFT
Prerequisites
Minting a Capsule NFT on-chain using Ternoa-JS
import fs from "fs";
import {
encryptFile,
getKeyringFromSeed,
mintCapsuleNFT,
File,
TernoaIPFS,
WaitUntil,
} from "ternoa-js";
const main = async () => {
try {
const SEED = "//TernoaTestAccount"; // The owner seed phrase.
const IPFS_NODE_URL = "IPFS_NODE_URL"; // The IPFS node used.
const IPFS_API_KEY = "IPFS_API_KEY"; // The IPFS node API KEY if required.
const CLUSTER_ID = 0; // The cluster of TEE enclaves used to store private key shares.
const CAPSULE_NFT_ROYALTY = 10; // Percentage of all second sales that the capsule NFT creator will receive - 10%.
const COLLECTION_ID = undefined; // The collection to which the capsule NFT belongs. Optional Parameter: Default is undefined.
const IS_SOULBOUND = false; // If true, makes the Capsule NFT a Soulbound token. Default is false.
const ipfsClient = new TernoaIPFS(new URL(IPFS_NODE_URL), IPFS_API_KEY);
const keyring = await getKeyringFromSeed(SEED);
const keys = {
privateKey: "PRIVATE_PGP_KEY",
publicKey: "PUBLIC_PGP_KEY",
};
const NFTFile = new File(
[await fs.promises.readFile("FILE_NAME")],
"FILE_NAME",
{
type: "FILE_TYPE",
}
);
const nftMetadata = {
title: "Nice souvenir",
description: "This is my first Capsule NFT on Ternoa.",
};
const file1 = new File(
[await fs.promises.readFile("FILE_NAME_1")],
"FILE_NAME_1",
{
type: "FILE_TYPE_1",
}
);
const file2 = new File(
[await fs.promises.readFile("FILE_NAME_2")],
"FILE_NAME_2",
{
type: "FILE_TYPE_2",
}
);
const encryptedFile1 = await encryptFile(file1, "PUBLIC_PGP_KEY");
const encryptedFile2 = await encryptFile(file2, "PUBLIC_PGP_KEY");
const capsuleMetadata = {
title: "(OPTIONAL) A secret stash.",
description: "(OPTIONAL) This is my first Capsule NFT on Ternoa.",
};
const capsuleNftData = await mintCapsuleNFT(
keyring,
ipfsClient,
keys,
NFTFile,
nftMetadata,
[
{
encryptedFile: encryptedFile1,
type: file1.type,
},
{
encryptedFile: encryptedFile2,
type: file2.type,
},
],
capsuleMetadata,
CLUSTER_ID,
CAPSULE_NFT_ROYALTY,
COLLECTION_ID,
IS_SOULBOUND,
WaitUntil.BlockInclusion
);
console.log("The on-chain Capsule NFT id is: ", capsuleNftData.event.nftId);
} catch (e) {
console.error(e);
}
};Next
Support
Last updated