WalletConnect / Web3ModalFlutter

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

[Bug]Metamask signature does not work. #122

Open iseruuuuu opened 1 week ago

iseruuuuu commented 1 week ago

Describe the bug

To Reproduce Steps to reproduce the behavior:

  1. Launch metamask and connect
  2. Go back to the app and "sign wallet
  3. launch metamask and sign
  4. go back to the app and log in

Expected behavior Transition to the meta mask and expect to be able to process signatures

Screenshots

Smartphone (please complete the following information):

Flutter Doctor

[✓] Flutter (Channel stable, 3.16.5, on macOS 14.4.1 23E224 darwin-arm64 (Rosetta), locale ja-JP)
[✓] Android toolchain - develop for Android devices (Android SDK version 33.0.0)
[✓] Xcode - develop for iOS and macOS (Xcode 15.3)
[✓] Chrome - develop for the web
[✓] Android Studio (version 2023.2)
[✓] VS Code (version 1.88.0)

Additional context

dependencies:
  web3modal_flutter: ^3.1.3
  riverpod_annotation: ^2.3.3

dev_dependencies:
  build_runner: ^2.4.7
  riverpod_generator: ^2.3.9
  riverpod_lint: ^2.3.7
import 'package:riverpod_annotation/riverpod_annotation.dart';
import 'package:web3modal_flutter/web3modal_flutter.dart';

part 'wallet_connect.g.dart';

@riverpod
Future<W3MService> walletConnect(WalletConnectRef ref) async {
  const metamask =
      'c57ca95b47569778a828d19178114f4db188b89b763c899ba0be274e97267d96';
  final w3mService = W3MService(
    projectId: ApiConstants.projectId,
    includedWalletIds: {metamask},
    featuredWalletIds: {metamask},
    excludedWalletIds: {metamask},
    metadata: const PairingMetadata(
      name: 'Web3Modal Flutter Example',
      description: 'Web3Modal Flutter Example',
      url: 'https://web3modal.com/',
      icons: ['https://web3modal.com/images/rpc-illustration.png'],
      redirect: Redirect(
        native: 'web3modalflutter://',
        universal: 'https://web3modal.com',
      ),
    ),
  );
  await w3mService.init();
  return w3mService;
}
/// Provider for signature
@riverpod
class Certification extends _$Certification {
  @override
  bool build() {
    return false;
  }

 Future<bool> certificationWithWalletConnect(BuildContext context) async {
    final walletConnect = await ref.read(walletConnectProvider.future);
    ///  The address is ready to be acquired.
    final address = ref.watch(walletProvider);
    /// The nonce is also getting it right.
    final nonce = await getNonce();
    final bytes = utf8.encode('Here is a basic message!$nonce');
    final encoded = hex.encode(bytes);
 ///  I want to call in signedMessage, but the signature process doesn't work.
    final signedMessage = await walletConnect.web3App!.request(
      chainId: 'eip155:1',
      topic: walletConnect.session?.topic ?? '',
      request: SessionRequestParams(
        method: 'personal_sign',
        params: ['0x$encoded', address],
      ),
    );

    if (signedMessage == '') {
      return false;
    }
    return true;
  }
iseruuuuu commented 1 week ago

Referenced implementations

iseruuuuu commented 1 week ago

Status quo

  1. Attempt login with walletConnect.openModal(context); to open meta-mask → login succeeded, address retrieval complete
  2. Return to the application and go to the authentication screen
  3. Press the signature button, but the metamask does not transition and not even a signature appears.
quetool commented 1 week ago

Hello, @iseruuuuu Did you call _w3mService.launchConnectedWallet(); right before your walletConnect.web3App!.request() call? Did you try some other Wallet?

On a side note, this 👇 is wrong:

includedWalletIds: {metamask},
featuredWalletIds: {metamask},
excludedWalletIds: {metamask},

What's your goal here? If you want to show only Metamask (which I don't recommend) you would just use includedWalletIds: {metamask}, that's enough.

iseruuuuu commented 1 week ago

@quetool Thanks for replay🙇

On a side note, this 👇 is wrong: includedWalletIds: {metamask}, featuredWalletIds: {metamask}, excludedWalletIds: {metamask}, What's your goal here? If you want to show only Metamask (which I don't recommend) you would just use includedWalletIds: {metamask}, that's enough.

Did you try some other Wallet?

Did you call _w3mService.launchConnectedWallet(); right before your walletConnect.web3App!.request() call?

  • Is the following assumption correct for implementation? I was able to open the meta mask, but no signature appeared.
    await walletConnect.launchConnectedWallet();
    final signedMessage = await walletConnect.web3App!.request(
    chainId: 'eip155:1',
    topic: walletConnect.session?.topic ?? '',
    request: SessionRequestParams(
    method: 'personal_sign',
    params: ['0x$encoded', address],
    ),
    );
quetool commented 1 week ago

Is the following assumption correct for implementation?

Nope, it's totally fair if you want to use only Metamask, for that it's enough to just use includedWalletIds: {metamask},

I asked to try some other wallets just to check if could be an issue with Metamask alone or a broader issue.

iseruuuuu commented 1 week ago

@quetool Thank you. As an additional matter to share, I did the above implementation on iOS and was able to confirm that the transition to the meta mask was correct and the signature process was issued. Therefore, I felt that there might be a problem with Android.

Also, I have tried to describe the AndroidManifest and other descriptions with reference to the SAMPLES, but it does not work.

As for the specific Android status,

quetool commented 1 week ago

Do you mind sharing a complete reproducible code? I'd like to see at the crash.