0
import { HardhatUserConfig } from "hardhat/config";
import "@nomicfoundation/hardhat-toolbox";
require('dotenv').config();

const {API_URL, PRIVATE_KEY} =  process.env;

const config: HardhatUserConfig = {
  solidity: "0.8.19",
  defaultNetwork: "sepolia",
  networks: {
    hardhat: {},
    sepolia: {
      url: `${process.env.API_URL}`,
      accounts: [`0x${process.env.PRIVATE_KEY}`],
    }
  }
};
export default config;

1 Answer 1

1
 sepolia: {
  url: `${process.env.API_URL}`,
   accounts: [`0x${process.env.PRIVATE_KEY}`], //No need to concatenate '0x"
}

The issue is from the configuration above. Firstly, there's no need to add the "0x" suffix. Here are a few ways to address the issue (depending on the cause of the problem)

  1. If you created the project using creat-react-app, your .env variables ought to be suffixed with "REACT_APP" (see https://create-react-app.dev/docs/adding-custom-environment-variables/)

accounts: [process.env.REACT_APP_PRIVATE_KEY]

  1. Else you installed dotenv, use may the following

accounts: [process.env.PRIVATE_KEY]

  1. If the above doesn't work. You need to ensure that you are using the right wallet PRIVATE KEY (e.g for metamask see https://support.metamask.io/hc/en-us/articles/360015289632) and not the API KEY from alchemy or infura

I hope this helps. To help others, please do not forget to select this answer as the solution if it addresses this issue. Happy coding

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.