TypeError: Cannot read properties of undefined (reading 'prototype'). #5294
-
When i run my "deploy.js script" and my "test-deploy.js" script. Need help in trying to figure out where did i missed Out on. I suspect it has something to do with my config file. This is my deploy.js const { ethers, run, network } = require("hardhat");
// use the "run" to run hardhat commands, example verify, rather than doing it manually on the cmd prompt.
require("dotenv").config();
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 address at: ${simpleStorage.address}`);
// we only want to RUN the verify func() only if it is on a testnet, and not if it is on Localhost hardhat/ganache testnet.
// So check if it is on the sepolia network, && if we have the etherscan API key, before we VERIFY.
if (network.config.chainId === 11155111 && process.env.ETHERSCAN_API_KEY) {
const wait_blocks = 3;
console.log(`Waiting for ${wait_blocks} block txs...`);
await simpleStorage.deployTransaction.wait(wait_blocks);
await verify(simpleStorage.address, []);
}
const currentValue = await simpleStorage.retrieve();
console.log(`Current Value is: ${currentValue}`);
//Update the current value
const transactionResponse = await simpleStorage.store(8);
await transactionResponse.wait(1);
const updatedValue = await simpleStorage.retrieve();
console.log(`updated value is: ${updatedValue}`);
}
// verify on etherscan
// since this contract does not use constructors, we can skip out the "args"
async function verify(contractAddress, args) {
console.log("verifying contract...");
try {
await run("verify:verify", {
address: contractAddress,
constructorArguments: args,
});
} catch (error) {
if (error.message.toLowerCase().includes("already verified")) {
console.log("Already Verified!");
} else {
console.log(error);
}
}
}
main()
.then(() => process.exit(0))
.catch((error) => {
console.error(error);
process.exit(1);
}); This is my hardhat.config.js require("@nomicfoundation/hardhat-toolbox");
require("dotenv").config();
require("@nomiclabs/hardhat-etherscan");
require("./tasks/block-number");
/** @type import('hardhat/config').HardhatUserConfig */
const SEPOLIA_RPC_URL = process.env.SEPOLIA_RPC_URL;
const PRIVATE_KEY = process.env.PRIVATE_KEY;
const ETHERSCAN_API_KEY = process.env.ETHERSCAN_API_KEY;
module.exports = {
defaultNetwork: "hardhat",
networks: {
sepolia: {
url: SEPOLIA_RPC_URL,
accounts: [PRIVATE_KEY],
chainId: 11155111,
},
// This localhost network is different fron the default hardhat network. (it's a separate one)
// This is the network, when u run "npx hardhat node", and when u run your script, on --network localhost, u can see the transactions.
localhost: {
url: "http://127.0.0.1:8545/",
// accoutns already auto set and given by hardhat
chainId: 31337,
},
},
solidity: "0.8.18",
etherscan: {
apiKey: ETHERSCAN_API_KEY,
},
}; my codes were working previously, but i probably misconfigured something and i can't find it. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
@Glow-in-the-dark I have never seen this error before, it looks like it came from one of the dependencies, try to remote node_modules folder, package-lock.json or yarn.lock file and reinstall dependencies. See if it works, otherwise, leave your repository link, I will test it locally. |
Beta Was this translation helpful? Give feedback.
-
Hello you could try checking your solidity version in this I see you are using version 0.8.18 in your hardhat config change it so it matches the version you are using in the contract for instance if in your contract you have pragma solidity ^0.8.7; try changing the version in your hardhat config to solidity : "0.8.7", |
Beta Was this translation helpful? Give feedback.
@Glow-in-the-dark The issue was in one of the dependencies, and it is working now; as you can see below.
Remove the node_modules folder, package-lock.json or yarn.lock file (use either npm or yarn, not both);
package.json
file;hardhat.config.js
file