transfer
The transfer
method allows token holders to send a specified amount of tokens to another Ethereum address. This is one of the fundamental operations of any ERC20 token. The method belongs to the ERC20Instance
object, which is returned by the getERC20Instance
method of EdexaClient
.
Method Signature
transfer(recipient: string, amount: BigNumberish, signer: WalletSigner): Promise<TransactionResponse>
Parameters
Parameter | Type | Description |
---|---|---|
recipient | string | The Ethereum address of the party set to receive the tokens. |
amount | BigNumberish | The count of tokens to transfer, denoted in the smallest token unit (e.g., Wei for Ether). Acceptable as a number, string, or BigNumber. |
signer | WalletSigner | The wallet signer instance in charge of transaction signature. Commonly produced using createWalletSigner method from EdexaClient . |
Returns
- A
Promise
that resolves to aTransactionResponse
object. This object provides details about the transaction, including its status, transaction hash, and more.
Usage Example
First, instantiate the desired ERC20 token contract using its contract address:
const erc20 = edexaClient.getERC20Instance("0x4DB67190e915C15aA8CCd889F35185D73dA37878");
Then, use the transfer
method to send tokens:
const recipientAddress = "0x2c360D20cE6b3D8b466511eF093C9177c3817B94";
const transferAmount = "1000000000000000000"; // This is equivalent to 1 token, considering 18 decimals
const signer = edexaClient.createWalletSigner("your private key");
const transactionResponse = await erc20.transfer(recipientAddress, transferAmount, signer);
console.log(`Transaction Hash: ${transactionResponse.hash}`);
Notes
Ensure you have sufficient balance in the sending address before initiating the transfer.
The
amount
is specified in the smallest divisible unit of the token. For many ERC20 tokens, this represents a value with 18 decimals. Ensure correct conversions before specifying the amount.Always securely manage your private keys. When using the
signer
, be cautious and avoid exposing private keys in client-side or insecure environments.