'RPC Error - valid string HTTPs rpc in Metamask

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.



Solution 1:[1]

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
    }
  ]
});

Solution 2:[2]

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/

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Pandapip1
Solution 2 Patrikoko