Skip to main content

Batch Burning Tokens

The batchBurn method in the ERC1155 API allows developers to efficiently burn (permanently remove) multiple tokens in a single operation. This functionality is crucial for managing token supply and can be used in various scenarios, such as redeeming tokens, removing expired tokens, or adjusting the token supply for balancing.


Overview of the batchBurn Method

Burning tokens is a common practice in token management that involves permanently removing a certain quantity of tokens from circulation. The batchBurn method streamlines this process by enabling the burning of multiple tokens at once, reducing the need for multiple transactions.


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

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

async function batchBurn() {
// 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 burn operation
const dataToBatchBurn = {
tokenId: ['tokenId1', 'tokenId2'], // Array of tokenIds to burn
value: [100, 50], // Corresponding array of amounts for each tokenId
chaincode: 'optionalChaincodeName', // Optional: specific chaincode name
channel: 'optionalChannelName', // Optional: specific blockchain channel
};

try {
// Execute the batch burn operation
const batchBurnResponse = await erc1155.batchBurn(dataToBatchBurn);
// Handle success
} catch (error) {
// Handle error
}
}

Request Parameters

Below is a table that outlines the parameters required to set token spending approval through the approveTokenAccess method. Each parameter is listed with its type, whether it is required or optional, and a description of its purpose.

ParameterTypeRequiredDescription
tokenIdArrayYesAn array containing the IDs of the tokens to be burned.
valueArrayYesAn array containing the amounts of each token to be burned, corresponding to the tokenIds.
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 successfully burning the tokens, the batchBurn method will return a response object containing the following attribute:

KeyTypeDescription
burnerStringThe username of the user who performed the burn operation.