Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lesson07: Failed to get chainId, falling back to net_version #6450

Open
caducus7 opened this issue Feb 8, 2024 · 4 comments
Open

Lesson07: Failed to get chainId, falling back to net_version #6450

caducus7 opened this issue Feb 8, 2024 · 4 comments

Comments

@caducus7
Copy link

caducus7 commented Feb 8, 2024

Hello all,
I'm having this issue on Lesson 07, when trying to deploy on Sepolia for the first time. I've been searching around but can't find a reason for this or tinker my way through to get the chainId to be read.
I'm fairly sure it has something to do with the RPC_URL from alchemy but nothing has worked for me so far.
Might it be a hardhat toolbox issue?

//hardhat-config.js

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

/** @type import('hardhat/config').HardhatUserConfig */
const SEPOLIA_RPC_URL =
    process.env.SEPOLIA_RPC_URL ||
    "https://eth-sepolia.g.alchemy.com/v2/myappkey"
const PRIVATE_KEY =
    process.env.PRIVATE_KEY ||
    "myprivatekey"
const ETHERSCAN_API_KEY =
    process.env.ETHERSCAN_API_KEY || "etherscanapikey"
const COINMARKETCAP_API_KEY =
    process.env.COINMARKETCAP_API_KEY || "coimarketcapkey"

module.exports = {
    solidity: {
        compilers: [{ version: "0.8.8" }, { version: "0.6.6" }],
    },
    defaultNetwork: "hardhat",
    networks: {
        sepolia: {
            url: SEPOLIA_RPC_URL,
            chainId: 11155111,
            accounts: [PRIVATE_KEY],
            blockConfirmations: 6,
        },
        hardhat: {
            chainId: 31337,
        },
    },

//helper-hardhat-config if relevant

const networkConfig = {
    31337: {
        name: "localhost",
    },
    // Price Feed Address, values can be obtained at https://docs.chain.link/data-feeds/price-feeds/addresses
    11155111: {
        name: "sepolia",
        ethUsdPriceFeed: "0x694AA1769357215DE4FAC081bf1f309aDC325306",
    },
}

const developmentChains = ["hardhat", "localhost"]

module.exports = { networkConfig, developmentChains }

//01-deploy-fund-me relevant chainId code

const { verifyMessage } = require("ethers")
const { networkConfig, developmentChains } = require("../helper-hardhat-config")
const { network } = require("hardhat")
const { verify } = require("../utils/verify")
require("dotenv").config()


module.exports = async ({ getNamedAccounts, deployments }) => {
    const { deploy, log } = deployments
    const { deployer } = await getNamedAccounts()
    const chainId = network.config.chainId

    let ethUsdPriceFeedAddress
    if (chainId == 31337) {
        const ethUsdAggregator = await deployments.get("MockV3Aggregator")
        ethUsdPriceFeedAddress = ethUsdAggregator.address
    } else {
        ethUsdPriceFeedAddress = networkConfig[chainId]["ethUsdPriceFeed"]
    } 

Originally posted by @caducus7 in #6296 (comment)

Screenshot_1

@rocco1226
Copy link

I'm also a rookie for web3 development and I can't resolve the problem. But I think if you are fairly convinced that the issue was related to the RPC_URL from alchemy, you can choose another web3 development platform, such as infura, to try another RPC_URL.

@caducus7
Copy link
Author

caducus7 commented Feb 9, 2024

But I think if you are fairly convinced that the issue was related to the RPC_URL from alchemy, you can choose another web3 development platform, such as infura, to try another RPC_URL.

You are correct and I tried that, but I still get the same problem.
What I meant was the way the RPC_URL is being handled by the code has to be the issue, since the deployment isn't happening at all. Could it be a hardhat issue? Can't seem to figure this out..

@rocco1226
Copy link

But I think if you are fairly convinced that the issue was related to the RPC_URL from alchemy, you can choose another web3 development platform, such as infura, to try another RPC_URL.

You are correct and I tried that, but I still get the same problem. What I meant was the way the RPC_URL is being handled by the code has to be the issue, since the deployment isn't happening at all. Could it be a hardhat issue? Can't seem to figure this out..

I had pushed my code in repo,you can check my code. My contract was deployed well.

@tusharr1411
Copy link

It should be require("dotenv").config() instead of require("dotenv").config in your hardhat.config.js
(parentheses after config)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants