Can an application retrieve what RPC URL is the user using in Metamask? Using the window.ethereum API I can recover the net_version and confirm that it is the expected one. But can I also retrieve the RPC URL in order to read the data from the same URL?


Assuming you need this to confirm that you are on the expected blockchain, and considering a blockchain is a decentralised network of nodes, not sure whether knowing the IP of the node you are connected to will tell you any relevant information.

On the other hand, the chain id will indeed tell whether you are on the mainnet (1), a public testnet (3, 4, 42...) or a local blockchain (1337, ...).

Once said that and application-wise, the IP is commonly defined at the moment of defining the provider, for instance:

const providers = [
    new Web3(new Web3.providers.HttpProvider('')),
    new Web3(new Web3.providers.HttpProvider(`https://ropsten.infura.io/v3/${infuraKey}`)),

Nevertheless, since a blockchain keeps the same global state across all nodes, there shouldn't be differences when reading data from one node or another (different IPs) within the same network.

  • Since Metamask does not inject the provider anymore, the idea is to read using the RPC URL selected by the user – Suzana Maranhão Dec 14 '20 at 22:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.