1

Command:

npx hardhat --network sepolia run scripts/deploy.js

Getting error messages:

* Invalid account: #0 for network: sepolia - private key too long, expected 32 bytes
  * Invalid value undefined for HardhatConfig.networks.etherscan.url - Expected a value of type string.
  * Invalid account: #0 for network: etherscan - private key too short, expected 32 bytes

Hardhat.cofig:

// import config before anything else import {config as dotEnvConfig} from dotEnvConfig();
/**
* @type import('hardhat/config').HardhatUserConfig
*/

require ('dotenv').config();
require("@nomicfoundation/hardhat-toolbox");
require("hardhat-deploy");


{
}

const {ALCHEMY_API_KEY,ETHERSCAN_API_KEY,PRIVATE_KEY} = process.env;
const ERC1155 = require("@openzeppelin/contracts/build/contracts/ERC1155.json");



module.exports =  {
    defaultNetwork: "sepolia",
    networks: {
      hardhat: {
      },
      sepolia: {
        url: "process.env.ALCHEMY_API_KEY",
        accounts: [`0x${ALCHEMY_API_KEY}`],
    },
    etherscan: {
        apiKey: "process.env.ETHERSCAN_API_KEY",
        accounts: [`0x${ETHERSCAN_API_KEY}`],
      },
    },
    solidity: {
      version: "0.8.9",
      settings: {
        optimizer: {
          enabled: true,
          runs: 200
        }
      }
    },
    paths: {
      sources: "./contracts",
      tests: "./test",
      cache: "./cache",
      artifacts: "./artifacts"
    },
    mocha: {
      timeout: 40000
    }
  }
1
  • Are you sure you are using the correct private key?
    – DevCrypto
    Aug 27 at 3:43

1 Answer 1

0

You need to pass the url and PK in a simple way, change your code to this:

Pass the URL, not only the API key.

       sepolia: {
            url: process.env.ALCHEMY_API_KEY, // Pass the full URL here
            accounts: [PRIVATE_kEY], //pass the wallet private key, not the api key
        },
        etherscan: {
            apiKey: process.env.ETHERSCAN_API_KEY, // Pass the full URL here
            accounts: [PRIVATE_kEY],//pass the wallet private key, not the api key
        },
11
  • @Gujarati No, I never used that and my code always runs fine, don't know how do you come with this. Aug 27 at 17:23
  • because it's run very well in my system.
    – Gujarati
    Aug 28 at 5:36
  • Good for you, I will always write the easiest and simplest answers, unless there's a need to add more characters. Thanks. Aug 28 at 9:23
  • Thanks I realized that I was using the wrong private key and use your hardhat.config example and removed my etherscan API just to see if less is better and get it to work but I still got an error For more info go to hardhat.org/HH8 or run Hardhat with --show-stack-traces MacBook-Pro:erc1155-contract complexdesign$ npx hardhat run scripts/deploy.js --network sepolia Error HH8: There's one or more errors in your config file: Invalid account: #0 for network: sepolia - private key too long, expected 32 bytes
    – Frantz M.
    Aug 29 at 19:24
  • It's clearly a wrong private key, Make sure to pass the right private key in the right way. How are you passing the private key? Aug 30 at 4:37

Your Answer

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

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