3

Here is the necessary part of the code, from where I keep receiving the following error:

const { Web3 } = require("web3");
const web3 = new Web3(new Web3.providers.HttpProvider('http://localhost:7545'));

TypeError: Cannot read property 'providers' of undefined Although, the node packages for Web3 are installed. How can I solve this problem?. Thanks.

2 Answers 2

3

From the example removing the {} around Web3 in the first line should do the trick

const Web3 = require("web3");
const web3 = new Web3(new Web3.providers.HttpProvider('http://localhost:7545'));
1

If you are using ethers.js:

Don't do

import ethers from "ethers" // bad

Instead do

import { ethers } from "ethers" // good

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.