Metamask Mobile cannot connect to private EVM chain #5210

I posted this issue to the MetaMask Mobile github, but perhaps the community here will be able to provide some insight.

Describe the bug
I have a Expanse Node running on my desktop computer. The node listens on the machines local I-Pv4 Address 192.168.1.2:8545 Chain ID 1998 (“0x7ce”) I can add the local RPC through the non-localhost endpoint in the browser extension just fine as you see in the picture, and MetaMask Mobile plays nice with Expanse’s mainnet RPC which runs the same node version I am using for my test net.

So when I launched my local private test net I got on my phone which is connected to the same network @192.168.1.5
In the node flags and enter:

Expanse Test Net

http192.168.1.2:8545

0x7ce

-blank-

It claims that it cannot fetch the Chain ID.

This lead me to believe possibly my phone cannot access the JSON RPC endpoint, so, I opened up a http1.1 request app on my phone and requested the Chain ID from the node successfully using the same endpoint entered in MetaMask Mobile, and was able to see the inbound connections in the logs of my node from doing so. This proves that my node will reply proper requests from the device that is acting like it cannot connect.

However if I try to connect to this endpoint in MetaMask Mobile I get the error cannot fetch chain id. Now because the chain ID is 0x7ce (1998) I then decided to try it in hex as when I made the http request from the app it returned a chain ID of “0x7ce” which is expected. The problem still persists.

Ultimately when I checked my node logs after spamming a few Add RPC button clicks… The node never received the requests as there aren’t any logged.

Here is what my node outputs into logs upon starting:

DEBUG[11-07|11:17:26.296] Sanitizing Go’s GC trigger percent=50
INFO [11-07|11:17:26.298] Maximum peer count ETH=0 LES=0 total=0
DEBUG[11-07|11:17:26.298] FS scan times list=0s set=0s diff=0s
TRACE[11-07|11:17:26.298] Handled keystore changes time=0s
INFO [11-07|11:17:26.343] Starting peer-to-peer node instance=Gexp/v1.9.10-stable-d57c0cd6/windows-amd64/go1.13.6
INFO [11-07|11:17:26.343] Allocated trie memory caches clean=512.00MiB dirty=512.00MiB
INFO [11-07|11:17:26.343] Allocated cache and file handles database=P:\Expanse-Test-Net-Datadir\gexp\chaindata cache=1024.00MiB handles=8192
DEBUG[11-07|11:17:26.654] Chain freezer table opened database=P:\Expanse-Test-Net-Datadir\gexp\chaindata\ancient table=receipts items=0 size=0.00B
DEBUG[11-07|11:17:26.677] Chain freezer table opened database=P:\Expanse-Test-Net-Datadir\gexp\chaindata\ancient table=diffs items=0 size=0.00B
DEBUG[11-07|11:17:26.679] Chain freezer table opened database=P:\Expanse-Test-Net-Datadir\gexp\chaindata\ancient table=headers items=0 size=0.00B
DEBUG[11-07|11:17:26.689] Chain freezer table opened database=P:\Expanse-Test-Net-Datadir\gexp\chaindata\ancient table=hashes items=0 size=0.00B
DEBUG[11-07|11:17:26.691] Chain freezer table opened database=P:\Expanse-Test-Net-Datadir\gexp\chaindata\ancient table=bodies items=0 size=0.00B
INFO [11-07|11:17:26.691] Opened ancient database database=P:\Expanse-Test-Net-Datadir\gexp\chaindata\ancient
DEBUG[11-07|11:17:26.691] Current full block not old enough number=0 hash=727fd5…92ae81 delay=90000
INFO [11-07|11:17:26.692] Initialised chain configuration config=“{ChainID: 1998 Homestead: 0 DAO: DAOSupport: false EIP150: 0 EIP155: 0 EIP158: 0 Byzantium: 0 Constantinople: 0 Petersburg: 0 Istanbul: 0, Muir Glacier: , Engine: unknown, PirlGuard: 0}”
INFO [11-07|11:17:26.692] Disk storage enabled for ethash caches dir=P:\Expanse-Test-Net-Datadir\gexp\ethash count=3
INFO [11-07|11:17:26.692] Disk storage enabled for ethash DAGs dir=C:\Users\Keith\AppData\Local\Ethash count=2
INFO [11-07|11:17:26.692] Initialising Expanse protocol versions=“[64 63]” network=1998 dbversion=7
INFO [11-07|11:17:26.692] Loaded most recent local header number=5 hash=061fd5…2d73cf td=788995 age=37m25s
INFO [11-07|11:17:26.692] Loaded most recent local full block number=0 hash=727fd5…92ae81 td=131072 age=53y7mo1w
INFO [11-07|11:17:26.692] Loaded most recent local fast block number=5 hash=061fd5…2d73cf td=788995 age=37m25s
DEBUG[11-07|11:17:26.692] Reinjecting stale transactions count=0
INFO [11-07|11:17:26.692] Loaded local transaction journal transactions=0 dropped=0
INFO [11-07|11:17:26.693] Regenerated local transaction journal transactions=0 accounts=0
WARN [11-07|11:17:26.693] Switch sync mode from full sync to fast sync
INFO [11-07|11:17:26.702] Allocated fast sync bloom size=1024.00MiB
INFO [11-07|11:17:26.702] Initialized fast sync bloom items=0 errorrate=0.000 elapsed=0s
DEBUG[11-07|11:17:26.703] Recalculated downloader QoS values rtt=20s confidence=1.000 ttl=1m0s
DEBUG[11-07|11:17:26.864] TCP listener up addr=[::]:42786
DEBUG[11-07|11:17:26.864] InProc registered namespace=admin
DEBUG[11-07|11:17:26.864] InProc registered namespace=admin
DEBUG[11-07|11:17:26.864] InProc registered namespace=debug
DEBUG[11-07|11:17:26.864] InProc registered namespace=web3
DEBUG[11-07|11:17:26.864] InProc registered namespace=eth
DEBUG[11-07|11:17:26.864] InProc registered namespace=eth
INFO [11-07|11:17:26.864] New local node record seq=20 id=ee1bd34bf1a7a4b2 ip=127.0.0.1 udp=0 tcp=42786
DEBUG[11-07|11:17:26.864] InProc registered namespace=eth
INFO [11-07|11:17:26.864] Started P2P networking self=“enode://de1c6014835f9f213ad27a3e489263a381f36c762262448876b6b7598678f6f6f59a40a5f0e80701a929ca3f7c42a376d5ef87d5e5b772678edf6a7b6a1dfa06@127.0.0.1:42786?discport=0”
DEBUG[11-07|11:17:26.865] InProc registered namespace=txpool
DEBUG[11-07|11:17:26.865] InProc registered namespace=debug
DEBUG[11-07|11:17:26.865] InProc registered namespace=debug
DEBUG[11-07|11:17:26.865] InProc registered namespace=eth
DEBUG[11-07|11:17:26.865] InProc registered namespace=personal
DEBUG[11-07|11:17:26.865] InProc registered namespace=eth
DEBUG[11-07|11:17:26.865] InProc registered namespace=ethash
DEBUG[11-07|11:17:26.865] InProc registered namespace=eth
DEBUG[11-07|11:17:26.865] InProc registered namespace=eth
DEBUG[11-07|11:17:26.865] InProc registered namespace=eth
DEBUG[11-07|11:17:26.865] InProc registered namespace=miner
DEBUG[11-07|11:17:26.865] InProc registered namespace=eth
DEBUG[11-07|11:17:26.865] InProc registered namespace=admin
DEBUG[11-07|11:17:26.865] InProc registered namespace=debug
DEBUG[11-07|11:17:26.865] InProc registered namespace=debug
DEBUG[11-07|11:17:26.865] InProc registered namespace=net
DEBUG[11-07|11:17:26.865] InProc registered namespace=exp
DEBUG[11-07|11:17:26.865] InProc registered namespace=exp
DEBUG[11-07|11:17:26.865] InProc registered namespace=exp
DEBUG[11-07|11:17:26.865] InProc registered namespace=exp
DEBUG[11-07|11:17:26.865] IPC registered namespace=admin
DEBUG[11-07|11:17:26.865] IPC registered namespace=admin
DEBUG[11-07|11:17:26.865] IPC registered namespace=debug
DEBUG[11-07|11:17:26.865] IPC registered namespace=web3
DEBUG[11-07|11:17:26.865] IPC registered namespace=eth
DEBUG[11-07|11:17:26.865] IPC registered namespace=eth
DEBUG[11-07|11:17:26.865] IPC registered namespace=eth
DEBUG[11-07|11:17:26.865] IPC registered namespace=txpool
DEBUG[11-07|11:17:26.865] IPC registered namespace=debug
DEBUG[11-07|11:17:26.865] IPC registered namespace=debug
DEBUG[11-07|11:17:26.865] IPC registered namespace=eth
DEBUG[11-07|11:17:26.865] IPC registered namespace=personal
DEBUG[11-07|11:17:26.865] IPC registered namespace=eth
DEBUG[11-07|11:17:26.865] IPC registered namespace=ethash
DEBUG[11-07|11:17:26.865] IPC registered namespace=eth
DEBUG[11-07|11:17:26.865] IPC registered namespace=eth
DEBUG[11-07|11:17:26.865] IPC registered namespace=eth
DEBUG[11-07|11:17:26.865] IPC registered namespace=miner
DEBUG[11-07|11:17:26.865] IPC registered namespace=eth
DEBUG[11-07|11:17:26.865] IPC registered namespace=admin
DEBUG[11-07|11:17:26.865] IPC registered namespace=debug
DEBUG[11-07|11:17:26.865] IPC registered namespace=debug
DEBUG[11-07|11:17:26.865] IPC registered namespace=net
DEBUG[11-07|11:17:26.865] IPC registered namespace=exp
DEBUG[11-07|11:17:26.865] IPC registered namespace=exp
DEBUG[11-07|11:17:26.865] IPC registered namespace=exp
DEBUG[11-07|11:17:26.866] IPC registered namespace=exp
INFO [11-07|11:17:26.866] IPC endpoint opened url=\.\pipe\gexp.ipc
DEBUG[11-07|11:17:26.866] HTTP registered namespace=debug
DEBUG[11-07|11:17:26.866] HTTP registered namespace=web3
DEBUG[11-07|11:17:26.866] HTTP registered namespace=eth
DEBUG[11-07|11:17:26.866] HTTP registered namespace=eth
DEBUG[11-07|11:17:26.866] HTTP registered namespace=eth
DEBUG[11-07|11:17:26.866] HTTP registered namespace=debug
DEBUG[11-07|11:17:26.866] HTTP registered namespace=debug
DEBUG[11-07|11:17:26.866] HTTP registered namespace=eth
DEBUG[11-07|11:17:26.866] HTTP registered namespace=personal
DEBUG[11-07|11:17:26.866] HTTP registered namespace=eth
DEBUG[11-07|11:17:26.866] HTTP registered namespace=eth
DEBUG[11-07|11:17:26.866] HTTP registered namespace=eth
DEBUG[11-07|11:17:26.866] HTTP registered namespace=eth
DEBUG[11-07|11:17:26.866] HTTP registered namespace=eth
DEBUG[11-07|11:17:26.866] HTTP registered namespace=debug
DEBUG[11-07|11:17:26.866] HTTP registered namespace=debug
DEBUG[11-07|11:17:26.866] HTTP registered namespace=net
INFO [11-07|11:17:26.866] HTTP endpoint opened url=http192.168.1.2:8545 cors=* vhosts=*
TRACE[11-07|11:17:27.243] Accepted RPC connection conn=\.\pipe\gexp.ipc
DEBUG[11-07|11:17:27.245] Served eth_syncing reqid=8393419984563830 t=0s
DEBUG[11-07|11:17:28.243] Served eth_syncing reqid=8393419984563831 t=0s
DEBUG[11-07|11:17:28.964] Couldn’t add port mapping proto=tcp extport=42786 intport=42786 interface=“UPnP or NAT-PMP” err=“no UPnP or NAT-PMP router discovered”

To Reproduce
Steps to reproduce the behavior

  1. Launch GEXP 1.9.10 with following flags
    [ '--ipcpath ' + "gexp.ipc", '--allow-insecure-unlock', '--syncmode full', '--verbosity 5', '--cache=1048', '--datadir '+ Datadir, '--maxpeers 0','--rpc', '--rpcapi web3,eth,debug,personal,net',"--rpccorsdomain='*'",'--rpcaddr "192.168.1.2"',"--rpcvhosts='*'", '--rpcport 8545', '--networkid 1998', '--nodiscover','--miner.threads 1','--miner.etherbase 0xb670bb2c3f4929125334908a54d3d9e4fc47a4db','2>testnet-log.log']
  2. Replace --rpcaddr with your machine’s I-Pv4 address the node is running on.
  3. Open MetaMask Mobile
  4. Add Custom RPC:
    Expanse Test Net <— name

http192.168.1.2:8545<— endpoint (replace with the same address you put in --rpcaddr flag

0x7ce <---- lowercase hex of chain Id (The error happens if 1998 or hex version)

  1. Get could not fetch Chain ID error.

Expected behavior
I expect that I should be able to connect to my private test net with MetaMask Mobile as long as my phone is connected to the same network as the private test net

Smartphone (please complete the following information):

  • Device: Samsung S22 Ultra
  • OS: Android
  • App Version v5.9.0
1 Like

It’s worth noting that I took out the :// of the http links and stuff so nothing would be an actual link, but trust this is displayed and entered correctly. The github issue has a more wholesome explanation.

Providing the link here:

4 Likes

This issue is caused by:
react_native_config.xml and the android manifest XML file.

Basically MetaMask mobile doesn’t allow non-HTTPS RPCs to be added as custom networks.

This is just caused by not supporting a developer mode fully.

To get around this I just decoded the APK and made the respective changes, rebuilt and signed with a dummy keystore, installed on my phone… Now everything’s fine!

The main repo team can figure out how they want to approach this or I would just post my Android project to be rebuilt in Android studio, but that would sadly violate the license.

If you check all of this, I’m sure you will find the issue. It’s not MetaMask, it’s very likely your settings.
Especially because all we have for errors to read are can’t fetch Chain Id and not even the full url of the RPC in case there actually is something wrong with your URL.

Open up an stdout log of your node and get the IPV4 of your device, enable any kind of verbose logging feature on the node if you can. Turn on Developer Mode in Chrome Extensions and read the Background.html file of the MetaMask extension. In the inspector click ‘Network’. and watch for incoming HTTPS requests and how they are handled and fix errors accordingly If you are Adding the Network by clicking the button it should generate a request and return properly, otherwise you will see bright red descriptive errors. SSL is picky and so are the Apps that support it. If you don’t see any requests coming from MetaMask you will see console.log errors from the MetaMask extension as HTTPS or your URL is not correct, and the logs will tell you why!

Additionally here are some other things to try:

Type the Chain Id in as a 0x prefix hex code.

Ensure that the SSL CA Certificate is inside the Root Trusted Certificate Authority(CA) in chrome.

If these are self-signed certificates, you must add them to your browser’s list of certificates in the Trusted Root CA

Do not use the self-signed CA Certificate these for production(release) builds as it would make HTTPS redundant.

Ensure that your node HAS SSL capability and do your due-diligence on what most browsers expect the version of SSL to be.

Personally I believe it would be easier if you just used HTTP for development and then enabled SSL with a reverse proxy that has the SSL capability. If these are all truly private chains then there’s no point in using SSL anyway though.

There could be something wrong with the common name of your domain of your respective SSL .ext file.

You must add subdomains to the common name and the IP address of the address your Node is listening on.

It’s extremely picky if you’re writing your own certificates just to have HTTPS in development unless you get it done by a widely Trusted Browser Certificate Authority.

So if you’re passing HTTPS to MetaMask, it HAS to be pristinely done for it to work.

Since you are using a private chain, per MetaMask’s HTTPS policy listed in _react_native_config.xml and even the android manifest XML file. MetaMask’s policies therefore will accept your RPC as cleartext HTTP:// url since it is on the localhost and you’re using MetaMask Desktop in-browser on the node machine.

This may be good notes to add to Metamask's documentation.

1 Like

Thanks for sharing the solution, and glad you found a work around! :slight_smile:

2 Likes

Thanks, Crypto is about community and us web3 devs have to talk if this space is going to get taken seriously and gain adoption. :slight_smile:

3 Likes

A post was split to a new topic: Mobile wallet not syncing with desktop

This topic was automatically closed after 30 days. New replies are no longer allowed.