RootSoft / walletconnect-dart-sdk

Open protocol for connecting dApps to mobile wallets with QR code scanning or deep linking.
MIT License
102 stars 61 forks source link

I just want to know how to switch the network in MetaMask mobile using code #105

Open Asadu43 opened 1 year ago

Asadu43 commented 1 year ago

I just want to know how to switch the network in MetaMask mobile using code

wufd commented 1 year ago

You can try "wallet_switchEthereumChain" or "wallet_addEthereumChain"

Asadu43 commented 1 year ago

You can try "wallet_switchEthereumChain" or "wallet_addEthereumChain"

Can you please Give me any example how can i use this?

wufd commented 1 year ago
await connector.sendCustomRequest(
        method: 'wallet_switchEthereumChain',
        params: [
          {'chainId': '0x${chainId.toRadixString(16)}'}
        ],
      )

or

await connector.sendCustomRequest(
        method: 'wallet_addEthereumChain',
        params: [
          {
            'chainId': '0x${chainId.toRadixString(16)}',
            'chainName': "xxx",
            'nativeCurrency': {
                      "name": "xxx",
                      "symbol": "xxx",
                      "decimals": xxx
            },
            'rpcUrls': [url,xxx],
            'blockExplorerUrls': [url,xxx]
          }
        ],
      )

chain_info: https://chainid.network/chains.json