transfer

transfer

The transfer function facilitates the transfer of a specified token amount from one Ethereum address to another. This operation is fundamental in the functionality of any ERC20 token. The function is a member of the ERC20Instance object, which is obtained through the getERC20Instance method of ZkyugaClient.

Method Signature

transfer(recipient: string, amount: BigNumberish, signer: WalletSigner): Promise<TransactionResponse>

Parameters

Parameter
Type
Description

recipient

string

The Ethereum address of the recipient who will receive the tokens. tokens.

amount

BigNumberish

The amount of tokens to transfer, specified in the smallest token unit (e.g., Wei for Ether). Acceptable as a number, string, or BigNumber.

signer

WalletSigner

The wallet signer instance responsible for transaction signature. Typically generated using the createWalletSigner method from ZkyugaClient.

Returns

  • A Promise that resolves to a TransactionResponse object, providing transaction details such as its status and hash.

Usage Example

Begin by instantiating the desired ERC20 token contract using its contract address:

const erc20 = zkyugaClient.getERC20Instance("0xa3ACa2a43F8E1C9b7bDBb1908A0cfBF16fE8B3E1");

Move digital assets (tokens) to another account using a specific function called transfer.

const recipientAddress = "0xF39Fd6e51aad88F6F4ce6aB8827279cffFb92266";
const transferAmount = "1000000000000000000"; // This is equivalent to 1 token, considering 18 decimals
const signer = zkyugaClient.createWalletSigner("YOUR_PRIVATE_KEY");

const transactionResponse = await erc20.transfer(recipientAddress, transferAmount, signer);
console.log(`Transaction Hash: ${transactionResponse.hash}`);

Considerations

  • Ensure the sending address has adequate balance before initiating the transfer.

  • The amount parameter is expressed in the token's smallest divisible unit. For many ERC20 tokens, this equates to a value with 18 decimals. Verify proper conversions when specifying the amount.

  • Safeguard your private keys diligently. When utilizing the signer, exercise caution to prevent exposure of private keys in insecure environments or client-side code.


Last updated