Mint Token
Minting tokens is an essential function of the edeXa ERC20 API. To mint tokens, the mintToken
method is used.
Prerequisites
- Authenticate the client using the edeXa SDK. For authentication details, see the authentication method.
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 theauthorization
header with your actual authentication token. - Asynchronous Execution: The
mintToken
function is anasync
function that usesawait
to pause execution until theerc20.mintToken
promise resolves. If successful, the minting response is logged. Errors are caught and logged usingconsole.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:
Parameter | Required | Type | Description | Default |
---|---|---|---|---|
value | Yes | Float | The amount of tokens to mint | |
chaincode | Optional | String | The name of the smart contract managing the tokens | Default chaincode |
channel | Optional | String | The name of the channel in the blockchain network | Default channel |
Response Format
The response from the mintToken
method includes:
Key | Type | Description |
---|---|---|
balance | Number | The updated balance after minting |
minter | String | The identifier of the minter |