transferFrom

The transferFrom method allows a contract to transfer a specified amount of tokens from one Ethereum address to another. This method is particularly useful in scenarios where a contract needs to perform token transfers on behalf of users, provided that the token owner has already given approval via the approve method. The transferFrom method is a part of the ERC20Instance object, returned by the getActionContractInstance method of a custom client implementation.

Method Signature

async transferFrom(from: string, to: string, amount: string, signer: any): Promise<string>

Parameters

Parameter
Type
Description

from

string

The Ethereum address from which tokens will be transferred.

to

string

The Ethereum address to which tokens will be transferred.

amount

string

The amount of tokens to be transferred.

signer

any

The signer object to authorize the transaction.

Return Value

The method returns a Promise that resolves to a string, representing the transaction result.

Example Usage

let fromAddress = "0xFromAddress";
let toAddress = "0xToAddress";
let amount = "2000";
let signer = new WalletSigner();

let transferResult = await client.transferFrom(fromAddress, toAddress, amount, signer);

Remarks

Before calling transferFrom, ensure that the from address has approved the caller (or the contract) to spend the specified amount of tokens. The approval is typically obtained through the approve method.

The actual implementation of transferFrom may vary depending on the token contract's logic and the underlying ERC20 standard implementation.