1

I tried to use 1337 as chainID on Hardhat to match metamask localhost 8545. enter image description here

My hardhat.config.js have already included 1337 chainID for hardhat as below.

module.exports = {
  solidity: "0.8.17",
  networks: {
    hardhat: {
      chainId: 1337
    }
  }
};

As you can see above, I set chainId as 1337, but it didn't work and I got the below error when I try to use the contract's setGreeting function in frontend.

async function setGreeting() {
    if (!greeting) return
    if (typeof window.ethereum !== 'undefined') {
      await requestAccount()
      const provider = new ethers.providers.Web3Provider(window.ethereum)
      const signer = provider.getSigner()
      const contract = new ethers.Contract(greeterAddress, Greeter.abi, signer)
      const transaction = await contract.setGreeting(greeting)
      await transaction.wait()
      fetchGreeting()
    }
  }

The error is below. enter image description here

Can you please inform me how to use 1337 instead of 31337 on Hardhat?

2
  • What does your hardhat chain say when you start it? Does it show the right ID? Dec 3, 2022 at 10:59
  • Hardhat default chainId is just 31337, and I want to change it to 1337 to match metamask. Dec 3, 2022 at 23:28

1 Answer 1

0

don't force to use 1337 id. Just add another network using chain id 31337.

Click fabcon -> settings -> networks -> add network

enter image description here

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.