Lesson 6 TypeError: simpleStorage.retrieve is not a function #5544
-
I followed along until lesson 6 at 9:08:50 of the video. When I tried to run "yarn hardhat run scripts/deploy.js" command, my code worked until the simpleStorage.retrieve line (21) then I got "TypeError: simpleStorage.retrieve is not a function" error. const { ethers, run, network } = require("hardhat")
//async main
async function main() {
const SimpleStorageFactory = await ethers.getContractFactory(
"SimpleStorage"
)
console.log("Deploying contract . . . ")
const simpleStorage = await SimpleStorageFactory.deploy()
await simpleStorage.deployed()
console.log(`Deployed contract to: ${simpleStorage.address}`)
// what happens when we deploy to our hardhat network?
// 11155111 is sepolia testnet chainId
if (network.config.chainId === 11155111 && process.env.ETHERSCAN_API_KEY) {
await simpleStorage.deployTransaction.wait(6)
await verify(simpleStorage.address, [])
}
const currentValue = await simpleStorage.retrieve()
console.log(`Current Value is: ${currentValue}`)
// Update the current value
const transactionResponse = await simpleStorage.store(7)
await transactionResponse.wait(1)
const updatedValue = await simpleStorage.retrieve()
console.log(`Updated Value is: ${updatedValue}`)
}
async function verify(contractAddress, args) {
console.log("Verifying contract . . . ")
try {
await run("verify:verify", {
address: contractAddress,
constructorArguments: args,
})
} catch (err) {
if (err.massge.toLowerCase().includes("already verified")) {
console.log("Already Verified!")
} else {
console.log(`verify() error: ${err}`)
}
}
}
main()
.then(() => process.exit(0))
.catch((err) => {
console.error(err)
process.exit(1)
}) and require("@nomicfoundation/hardhat-toolbox")
require("dotenv").config()
require("@nomiclabs/hardhat-etherscan")
/** @type import('hardhat/config').HardhatUserConfig */
const SEPOLIA_RPC_URL = process.env.SEPOLIA_RPC_URL
// const SEPOLIA_RPC_URL_KEY = process.env.SEPOLIA_RPC_URL_KEY
const PRIVATE_KEY = process.env.PRIVATE_KEY
const ETHERSCAN_APT_KEY = process.env.ETHERSCAN_APT_KEY
module.exports = {
defaultNetwork: "hardhat",
networks: {
sepolia: {
url: SEPOLIA_RPC_URL,
accounts: [PRIVATE_KEY],
chainId: 11155111,
},
},
solidity: "0.8.9",
etherscan: {
// Your API key for Etherscan
// Obtain one at https://etherscan.io/
apiKey: ETHERSCAN_APT_KEY,
},
} what did I missed |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 3 replies
-
@toppyc4 can you provide link of your repo ? i will check |
Beta Was this translation helpful? Give feedback.
-
@toppyc4 The program is not able to recognize the |
Beta Was this translation helpful? Give feedback.
-
@toppyc4 i checked your code you don't have retrieve function first you need to create one then you can call that function . |
Beta Was this translation helpful? Give feedback.
@toppyc4 The program is not able to recognize the
retrieve
function. Please check the spelling, is it same as the one defined in the contract.