Getting an error while I'm trying to deploy a smart contract to Goerli testnet. The error:

Error HH8: There's one or more errors in your config file:

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

To learn more about Hardhat's configuration, please go to https://hardhat.org/config/

For more info go to https://hardhat.org/HH8 or run Hardhat with --show-stack-traces

Here is my hardhat.config.js file:

/** @type import('hardhat/config').HardhatUserConfig */


module.exports = {
  solidity: "0.8.17",

  networks: {
    goerli: {
      url: `https://eth-goerli.alchemyapi.io/v2/${ALCHEMY_API_KEY}`,
      accounts: [GOERLI_PRIVATE_KEY],

I was on the same directory (The scripts directory). Also I copied the private key from Metamask of my Goerli account. I searched on google but found nothing helpful.

  • What is "PRV_KEY" here? I assume you are trying to import it from .env file. Is it so? Commented Jan 17, 2023 at 15:12
  • Actually I hard typed api & key. & Before post just replaced with API_KEY & PRV_KEY. @SolidityLearner Commented Jan 17, 2023 at 15:27
  • Make sure the private key is correct. And once without the strings. Commented Jan 18, 2023 at 12:09
  • Or you can use .env file for it, that's how I always write code and it works every single time. Commented Jan 18, 2023 at 12:09

1 Answer 1


After trying two days , I opened a new metamask and created a new account & by following the same private key copy method which I followed on my first metamask it worked perfectly, IDK what happend but it worked.

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.