So i currently learn to become web3 developer. so i follow tutorial from yt and i got stuck. I try to run Deploy.js using command PRIVATE_KEY_PASSWORD = password node Deploy.js. i am using windows 10. And i got this error
PRIVATE_KEY_PASSWORD : The term 'PRIVATE_KEY_PASSWORD' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the
spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:1
+ PRIVATE_KEY_PASSWORD = password node Deploy.js
+ ~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (PRIVATE_KEY_PASSWORD:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
this is my Deploy.js code
const ethers = require('ethers');
const fs = require("fs-extra");
const translate = require("solc/translate");
require('dotenv').config();
async function main() {
// http://127.0.0.1:7545
const provider = new ethers.providers.JsonRpcProvider(process.env.RPC_URL);
// const wallet = new ethers.Wallet(process.env.PRIVATE_KEY,provider);
const encryptedJson = fs.readFileSync("./.encryptedKey.json", "utf8");
let wallet = new ethers.Wallet.fromEncryptedJsonSync(encryptedJson, process.env.PRIVATE_KEY_PASSWORD);
wallet = await wallet.connect(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();
await contract.deployTransaction.wait(1);
// Getting number from SimpleStorage contract
const currentFavoriteNumber = await contract.retrieve();
console.log(`Current Favorite Number: ${currentFavoriteNumber.toString()}`);
const transactionResponse = await contract.store("7");
const transactionReceipt = await transactionResponse.wait(1);
const updatedFavoriteNumber = await contract.retrieve();
console.log(`Updated transaction number is: ${updatedFavoriteNumber}`);
// console.log("Let's deploy with only transaction data!");
// const nonce = await wallet getTransactionCcount();
// const tx = {
// nonce: nonce,
// gasPrice: 20000000000,
// gasLimit: 100000,
// to: null,
// value: 0,
// data: "0x60"(I delete some of it since i think its not relevant aka commented)
// chainId: 1337,
// };
// const sentTxResponse = await wallet.sendTransaction(tx);
// await sentTxResponse.wait(1);
// console.log(sentTxResponse);
}
main()
.then(() => process.exit(0))
.catch((error) => {
console.error(error);
process.exit(1);
});
I think there is no problem with encryptedKey.json. But if that code is needed i will post it too. thanks for your help guys