WalletConnect / Web3ModalFlutter

The Web3Modal for WalletConnect built using Flutter.
https://pub.dev/packages/web3modal_flutter
Apache License 2.0
44 stars 44 forks source link

[HELP] How to personal sign, make transaction with Coinbase ? #141

Closed mthinh closed 5 months ago

mthinh commented 5 months ago

Describe the bug I was able to connect coinbase, but cannot request a message signed The error keeps saying "No matching key. session topic doesn't exist: And I found out that cause we are connecting to coinbase data which does not contain topic

I'm currently using v.3.1.2

Screenshots

Screenshot 2024-06-24 at 14 12 45 Screenshot 2024-06-24 at 14 13 52

Desktop (please complete the following information):

Smartphone (please complete the following information):

Additional context Add any other context about the problem here.

quetool commented 5 months ago

Hello @mthinh, can I see your implementation?

mthinh commented 5 months ago
Future<String?> personalSign({
  required String message,
  required String wallet,
  String? chainId,
}) async {
  await _w3mService.launchConnectedWallet();

  if (_w3mService.session?.sessionService.isCoinbase == true) {
    final data = await _w3mService.cbRequest(
      chainId: chainId ?? _currentWalletChainId ?? ETHEREUM.chainId,
      request: SessionRequestParams(
        method: 'personal_sign',
        params: [message, wallet],
      ),
    );
    if (data is String) return data;
    return null;
  }

  final data = await _app!.request(
    topic: _w3mService.session?.topic ?? '',
    chainId: chainId ?? _currentWalletChainId ?? ETHEREUM.chainId,
    request: SessionRequestParams(
      method: 'personal_sign',
      params: [message, wallet],
    ),
  );
  if (data is String) return data;

  return null;
}

Thanks @quetool , I just found out that we always have cbRequest method to handle coinbase case

quetool commented 5 months ago

cbRequest shouldn't be used and it will be deprecated soon. Let me take a look at your code.

quetool commented 5 months ago

This is what you need to do. I added some explanatory comments.

Future<String?> personalSign({
  required String message,
  required String wallet,
}) async {
  _w3mService.launchConnectedWallet(); // you don't have to await this method

  // not sure why you used `_app!.request()` here, what is _app?
  final data = await _w3mService!.request(
    topic: _w3mService.session?.topic ?? '',
    // chainId chas to be always the current selected chain, otherwise request might not work on several wallets if the chain was not approved.
    chainId: _w3mService.selectedChain!.chainId,
    request: SessionRequestParams(
      method: 'personal_sign',
      params: [message, wallet],
    ),
  );
  if (data is String) return data;

  return null;
}
mthinh commented 5 months ago

cool, thanks, let me try to @quetool

mthinh commented 5 months ago

Hi @quetool , btw, you got any idea on Coinbase side ? I tried to sign a transaction, but always facing the error saying Something went wrong Here is my code

Future<String> requestTransaction({
    required String chainId,
    required EthereumTransaction transaction,
  }) async {
    _w3mService.launchConnectedWallet();

    final transactionId = await _w3mService.request(
      topic: _w3mService.session?.topic ?? '',
      chainId: chainId,
      request: SessionRequestParams(
        method: 'eth_sendTransaction',
        params: [
          transaction.copyWith(data: transaction.data ?? '').toJson(),
        ],
      ),
    );
    return transactionId;
  }

IMG_8934

quetool commented 5 months ago

This is something on Coinbase side. Anyway this is not a personal_sign, right? Did the personal_sign example work? Any chance you can share the code for this transaction issue? I'm pretty sure it might be something wrong in the transaction object that Coinbase can't part properly.

mthinh commented 5 months ago

@quetool , this is the code to make a transaction request, it works with other wallet (metamask, etc,..) but coinbase. Btw, sign transaction is working now. Thanks

quetool commented 5 months ago

Wonderful! Would be interesting if you could share the transaction object so I could debug and report to Coinbase if the issue is on their side

mthinh commented 5 months ago

Hi @quetool , this is how transaction object looks like

Screenshot 2024-06-24 at 15 27 41
quetool commented 5 months ago

And is this not working? The only thing I see is the missing 0x in the hex representation of the value but that shouldn't be an issue. It is weird anyway that is not added if you are using .toJson() method from our package

quetool commented 5 months ago

Please remove the copyWith(data: transaction.data ?? '') from transaction and try again.

mthinh commented 5 months ago

If I remove it, will face this error, cause data is required as string

Screenshot 2024-06-24 at 15 41 15 Screenshot 2024-06-24 at 15 41 54
mthinh commented 5 months ago

btw, Im using eth sepolia to test , also try data = 0x0 but no luck

Screenshot 2024-06-24 at 15 49 36
quetool commented 5 months ago

Seems like you are using and old version of our package. Could you please update to web3modal_flutter: ^3.2.2?

mthinh commented 5 months ago

@quetool yes. currently using 3.1.2 cause I dont see any differences between 3.1.2 and 3.2.2 in term of coinbase stuff

quetool commented 5 months ago

But there are :) You can check coinbase_service here https://github.com/WalletConnect/Web3ModalFlutter/blob/master/lib/services/coinbase_service/coinbase_service.dart#L222

Several other bug fixes and new features were made in following versions https://pub.dev/packages/web3modal_flutter/changelog

I would totally update if I were you :)

mthinh commented 5 months ago

@quetool sure ah, thanks, let me update and retry

mthinh commented 5 months ago

Thanks @quetool , I can see transaction confirmation popup now. Thanks a lot for your great help 🙏

quetool commented 5 months ago

Wonderful! I'll close the issue then! Thanks!