5

In my project, I tried to connect with metamask on Ganache. But I got the error like the following.

inpage.js:1 MetaMask - RPC Error: Expected an array with at least one valid string HTTPS url 'rpcUrls', Received:
http://127.0.0.1:7545/
code: -32602
message: "Expected an array with at least one valid string HTTPS url 'rpcUrls', Received...

Please let me know how can fix it.

TylerH
  • 20,799
  • 66
  • 75
  • 101
tomato
  • 153
  • 2
  • 10

3 Answers3

0

I'll be assuming your code looks like the following:

await ethereum.request({
  method: 'wallet_addEthereumChain',
  params: [
    {
      chainId: '0x539',
      chainName: 'Gananche',
      rpcUrls: 'http://127.0.0.1:7545/'
    }
  ]
});

The rpcUrls value has to be an array, but from your error message it looks like you're passing a string. To fix this, make the value an array as follows:

await ethereum.request({
  method: 'wallet_addEthereumChain',
  params: [
    {
      chainId: '0x539',
      chainName: 'Gananche',
      rpcUrls: ['http://127.0.0.1:7545/'] // Is now an array
    }
  ]
});
Pandapip1
  • 730
  • 5
  • 15
0

you can install localtunnel to tunneling to local HTTPS server

npm install -g localtunnel

and after use the command line interface to request a tunnel to your local server:

lt --port 7545

An url will be created (ex: https://wise-mule-dig-195-131-122-13.loca.lt/) Open the url created and click on the button "Click to continue"

After you can used this new url instead of http://127.0.0.1:7545/

Patrikoko
  • 478
  • 5
  • 5
0

I have had the same issue and I believe that it is because of the unsafe http url, since it allowed me to pass on the same parameters changing http to https. So possibly localtunnel might work for you as Patrikoko said?

Another possibility that keeps everything local could be: https://www.npmjs.com/package/local-ssl-proxy This serves it with a self signed certificate

In the github readme is says you can serve it with your own trusted certificate as well: https://github.com/cameronhunter/local-ssl-proxy#readme

local-ssl-proxy --key localhost-key.pem --cert localhost.pem --source 9001 --target 9000