Lesson 6: deploy.js not using default hardhat network #6353
-
I am currently at lesson 6, timestamp 8:50 const { ethers } = require("hardhat");
async function main() {
const simpleStorageFactory = await ethers.getContractFactory("SimpleStorage");
console.log("Deploying contract...");
const simpleStorage = await simpleStorageFactory.deploy();
await simpleStorage.waitForDeployment();
simpleStorageAddress = simpleStorage.target;
console.log(`Contract deployed to: ${simpleStorageAddress}`);
}
main()
.then(() => process.exit(0))
.catch((error) => {
console.log(error);
process.exit(1);
}); and my hardhet.config.js file looks like this: require("@nomicfoundation/hardhat-toolbox");
require("dotenv").config();
/** @type import('hardhat/config').HardhatUserConfig */
module.exports = {
defaultNetwork: "hardhat",
networks: {
hardhat: {
chainId: 31337,
},
sepolia: {
url: process.env.SEPOLIA_RPC_URL,
accounts: [process.env.SEPOLIA_PRIVATE_KEY],
chainId: 11155111,
},
},
solidity: "0.8.19",
}; For some reason, when I try to run deploy.js using the default hardhat network, it tries to use the sepolia network instead and throws this error:
Please can someone help me fix this error so that deploy.js runs using the hardhat network. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
The error
Add |
Beta Was this translation helpful? Give feedback.
The error
Invalid account: #0 for network: sepolia - Expected string, received undefined
suggest that your private key variable isundefined
.Add
console.log(process.env.SEPOLIA_RPC_URL)
andconsole.log(process.env.SEPOLIA_PRIVATE_KEY)
to your deploy script - to check your data is formatted as expected.