I use Metamask. Until now I used the goerli testnet network for my development project. I use ethers.js
also in my project. Now how can I implement a test for knowing the network if it is goerli or the main network Ethereum ? Here is my code, but I dont see any clue for my needs :
const { ethers } = require("ethers");
async function main() {
const provider = new ethers.providers.InfuraProvider();
let ntwrk = await provider.getNetwork();
console.log("============= selected network =", ntwrk);
}
main();
At runtime the console log shows :
{
name: 'homestead',
chainId: 1,
ensAddress: '0x....',
_defaultProvider: [Function: func] { renetwork: [Function (anonymous)] }
}
When I change the network then the name is always 'homestead', and the chainId is always 1
edit :
full code
const { ethers } = require("ethers");
async function main() {
// Configuring the connection to an Ethereum node
const provider = new ethers.providers.InfuraProvider(
);
let ntwrk = await provider.getNetwork();
console.log("============= selected network =", ntwrk);
}
main();