Skip to main content

Batch Token Transfer to Multiple Users

This guide outlines the process for transferring multiple tokens to multiple users in a single operation using the ERC1155 API. The tokenTransferMultiUsers method facilitates this process, enhancing the efficiency of token distributions.


Overview of the tokenTransferMultiUsers Method

Batch token transfers are crucial for applications that require distributing tokens to multiple users simultaneously, such as rewards, airdrops, or initial token distributions. This method streamlines the process, reducing the complexity and cost associated with individual transfer 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 tokenTransferMultiUsers method:

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

async function tokenTransferToMultiUser() {
// 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 the token transfer
const dataToTokenTransfer = {
to: ['username1', 'username2'], // Usernames of the recipients
tokenId: ['tokenId1', 'tokenId2'], // Token IDs to transfer
value: [100, 200], // Amounts of each token to transfer
chaincode: 'optionalChaincodeName', // Optional chaincode name
channel: 'optionalChannelName', // Optional blockchain channel
};

try {
// Execute the batch token transfer
const transferTokenResponse = await erc1155.tokenTransferMultiUsers(
dataToTokenTransfer
);
// Handle success
} catch (error) {
// Handle error
}
}

Request Parameters

ParameterTypeRequiredDescription
toArrayYesAn array containing the usernames of the users to receive tokens.
tokenIdArrayYesAn array of token IDs for the tokens being transferred.
valueArrayYesAn array of amounts for each token being transferred.
chaincodeStringNoThe name of the smart contract or chaincode managing the tokens.
channelStringNoThe name of the blockchain channel where the transfer occurs.

Response Format

Upon successfully executing the batch token transfer, the tokenTransferMultiUsers method returns a response object containing:

KeyTypeDescription
toArrayAn array of usernames of the users who received tokens.
fromStringThe username of the user who initiated the transfer.