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;
Add a comment
|
1 Answer
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)
- 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]
- Else you installed dotenv, use may the following
accounts: [process.env.PRIVATE_KEY]
- 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