NomicFoundation / hardhat

Hardhat is a development environment to compile, deploy, test, and debug your Ethereum software.
https://hardhat.org
Other
7.18k stars 1.38k forks source link

Unable to fork sepolia testnet #5554

Closed Abhishekkochar closed 4 days ago

Abhishekkochar commented 1 month ago

I'm trying to fork the sepolia testnet using alchemy.

Following is the hardhat.config.ts file:

require("dotenv").config();
require("hardhat-contract-sizer");

import chalk from "chalk";
import { HardhatUserConfig } from "hardhat/config";
import { privateKeys } from "./utils/wallets";

import "@nomiclabs/hardhat-ethers";
import "@nomiclabs/hardhat-waffle";
import "@typechain/hardhat";
import "solidity-coverage";
import "./tasks";

const forkingConfig = {
  url: `https://eth-sepolia.g.alchemy.com/v2/${process.env.ALCHEMY_TOKEN}`,
  blockNumber: 6378120,
};

checkForkedProviderEnvironment();

const config: HardhatUserConfig = {
  solidity: {
    compilers: [
      {
        version: "0.6.10",
        settings: { optimizer: { enabled: true, runs: 200 } },
      },
      {
        version: "0.8.11",
        settings: {
          optimizer: {
            enabled: true,
            runs: 200,
          },
        },
      },
    ],
  },
  networks: {
    hardhat: {
      allowUnlimitedContractSize: false,
      forking: (process.env.FORK) ? forkingConfig : undefined,
      accounts: getHardhatPrivateKeys(),
      gas: 12000000,
      blockGasLimit: 12000000
    },
    localhost: {
      url: "http://127.0.0.1:8545/",
      forking: (process.env.FORK) ? forkingConfig : undefined,
      timeout: 200000,
      gas: 12000000,
      blockGasLimit: 12000000
    },
    // sepolia: {
    //   url: `https://eth-sepolia.g.alchemy.com/v2/${process.env.ALCHEMY_TOKEN}`,
    //   // @ts-ignore
    //   accounts: [`0x${process.env.DEPLOY_PRIVATE_KEY}`],
    // },
  },
  // @ts-ignore
  typechain: {
    outDir: "typechain",
    target: "ethers-v5",
    externalArtifacts: ["external/**/*.json"],
  },
  // @ts-ignore
  contractSizer: {
    runOnCompile: false,
  },

  // These are external artifacts we don't compile but would like to improve
  // test performance for by hardcoding the gas into the abi at runtime
  // @ts-ignore
  externalGasMods: [
    "external/abi/perp",
  ],
};

function getHardhatPrivateKeys() {
  return privateKeys.map(key => {
    const ONE_MILLION_ETH = "1000000000000000000000000";
    return {
      privateKey: key,
      balance: ONE_MILLION_ETH,
    };
  });
}

function checkForkedProviderEnvironment() {
  if (process.env.FORK &&
      (!process.env.ALCHEMY_TOKEN || process.env.ALCHEMY_TOKEN === "fake_alchemy_token")
     ) {
    console.log(chalk.red(
      "You are running forked provider tests with invalid Alchemy credentials.\n" +
      "Update your ALCHEMY_TOKEN settings in the `.env` file."
    ));
    process.exit(1);
  }
}

export default config;

All the .env variables are valid and FORK has been set to true. Below is the error:

Screenshot 2024-07-27 at 1 18 19 AM
Abhishekkochar commented 1 month ago

Issue happens when try to fork the chain.

schaable commented 1 month ago

Hey @Abhishekkochar, I tested a simplified version of your Hardhat config and it seems to work as expected. Here’s the configuration I used:

const forkingConfig = {
  url: `your-alchemy-url`,
  blockNumber: 6378120,
};

const config: HardhatUserConfig = {
  solidity: {
    compilers: [
      {
        version: "0.6.10",
        settings: { optimizer: { enabled: true, runs: 200 } },
      },
      {
        version: "0.8.11",
        settings: {
          optimizer: {
            enabled: true,
            runs: 200,
          },
        },
      },
    ],
  },
  networks: {
    hardhat: {
      allowUnlimitedContractSize: false,
      forking: forkingConfig,
      gas: 12000000,
      blockGasLimit: 12000000,
    },
  },
};

Could you try again with this configuration and let me know if it works for you? If not, could you provide any extra information or share a link to the repo (if public)? Also, which version of Hardhat are you using?

schaable commented 4 days ago

I'm closing this for bookkeeping purposes, but if you can provide the requested details, please let us know, and we’ll reopen it. Thanks!