private key showing in the terninal when entering node deploy.js #909
-
Hi, I am new to coding and following tutorial (time line in video: 8.03.27), I am in simple stotage.sol and deploying a contract I see in the terminal when we give node deploy.js it should say Deploying please wait, but instead it first show my private key in the terminal (it supposed to not show my private key in the terminal right) then saying Deploying please wait, I might missed something in the code but I could not figure it out, can someone help me here. code below: const ethers = require("ethers")
const fs = require("fs-extra")
require("dotenv").config()
async function main() {
console.log(process.env.PRIVATE_KEY)
const provider = new ethers.providers.JsonRpcProvider(process.env.RPC_URL)
const wallet = new ethers.Wallet(process.env.PRIVATE_KEY, 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)
console.log(`Contract Addresss: ${contract.address}`)
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 favorite number is: ${updatedFavoriteNumber}`)
}
main()
.then(() => process.exit(0))
.catch((error) => {
console.error(error)
process.exit(1)
}) $ node deploy.js
Deploying, Please wait...
Contract Addresss: 0x93B086780665aF46aE82eBC502734EB23b9796af
Current Favorite Number: 0
Updated favorite number is: 7 |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 7 replies
-
@Sugunaramkumar Sorry could not understand your problem? |
Beta Was this translation helpful? Give feedback.
-
What is the problem here? If you are confused with that address being your private key - it is not, it is the contract's address. Please clarify your problem if this is not the issue. EDIT: Someone pointed this out below: the problem is in the first line after declaring the |
Beta Was this translation helpful? Give feedback.
-
Remove that console.log |
Beta Was this translation helpful? Give feedback.
You are console logging your private key!
Remove that console.log