WalletConnect / WalletConnectModalFlutter

The WalletConnectModal for WalletConnect built using Flutter.
https://pub.dev/packages/walletconnect_modal_flutter
Apache License 2.0
20 stars 18 forks source link

Does it work with Testnets (Sepolia) #35

Open eelco2k opened 10 months ago

eelco2k commented 10 months ago

Describe the bug

Because w3m_chains_presets.dart does not have the testnet network chains i was referred in a comment to implement it as a custom-chain:

 // See https://docs.walletconnect.com/web3modal/flutter/custom-chains
 W3MChainInfo sepoliaTestnet = W3MChainInfo(
      chainName: 'Sepolia Test Network',
      namespace: 'eip155:11155111',
      chainId: '11155111',
      tokenName: 'SETH',
      requiredNamespaces: {
        'eip155': const RequiredNamespace(
          methods: EthUtil.ethRequiredMethods,
          chains: ['eip155:11155111'],
          events: EthUtil.ethEvents,
        ),
      },
      optionalNamespaces: {
        'eip155': const RequiredNamespace(
          methods: EthUtil.ethOptionalMethods,
          chains: ['eip155:11155111'],
          events: [],
        ),
      },
      rpcUrl: 'https://rpc.sepolia.org',
      blockExplorer: W3MBlockExplorer(
        name: 'Sepolia Etherscan',
        url: 'https://sepolia.etherscan.io',
      ),
    );

 W3MChainPresets.chains.putIfAbsent(
      '11155111',
      () => sepoliaTestnet);

But after after adding the W3MChainInfo() and run the flutter sample app. I can select the Sepolia Testnet, and i can scan the QR code, it also connects to my Metamask wallet, but when i want to execute one of the methods i receive an error


I/flutter (26749): snapshot: AsyncSnapshot<dynamic>(ConnectionState.done, null, WalletConnectError(code: 5100, message: Unsupported chains. The chain eip155:1 is not supported, data: null), #0      SignApiValidatorUtils.isValidNamespacesChainId (package:walletconnect_flutter_v2/apis/sign_api/utils/sign_api_validator_utils.dart:127:7)
I/flutter (26749): #1      SignEngine._isValidRequest (package:walletconnect_flutter_v2/apis/sign_api/sign_engine.dart:1641:27)
I/flutter (26749): <asynchronous suspension>
I/flutter (26749): #2      SignEngine.request (package:walletconnect_flutter_v2/apis/sign_api/sign_engine.dart:473:5)
I/flutter (26749): <asynchronous suspension>
I/flutter (26749): #3      Web3App.request (package:walletconnect_flutter_v2/apis/web3app/web3app.dart:204:14)
I/flutter (26749): <asynchronous suspension>
I/flutter (26749): #4      EIP155.ethSendTransaction (package:walletconnect_flutter_dapp/utils/crypto/eip155.dart:235:12)
I/flutter (26749): <asynchronous suspension>
I/flutter (26749): )

Is this still unsupported in web3modal_flutter @ 3.0.0-beta06 ? or am i implementing it wrong?

quetool commented 10 months ago

Hello @eelco2k, is this a report for WalletConnectModalFlutter or Web3Modal? Coz the info provided is related to Web3Modal but the issue is reported on WalletConnectModalFlutter.

Anyway, I tested it and it's fine for me, you sure you are adding the chain before service init?

W3MChainPresets.chains.putIfAbsent('11155111', () => sepoliaTestnet);
await _w3mService.init();
eelco2k commented 10 months ago

@quetool I'm sorry i posted in the wrong repo. If you suggest me to open a ticket there i will do that but here are some more small tests i conducted.

Yes i added this putIfAbsent before the service init.

I tried the same with the goerli testnet, same problem.


W3MChainInfo goerliTestnet = W3MChainInfo(
      chainName: 'Goerli Test Network',
      namespace: 'eip155:5',
      chainId: '5',
      tokenName: 'ETH',
      requiredNamespaces: {
        'eip155': const RequiredNamespace(
          methods: EthUtil.ethRequiredMethods,
          chains: ['eip155:5'],
          events: EthUtil.ethEvents,
        ),
      },
      optionalNamespaces: {
        'eip155': const RequiredNamespace(
          methods: EthUtil.ethOptionalMethods,
          chains: ['eip155:5'],
          events: [],
        ),
      },
      rpcUrl: 'https://goerli.drpc.org/',
      blockExplorer: W3MBlockExplorer(
        name: 'Sepolia Etherscan',
        url: 'https://goerli.etherscan.io',
      ),
    );

    W3MChainPresets.chains.putIfAbsent('5', () => goerliTestnet);
    await _w3mService.init();
    _w3mService.selectChain(goerliTestnet);

I run the sample Web3Modal Flutter app on Samsung M23 Android phone. Explicitly using ( Connect Wallet ) button, then "All Wallets" option, and then the {+} qr code camera icon right next to the search wallet input field.

Then i take another phone, iphone 12 Pro, iOS 17.0.3 and open MetaMask v7.8.0 (1174). In MetaMask i'm using also the scan QR-code icon in the top right corner, and i scan the showed QR-code (on android) with my iphone.

Iphone MetaMask prompts me if i want to connect to this site: (www.walletconnect.com, Goerli) and i click ( Connect ). I get a small dialog verifying connection is succesful. On my Android phone i get a Title: MetaMask Wallet with a session topic: 9ecxxxxx719. Ethereum with my Account ID 0x593xxxxA5 and 4 buttons with Methods. and two Events with outlined buttons.

When i click on one of the buttons for example: eht_sendTransaction. A dialog popups-up with this info:

eth_sendTransaction
WalletConnectError( code: 5100, message: Unsupported chains, The chain eip155:1 is not supported, data: null)

close

Perhaps it has to do with MetaMask and how it handles testNets?... Because when i use the normal Ethereum chain to connect i am able to do all the Methods succesfully....