y-pakorn / flutter_web3

Web3 Ethereum, Etherjs and Wallet Connect wrapper for Flutter Web.
Other
134 stars 47 forks source link

Send ERC20 tokens with wallet private key #46

Open diegobarle opened 2 years ago

diegobarle commented 2 years ago

From the documentation we can initialise a wallet using a private key (or mnemonic) and connect it to a provider to be able to send transactions:

final linkContractAddress = "0xa36085F69e2889c224210F603D836748e7dC0088";
final linkContract = ContractERC20(linkContractAddress, provider!.getSigner());
final linkProvider = linkContract.contract.provider;
final wallet = Wallet(myPrivateKey, linkProvider);

final toAddress = "0x...";
final amount = BigInt.from(1);

final transaction = await testWallet.sendTransaction(TransactionRequest(
        to: toAddress,
        value: amount,
      ),);

final receipt = await transaction.wait(); 

The result of this is the wallet sending to {toAddress} a total of {amount} ETH.

How can I specify to send LINK (from the ContractERC20 I've specified above) instead of ETH?

4xMafole commented 1 year ago

Hello, @diegobarle. Can you elaborate more about the issue?