Skip to main content

Minting Tokens

This guide outlines the process of minting tokens within your blockchain application using the ERC1155 API. The mintToken method enables the creation of new tokens, adding them to the total supply and assigning them to a specific account.


Overview of the mintToken Method

Minting is the process of creating new tokens and is a crucial feature for token management in blockchain applications. It allows for the initial distribution of tokens, rewards issuance, and more.


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 mintToken method:

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

async function mintToken() {
// Configuration settings for the ERC1155 instance
const settings = {
network: Network.SANDBOX, // Use Network.MAINNET for production environments
};

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

// Data required for minting tokens
const dataToMintToken = {
value: 100, // Amount of tokens to mint
chaincode: 'optionalChaincodeName', // Optional: Chaincode name
channel: 'optionalChannelName', // Optional: Blockchain channel
};

try {
// Execute the minting operation
const mintTokenResponse = await erc1155.mintToken(dataToMintToken);
// Handle success
} catch (error) {
// Handle error
}
}

Request Parameters

ParameterTypeRequiredDescription
valueNumberYesThe amount of tokens you want to mint.
chaincodeStringNoThe name of the smart contract or chaincode managing the tokens.
channelStringNoThe name of the blockchain channel where the minting occurs.

Response Format

Upon successfully minting the tokens, the mintToken method returns a response object containing:

KeyTypeDescription
tokenIdStringThe unique identifier of the minted tokens.
minterStringThe username of the user who minted the tokens.