transferFrom method
Future<String>
transferFrom(
- String contractAddres_,
- dynamic _spenderAddr,
- dynamic receiver_Address,
- dynamic transferfrom_value,
- dynamic SpenderPrivatekey,
- dynamic ownerAddress,
Transfer tokens from one address to another contractAddres_ : Token Address. _spenderAddr : Spender Address is The address which you want to send tokens from. reciever_Address : Reciever Address is The address which you want to transfer to. spenderPrivateKey: Spender's Private key. ownerAddress : Token Owner Address. transferfrom_value : the amount of tokens to be transferred.
Implementation
Future<String> transferFrom(
String contractAddres_,
_spenderAddr,
receiver_Address,
transferfrom_value,
SpenderPrivatekey,
ownerAddress) async {
final EthereumAddress contractAddr =
EthereumAddress.fromHex(contractAddres_);
final contract = DeployedContract(
ContractAbi.fromJson(abiString, 'XRC20'), contractAddr);
final tokenTransferFrom = contract.function('transferFrom');
final EthereumAddress spender = EthereumAddress.fromHex(_spenderAddr);
final EthereumAddress receiver = EthereumAddress.fromHex(receiver_Address);
final EthereumAddress ownAddr = EthereumAddress.fromHex(ownerAddress);
final BigInt parsed__value = BigInt.parse('1000000000000000000');
final nonce = await client.getTransactionCount(spender);
final gasPrice = await client.getGasPrice();
final transferFrom = await Transaction.callContract(
contract: contract,
function: tokenTransferFrom,
parameters: [
ownAddr,
receiver,
BigInt.from(transferfrom_value) * parsed__value
],
from: spender,
gasPrice: gasPrice,
nonce: nonce,
maxFeePerGas: null,
maxPriorityFeePerGas: null,
);
final String spender_privateKey = SpenderPrivatekey;
final credentials = await EthPrivateKey.fromHex(spender_privateKey);
final transferForms = await client.sendTransaction(
credentials, transferFrom,
chainId: null, fetchChainIdFromNetworkId: true);
return ('$transferForms');
}