Lesson 5 deploying contract using Alchemy and Sepolia #5814
-
I have almost finished this lesson and this is the code I have: const ethers = require("ethers")
const fs = require("fs-extra")
require("dotenv").config()
async function main() {
let provider = new ethers.JsonRpcProvider(process.env.RPC_URL)
let 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()
// const contract = await contractFactory.deploy({ gasPrice: 100000000000 })
const deploymentReceipt = await contract.deploymentTransaction().wait(1)
console.log(`Contract deployed to ${contract.address}`)
let currentFavoriteNumber = await contract.retrieve()
console.log(`Current Favorite Number: ${currentFavoriteNumber}`)
console.log("Updating favorite number...")
let transactionResponse = await contract.store(7)
let transactionReceipt = await transactionResponse.wait()
currentFavoriteNumber = await contract.retrieve()
console.log(`New Favorite Number: ${currentFavoriteNumber}`)
}
main()
.then(() => process.exit(0))
.catch((error) => {
console.error(error)
process.exit(1)
})
// const transactionReceipt = await contract.deploymentTransaction().wait(1); However, I am unable to circumvent the following error and have found no solution in the github code or in the tutorial. Can someone help me fix this.
|
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 3 replies
-
try change |
Beta Was this translation helpful? Give feedback.
-
Hi aaditya I am facing the same issue, were you able to rectify it? |
Beta Was this translation helpful? Give feedback.
try change
contract.address
tocontract.target
orcontract.getAddress()
console.log(`Contract deployed to ${contract.target}`)