walletconnect-dart-sdk icon indicating copy to clipboard operation
walletconnect-dart-sdk copied to clipboard

Send tokens other than ETH

Open LongTien15 opened this issue 3 years ago • 9 comments

EthereumWalletConnectProvider send transasction only to send eth, i want to send other tokens in my metamask wallet like DAI,..

LongTien15 avatar Aug 05 '22 04:08 LongTien15

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

RootSoft avatar Aug 08 '22 08:08 RootSoft

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 avatar Aug 08 '22 08:08 LongTien15

@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;
  }

RootSoft avatar Aug 08 '22 08:08 RootSoft

Capture

It's always ETH. I want it to be my ERC20 tokens

LongTien15 avatar Aug 08 '22 08:08 LongTien15

I called the transfer from, from my account to the DAI ERC20 smart contract

LongTien15 avatar Aug 08 '22 08:08 LongTien15

Sorry, my bad. My parameters are wrong. Thank you

LongTien15 avatar Aug 08 '22 08:08 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.

LongTien15 avatar Aug 08 '22 17:08 LongTien15

@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 ?

moesaid avatar Jan 23 '23 22:01 moesaid

@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;
  }

hey when i use this result coming null how i can fix this?? i wanted write on smartcontract using walletconnect

bansalgaurav852 avatar Mar 07 '23 05:03 bansalgaurav852