Lesson 5 node.js Error #1760
-
const ethers = require("ethers"); //const = let
const fs = require("fs-extra");
async function main() {
//http://127.0.0.1:7545
const provider = new ethers.providers.JsonRpcProvider(
"http://127.0.0.1:7545"
);
const wallet = new ethers.Wallet(
"0x430d309BD0c4a46E0Af0AEEE1D7F9E18D280Be7C",
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(); //telling to stop here, wait for the contract to deploy
console.log(contract);
}
main()
.then(() => process.exit(0))
.catch((error) => {
console.error(error);
process.exit(1);
}); While trying to connect to Ganache and run on VScode just now, I received the following error in the terminal: Error: invalid private key (argument="privateKey", value="[[ REDACTED ]]", code=INVALID_ARGUMENT, version=signing-key/5.6.2)
at Module._compile (node:internal/modules/cjs/loader:1105:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1159:10)
at Module.load (node:internal/modules/cjs/loader:981:32) {
reason: 'invalid private key',
code: 'INVALID_ARGUMENT',
argument: 'privateKey',
value: '[[ REDACTED ]]' I checked my code but didn't seem to have saw anything wrong. Can anyone tell me how to solve this problem? I'm using the Mac BigSur system |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 9 replies
-
Did you add an address or a private key when connecting to the wallet? |
Beta Was this translation helpful? Give feedback.
-
Try this—the green one—and let me know: -const contract = await contractFactory.deploy(); //telling to stop here, wait for the contract to deploy
-console.log(contract);
+const contract = await contractFactory.deploy(); //telling to stop here, wait for the contract to deploy
+await contract.deployed();
+console.log(contract); |
Beta Was this translation helpful? Give feedback.
-
Here: const wallet = new ethers.Wallet(
"0x430d309BD0c4a46E0Af0AEEE1D7F9E18D280Be7C",
provider
); You have added public key and NOT private key const wallet = new ethers.Wallet(
"<add private key here>",
provider
); |
Beta Was this translation helpful? Give feedback.
Did you add an address or a private key when connecting to the wallet?