I can connect truffle to my own geth chain, with this setting

$ vi truffle-config.js
  networks: {
    development: {
      host: "mydomain.com",
      port: 9000,
      network_id: "*",

but hardhat couldn't.


const config: HardhatUserConfig = {
  solidity: "0.8.17",
  networks: {
    localhost: {
chainId: 2000,
      chainId: 2000,

It's strange. I run geth with chainid 2000, but hardhat error said it connected to 2020.

Hardhat was set to use chain id 2000, but connected to a chain with id 2020.

Here's my geth setting.

geth --networkid 2000 --nodiscover --datadir data --http --http.port 9000 --http.addr --http.corsdomain '*' $ARGS --http.vhosts "*" --nodiscover --allow-insecure-unlock --http.api 'web3,eth,net,debug,personal'
 npx hardhat run --network localhost  scripts/deploy.js

later I changed chainId to 2020, error disappeared but ProviderError:HttpProviderError happend.

1 Answer 1


If what you want is to have a local ethereum node only for development (recommended)

You can use the same hardhat. It comes built-in with Hardhat Network, a local Ethereum network node designed for development. It allows you to deploy your contracts, run your tests and debug your code, all within the confines of your local machine.

npx hardhat run --network hardhat scripts/my-script.js

Even with hardhat you can independently run a node so that external clients can connect to it. This could be MetaMask, your Dapp interface, or a script. To run Hardhat Network this way, inside your project run:

npx hardhat node

Then just connect your metamask to and in the metamask you can load any of the accounts that the hardhat generates for development.

You can read more in the following link: https://hardhat.org/hardhat-network/docs/overview

If you still want to connect hardhat with geth then you can visit this link


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.