1

I wanna to check current rpc network is using Flashbot or Infura.

I know can using window.ethereum.networkVersion to get ChainID to check it is Mainnet or Goerli.

But I do not know how to check current rpc network is using Flashbot or Infura.

3 Answers 3

0

Not sure nor can check now but you can have the url of the rpc in some window.ethereumproperties.

0

Try this one:

provider.getNetwork()

It will return the following (as example):

{
    "name": "bnb",
    "chainId": 56,
    "ensAddress": null,
    "_defaultProvider": null
}
1
  • Thanks, I tried web3.currentProvider.getNetwork() but not work, it return me: web3.currentProvider.getNetwork is not a function
    – Moon soon
    Commented Feb 16, 2023 at 0:16
0

For those looking for an up-to-date answer (April 2024):

You should be using chain ids rather than network ids. More on that on this post by Pedro Gomes (WalletConnect's founder).

To get the chain id with web3.js 4.x, you should use web3.eth.getChainId() instead, and map that to the network name yourself:

const SUPPORTED_CHAINS_NAMES: Record<number, string> = {
  1: 'Ethereum  Mainnet',
  11155111: 'Sepolia',
};

const chainId = Number(await web3.eth.getChainId());
const chainName = SUPPORTED_CHAINS_NAMES[chainId] || 'Unsupported Chain';

Or use a library like eth-chains to get up-to-date chain information, instead of manually mapping the chain id:

const chainId = Number(await web3.eth.getChainId());
const chainInfo = chains.getById(chainId) || null;
const chainName = chainInfo?.name || 'Unsupported Chain';

Also, see web3.js' migration guide.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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