TypeError: ethers.contractFactory is not a constructor #4730
-
Hello everyone. I am getting the following error when I try to run the "node deploy.js": Here is the code for the deploy.js file: const ethers = require("ethers");
const fs = require("fs-extra");
async function main() {
const provider = new ethers.providers.JsonRpcProvider(
"http://127.0.0.1:7545"
);
const wallet = new ethers.Wallet(
"1574b17f91f95a4ff581d10e3f0c32b17bce44d6eb7b448d13ccce875850f622",
provider
);
const abi = fs.readFileSync("./SimpleStorage_sol_SimpleStorage.abi", "utf8");
const binary = fs.readFileSync(
"./SimpleStorage_sol_SimpleStorage.bin",
"utf8"
);
const contractFactory = new ethers.contractFactory(abi, binary, wallet);
console.log("Deploying, please wait...");
const contract = await contractFactory.deploy();
console.log(contract);
}
main()
.then(() => process.exit(0))
.catch((error) => {
console.error(error);
process.exit(1);
}); And here is my package.json: {
"dependencies": {
"ethers": "5.6.2",
"fs-extra": "^11.1.0",
"solc": "0.8.7-fixed"
},
"scripts": {
"compile": "yarn solcjs --bin --abi --include-path node_modules/ --base-path . -o . SimpleStorage.sol"
}
} Also, I don't know if that's important but when I run the "yarn compile", even though my ABI and BIN are getting compiled, I can getting the following warning:
|
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
i just noticed a small mistake in your code, instead of this ( new ethers.contractFactory() ); use capital C, so your updated code should looks like: new ethers.ContractFactory() |
Beta Was this translation helpful? Give feedback.
-
and if you want no need to install fs-extra module, go with node built in "fs" module so you can grab fs like: const fs = require("fs"); rest stay same |
Beta Was this translation helpful? Give feedback.
i just noticed a small mistake in your code,
instead of this ( new ethers.contractFactory() );
use capital C, so your updated code should looks like:
new ethers.ContractFactory()