0

**I am going through freecodecamp's course on fullstack web3 development. Can anyone help me with this error. Am not able to resolve this issueenter image description here. **

Deploy.js code : 
// imports
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?
  if (network.config.chainId === 11155111 && process.env.ETHERSCAN_API_KEY) {
    console.log("Waiting for block confirmations...");
    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}`);
}

const verify = async (contractAddress, args) => {
  console.log("Verifying contract...");
  try {
    await run("verify:verify", {
      address: contractAddress,
      constructorArguments: args,
    });
  } catch (e) {
    if (e.message.toLowerCase().includes("already verified")) {
      console.log("Already Verified!");
    } else {
      console.log(e);
    }
  }
};

// main
main()
  .then(() => process.exit(0))
  .catch((error) => {
    console.error(error);
    process.exit(1);
  });

hardhat.config.js code:

require('@nomicfoundation/hardhat-toolbox')
require('dotenv').config()
require('hardhat-gas-reporter')
require('solidity-coverage')

const COINMARKETCAP_API_KEY = process.env.COINMARKETCAP_API_KEY || ''
const SEPOLIA_RPC_URL =
  process.env.SEPOLIA_RPC_URL ||
  'https://eth-sepolia.g.alchemy.com/v2/your-api-key'
const PRIVATE_KEY =
  process.env.PRIVATE_KEY ||
  '0x11ee3108a03081fe260ecdc106554d09d9d1209bcafd46942b10e02943effc4a'
const ETHERSCAN_API_KEY = process.env.ETHERSCAN_API_KEY || ''

module.exports = {
  defaultNetwork: 'hardhat',
  networks: {
    hardhat: {},
    sepolia: {
      url: SEPOLIA_RPC_URL,
      accounts: [PRIVATE_KEY],
      chainId: 11155111,
    },
    localhost: {
      url: 'http://localhost:8545',
      chainId: 31337,
    },
  },
  solidity: '0.8.19',
  etherscan: {
    apiKey: ETHERSCAN_API_KEY,
  },
  gasReporter: {
    enabled: true,
    currency: 'USD',
    outputFile: 'gas-report.txt',
    noColors: true,
    coinmarketcap: COINMARKETCAP_API_KEY,
  },
}
package.json : 
```dart
  
{
  "name": "hardhat_simple_storage",
  "version": "1.0.0",
  "license": "MIT",
  "devDependencies": {
    "@ethersproject/abi": "^5.7.0",
    "@ethersproject/providers": "^5.7.2",
    "@nomicfoundation/hardhat-chai-matchers": "^1.0.5",
    "@nomicfoundation/hardhat-network-helpers": "^1.0.7",
    "@nomicfoundation/hardhat-toolbox": "^2.0.0",
    "@nomiclabs/hardhat-ethers": "^2.2.1",
    "@nomiclabs/hardhat-etherscan": "^3.1.3",
    "@typechain/ethers-v5": "^10.1.1",
    "@typechain/hardhat": "^6.1.4",
    "chai": "^4.3.7",
    "dotenv": "^16.0.3",
    "ethers": "^5.7.2",
    "hardhat": "^2.12.3",
    "hardhat-deploy": "^0.11.22",
    "hardhat-gas-reporter": "^1.0.9",
    "solidity-coverage": "^0.8.2",
    "typechain": "^8.1.1"
  },
  "dependencies": {
    "@types/mocha": "^10.0.1",
    "ts-node": "^10.9.1",
    "typescript": "^4.9.4"
  }
}

package.json:

{
  "name": "hardhat_simple_storage",
  "version": "1.0.0",
  "license": "MIT",
  "devDependencies": {
    "@ethersproject/abi": "^5.7.0",
    "@ethersproject/providers": "^5.7.2",
    "@nomicfoundation/hardhat-chai-matchers": "^1.0.5",
    "@nomicfoundation/hardhat-network-helpers": "^1.0.7",
    "@nomicfoundation/hardhat-toolbox": "^2.0.0",
    "@nomiclabs/hardhat-ethers": "^2.2.1",
    "@nomiclabs/hardhat-etherscan": "^3.1.3",
    "@typechain/ethers-v5": "^10.1.1",
    "@typechain/hardhat": "^6.1.4",
    "chai": "^4.3.7",
    "dotenv": "^16.0.3",
    "ethers": "^5.7.2",
    "hardhat": "^2.12.3",
    "hardhat-deploy": "^0.11.22",
    "hardhat-gas-reporter": "^1.0.9",
    "solidity-coverage": "^0.8.2",
    "typechain": "^8.1.1"
  },
  "dependencies": {
    "@types/mocha": "^10.0.1",
    "ts-node": "^10.9.1",
    "typescript": "^4.9.4"
  }
}

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.