Open LongTien15 opened 1 year ago
A transaction sending an ERC-20 token needs to have the token contract as the recipient (the to field), and the data field containing encoded instructions to execute its transfer() function along with address of the token receiver and amount.
Here's some more information: https://stackoverflow.com/a/70847856/798314
I did it but metamask does not recognize the token. I think it is because in wallet_connect send_transaction, the value is always in ETH?
@LongTien15 You can try and write your own sendTransaction
and play with the values using sendCustomRequest
Future<String> sendTransaction({
required String from,
String? to,
Uint8List? data,
int? gas,
BigInt? gasPrice,
BigInt? value,
int? nonce,
}) async {
final result = await connector.sendCustomRequest(
method: 'eth_sendTransaction',
params: [
{
'from': from,
if (data != null) 'data': hex.encode(List<int>.from(data)),
if (to != null) 'to': to,
if (gas != null) 'gas': '0x${gas.toRadixString(16)}',
if (gasPrice != null) 'gasPrice': '0x${gasPrice.toRadixString(16)}',
if (value != null) 'value': '0x${value.toRadixString(16)}',
if (nonce != null) 'nonce': '0x${nonce.toRadixString(16)}',
}
],
);
return result;
}
It's always ETH. I want it to be my ERC20 tokens
I called the transfer from, from my account to the DAI ERC20 smart contract
Sorry, my bad. My parameters are wrong. Thank you
Managed to send some DAI to the contract. But i cannot approve it. calling send transaction with the approve function as the data not working.
@LongTien15
Managed to send some DAI to the contract. But i cannot approve it. calling send transaction with the approve function as the data not working.
any update ?
@LongTien15 You can try and write your own
sendTransaction
and play with the values usingsendCustomRequest
Future<String> sendTransaction({ required String from, String? to, Uint8List? data, int? gas, BigInt? gasPrice, BigInt? value, int? nonce, }) async { final result = await connector.sendCustomRequest( method: 'eth_sendTransaction', params: [ { 'from': from, if (data != null) 'data': hex.encode(List<int>.from(data)), if (to != null) 'to': to, if (gas != null) 'gas': '0x${gas.toRadixString(16)}', if (gasPrice != null) 'gasPrice': '0x${gasPrice.toRadixString(16)}', if (value != null) 'value': '0x${value.toRadixString(16)}', if (nonce != null) 'nonce': '0x${nonce.toRadixString(16)}', } ], ); return result; }
hey when i use this result coming null how i can fix this?? i wanted write on smartcontract using walletconnect
EthereumWalletConnectProvider send transasction only to send eth, i want to send other tokens in my metamask wallet like DAI,..