'Adding a custom network to MetaMask with http address isn't working using wallet_addEthereumChain
I am creating a button that adds a custom network to MetaMask. The issue is the geth node has an http address not a https. When I run the code to add with wallet_addEthereumChain I get an error saying it expects an https address. Is there a way around this.
const formattedChainId = hexStripZeros(BigNumber.from(chainId).toHexString());
try {
await window.ethereum.request({
method: "wallet_addEthereumChain",
params: [
{
chainId: formattedChainId,
chainName: "CU Internal",
rpcUrls: ["http://myAddress"],
nativeCurrency: {
name: "ETH",
symbol: "ETH",
decimals: 18,
},
blockExplorerUrls: null,
},
],
});
} catch (error) {
console.error("error adding eth network: ");
}
}
This is the call I'm making
Solution 1:[1]
Same problem here, rpcUrls MUST be https, Metamask makes this check.
const firstValidRPCUrl = Array.isArray(rpcUrls)
? rpcUrls.find((rpcUrl) => validUrl.isHttpsUri(rpcUrl))
: null;
but specification is
All URL strings MUST include the protocol component of the URL. HTTPS SHOULD always be used over HTTP.
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 | Gianni Unz |
