Mint + UpdateMetadata

Each Update Metadata has a Kapp Fee of 2KLV, and the Bandwidth Fee depends on the size of the metadata

metadataScript.js

import { Account, utils, TransactionType } from "@klever/sdk-node";

utils.setProviders({
  api: "https://api.devnet.klever.finance",
  node: "https://node.devnet.klever.finance",
});

const privateKey = "Your PrivateKey";
const mainAccount = new Account(privateKey);
await mainAccount.ready;
const receiverAccount = mainAccount.getAddress(); // the account receiver of the NFTs

const assetTriggerMint = {
  amount: 50, // any amount you want, up to 50
  assetId: "Your AssetId",
  triggerType: 0, // Mint
};

const contracts = [
  {
    type: TransactionType.AssetTrigger,
    payload: {
      ...assetTriggerMint,
      receiver: receiverAccount,
    },
  },
];

const transactionRes = [mainAccount.quickSend(contracts)];
const result = await utils.transactionsProcessed(transactionRes);
const arrayAssetId = [];

if (result[0].transaction.status !== 'success') {
  throw new Error(`Transaction failed: ${result[0].transaction.resultCode}`);
}

result[0].transaction.receipts.slice(2).forEach((element) => {
  if (!element.assetId.includes('/')) {
    throw new Error(`${element.assetId} is not a NFT. The amount was minted but the metadata can't be updated`);
  }
  arrayAssetId.push(element.assetId);
});

const updateMetaDataContracts = [];
const updateMetaDataDatas = [];
arrayAssetId.forEach((assetId) => {
  updateMetaDataContracts.push({
    type: TransactionType.AssetTrigger,
    payload: {
      triggerType: 8,
      assetId: assetId,
      mime: "application/json", // You can use any MIME type.
      // Here is a list of the most common ones: 
      // https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types/Common_types
      receiver: receiverAccount,
    },
  });
  updateMetaDataDatas.push(JSON.stringify({assetId})); // You can send any metadata for the given assetId here
});

const requestArray = [];
for (
  let index = 0;
  index < updateMetaDataContracts.length;
  index = index + 20 // The amount of contracts per transaction is limited to 20
) {
  const request = await mainAccount.quickSend(
    updateMetaDataContracts.slice(
      index,
      index + 20 < updateMetaDataContracts.length
        ? index + 20
        : updateMetaDataContracts.length
    ),
    updateMetaDataDatas.slice(
      index,
      index + 20 < updateMetaDataContracts.length
        ? index + 20
        : updateMetaDataContracts.length
    )
  );
  requestArray.push(request);
}

const resultUpdateMetaData = await utils.transactionsProcessed(requestArray);
resultUpdateMetaData.forEach((element, index) => {
  console.log(`Hash ${index}: ${element.transaction.hash}`)
});

Last updated