I am not being able to connect hardhat to the local ganache network. I have already connected the ganache to the metamask.

Here is my hardhat.config.js code:

/** @type import('hardhat/config').HardhatUserConfig */
module.exports = {
  solidity: "0.8.4",

  networks: {
    localganache: {
      url: process.env.PROVIDER_URL || "",
      accounts: [`0x${process.env.PRIVATE_KEY}`] || "0xe5bd56d0495f627245970002400325172c3fd589233c2c16c94d23efa33f7495", // Fixing the syntax error here

Error I'm getting is

npx hardhat run scripts/deploy.js --network localganache
Error HH8: There's one or more errors in your config file:

  * Invalid account: #0 for network: localganache - private key too short, expected 32 bytes

1 Answer 1


The error message indicates that the private key provided in the accounts section of your Hardhat configuration is too short. A valid Ethereum private key should be 32 bytes (64 characters when represented as a hexadecimal string).

Thus, remove the "0x" in your code should solve the problem since it adds two characters (66 characters) to the private key. Something like this will work

accounts: [`${process.env.PRIVATE_KEY}`] || "e5bd56d0495f627245970002400325172c3fd589233c2c16c94d23efa33f7495",
  • Thank you it worked!
    – imbot
    Commented Jan 6 at 17:42

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.