Skip to main content

Batch Minting Tokens

The batchMint method enables developers to mint multiple tokens in a single operation, simplifying the process of issuing tokens on the blockchain. This functionality is essential for creating tokens in bulk, whether for initial distribution, rewards, or other purposes.


Overview of the batchMint Method

Minting tokens refers to the process of creating new tokens and adding them to the circulation within the blockchain network. The batchMint method streamlines this process by allowing the creation of multiple tokens at once, enhancing efficiency and scalability.


Prerequisites

  • Installed the edeXa-sdk in your project.
  • An authentication token obtained through the SDK's authentication method. This token is necessary to authorize your requests.

Sample Code Snippet

Here is a JavaScript code snippet demonstrating the use of the batchMint method:

import { ERC1155, Network } from 'edeXa-sdk';

async function batchMintToken() {
// Define network settings and authorization
const settings = {
network: Network.SANDBOX, // Use Network.MAINNET for production environments
};

const erc1155 = new ERC1155({
...settings,
authorization: `Bearer ${token}`, // Replace `${token}` with your actual authorization token
});

// Define the data for the batch mint operation
const dataToBatchMintToken = {
value: [100, 200], // Array of amounts for each token to be minted
chaincode: 'optionalChaincodeName', // Optional: specific chaincode name
channel: 'optionalChannelName', // Optional: specific blockchain channel
};

try {
// Execute the batch mint operation
const batchMintTokenResponse = await erc1155.batchMint(
dataToBatchMintToken
);
// Handle success
} catch (error) {
// Handle error
}
}

Request Parameters

ParameterTypeRequiredDescription
valueArrayYesAn array containing the amounts of each token to be minted.
chaincodeStringNoThe name of the smart contract or chaincode managing the tokens.
channelStringNoThe name of the blockchain channel where the operation will be executed.

Response Format

Upon successful minting, the batchMint method returns a response object containing the following attributes:

KeyTypeDescription
tokenIdArrayAn array of token IDs for the minted tokens.
minterStringThe username of the user who performed the minting operation.