Skip to main content

safeBatchTransferFrom

The safeBatchTransferFrom method in the ERC-1155 token standard orchestrates the secure transfer of specified amounts of multiple tokens with their respective IDs from one Ethereum address to another. This method ensures a streamlined and secure transaction by verifying if the receiving address implements the essential ERC-1155 token receiver interface. This method is encompassed within the ERC1155Instance object, obtainable via the relevant method of the EdexaClient or the corresponding library.

Method Signature

async safeBatchTransferFrom(
from: string,
to: string,
ids: string[],
values: string[],
data: string,
signer: WalletSigner
): Promise<TransactionResponse>

Parameters

ParameterTypeDescription
fromstringThe Ethereum address initiating the token transfer.
tostringThe Ethereum address intended to receive the tokens.
idsstring[]An array of specific IDs of the ERC-1155 tokens involved in the transfer.
valuesstring[]An array specifying the quantities of each token to be transferred, correlating with the provided IDs.
datastringOptional additional data or bytes accompanying the transfer.
signerWalletSignerThe wallet signer instance tasked with signing the transaction.

Returns

  • A Promise resolving to a TransactionResponse, offering details concerning the batch transfer transaction.

Usage Example

First, instantiate the desired ERC-1155 token contract:

const erc1155 = edexaClient.getERC1155Instance("your ERC-1155 contract address here");

Subsequently, employ the safeBatchTransferFrom method with the pertinent parameters:

const senderAddress = "0x1a2b3C45d6E7f8b9E0ed5678Df1234567A89BcDe";
const recipientAddress = "0x2c360D20cE6b3D8b466511eF093C9177c3817B94";
const tokenIds = ["token-id-1", "token-id-2", "token-id-3"];
const transferAmounts = ["50", "25", "75"];
const dataBytes = "0x"; // Optional data bytes
const signer = edexaClient.createWalletSigner("your private key");

const batchTransferTransaction = await erc1155.safeBatchTransferFrom(senderAddress, recipientAddress, tokenIds, transferAmounts, dataBytes, signer);
console.log(`Batch Transfer Transaction Hash: ${batchTransferTransaction.hash}`);

Notes

  • The safeBatchTransferFrom method enhances efficiency by consolidating multiple token transfers into a single transaction, while also ensuring the recipient's capability to handle ERC-1155 tokens.

  • Prior to initiating a batch transfer, always validate the Ethereum addresses, token IDs, and other parameters to guarantee the precision and security of the token movement.