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 ZkyugaClient
or the corresponding library.
Method Signature
async safeBatchTransferFrom(
from: string,
to: string,
ids: string[],
values: string[],
data: string,
signer: WalletSigner
): Promise<TransactionResponse>
Parameters
from
string
The Ethereum address initiating the token transfer.
to
string
The Ethereum address intended to receive the tokens.
ids
string[]
An array of specific IDs of the ERC-1155 tokens involved in the transfer.
values
string[]
An array specifying the quantities of each token to be transferred, correlating with the provided IDs.
data
string
Optional additional data or bytes accompanying the transfer.
signer
WalletSigner
The wallet signer instance tasked with signing the transaction.
Returns
A
Promise
resolving to aTransactionResponse
, offering details concerning the batch transfer transaction.
Usage Example
First, instantiate the desired ERC-1155 token contract:
const erc1155 = zkyugaClient.getERC1155Instance("your ERC-1155 contract address here");
Subsequently, employ the safeBatchTransferFrom
method with the pertinent parameters:
const senderAddress = "0x315cbb881Ac891D28F78FFd47A9fe6b0D5a23D86";
const recipientAddress = "0xF39Fd6e51aad88F6F4ce6aB8827279cffFb92266";
const tokenIds = ["token-id-1", "token-id-2", "token-id-3"];
const transferAmounts = ["100", "125", "175"];
const dataBytes = "0x"; // Optional data bytes
const signer = zkyugaClient.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.
Last updated