Complete the code to connect to the Ethereum mainnet using Infura.
const provider = new ethers.providers.JsonRpcProvider('[1]');
The mainnet URL is https://mainnet.infura.io/v3/YOUR-PROJECT-ID. Other URLs connect to testnets.
Complete the code to check the current block number on the Rinkeby testnet.
const provider = new ethers.providers.JsonRpcProvider('[1]'); const blockNumber = await provider.getBlockNumber();
Rinkeby testnet uses the URL https://rinkeby.infura.io/v3/YOUR-PROJECT-ID.
Fix the error in the code to connect to the Goerli testnet.
const provider = new ethers.providers.JsonRpcProvider('[1]');
The correct Goerli URL is https://goerli.infura.io/v3/YOUR-PROJECT-ID. Spelling and version must be exact.
Fill both blanks to create a dictionary mapping network names to their Infura URLs.
const networks = {
'mainnet': '[1]',
'sepolia': '[2]'
};Mainnet and Sepolia URLs are https://mainnet.infura.io/v3/YOUR-PROJECT-ID and https://sepolia.infura.io/v3/YOUR-PROJECT-ID respectively.
Fill all three blanks to filter and map testnet names with their URLs from a networks object.
const testnets = Object.entries(networks) .filter(([[1], [2]]) => [3] !== 'mainnet') .map(([name, url]) => ({ name, url }));
The entries are destructured as [name, url]. We filter out where name !== 'mainnet'.