Skip to main content

Mint Token

Minting tokens is an essential function of the edeXa ERC20 API. To mint tokens, the mintToken method is used.


Prerequisites


Sample Code Snippet

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

// SDK.js
import { ERC20, Network } from 'edeXa-sdk';

async function mintToken() {
const erc20 = new ERC20({
...settings,
authorization: `Bearer ${token}`,
});

const settings = {
network: Network.SANDBOX, // or Network.MAINNET for the mainnet network
};

const dataToMintToken = {
value: 'Enter the amount of tokens to mint',
chaincode: 'Name of the smart contract', // Optional
channel: 'Name of the channel', // Optional
};

try {
const mintTokenResponse = await erc20.mintToken(dataToMintToken);
// Handle success
} catch (error) {
// Handle error
}
}

Important Notes

  • Authentication Token: Replace the token in the authorization header with your actual authentication token.
  • Asynchronous Execution: The mintToken function is an async function that uses await to pause execution until the erc20.mintToken promise resolves. If successful, the minting response is logged. Errors are caught and logged using console.error.
  • Token Amount: Specify the amount of tokens you want to mint in the value field.

Request Parameters

The dataToMintToken object requires the following parameters:

ParameterRequiredTypeDescriptionDefault
valueYesFloatThe amount of tokens to mint
chaincodeOptionalStringThe name of the smart contract managing the tokensDefault chaincode
channelOptionalStringThe name of the channel in the blockchain networkDefault channel

Response Format

The response from the mintToken method includes:

KeyTypeDescription
balanceNumberThe updated balance after minting
minterStringThe identifier of the minter