Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Send tokens other than ETH #69

Open
LongTien15 opened this issue Aug 5, 2022 · 9 comments
Open

Send tokens other than ETH #69

LongTien15 opened this issue Aug 5, 2022 · 9 comments

Comments

@LongTien15
Copy link

LongTien15 commented Aug 5, 2022

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

@RootSoft
Copy link
Owner

RootSoft commented Aug 8, 2022

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

@LongTien15
Copy link
Author

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?

@RootSoft
Copy link
Owner

RootSoft commented Aug 8, 2022

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

@LongTien15
Copy link
Author

Capture

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

@LongTien15
Copy link
Author

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

@LongTien15
Copy link
Author

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

@LongTien15 LongTien15 reopened this Aug 8, 2022
@LongTien15
Copy link
Author

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.

Repository owner deleted a comment Aug 9, 2022
@moesaid
Copy link

moesaid commented Jan 23, 2023

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

@bansalgaurav852
Copy link

@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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants
@RootSoft @moesaid @LongTien15 @bansalgaurav852 and others