0

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

0

1 Answer 1

0

Make sure you have .env file, and declare PRIVATE_KEY_PASSWORD inside the file.

.env

PRIVATE_KEY_PASSWORD="YourPrivateKeyPassword"
3
  • yes according to the video that i follow the private_key_password need to be deleted since we dont want another person to look into our private key and the password to open the private key. I try with the private_key_password deleted and with private_key_password exist on the code but still encounter the same error
    – Crigs
    Commented Feb 3, 2023 at 10:02
  • make sure you have run source .env in terminal.
    – John Joe
    Commented Feb 4, 2023 at 4:21
  • Thanks for your help i will try it. But for now i just skip it and go on with the course
    – Crigs
    Commented Feb 8, 2023 at 12:56

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.