const ethers = require("ethers");
const provider = new ethers.providers.JsonRpcProvider('https://mainnet.infura.io/v3/MYKEYISHERE')
web3.eth.getBlockNumber().then(console.log)
Error:
const provider = new ethers.providers.JsonRpcProvider(`https://mainnet.infura.io/v3/MYKEYISHERE`)
^
TypeError: Cannot read properties of undefined (reading 'JsonRpcProvider')
Best Answer
Look at this post.
EthersJS Listening to events with NodeJS Strange Errors
Had the same problem few days ago, turned out to be problem with a beta release of ethers.js.
The fix for me was to downgrade
"ethers"
to version5.4
in theconfig.json
, then remove node_modules folder and lastlynpm install
to install ethers again.