我收到了这个错误
TypeError: Cannot read properties of null (reading 'sendTransaction')当我运行以下命令时:
yarn hardhat run scripts/deploy.js --network Sepoliadeploy.js:
const { ethers } = require("hardhat")
async function main() {
const SimpleStorageFactory = await ethers.getContractFactory(
"SimpleStorage"
)
console.log("Deploying the contract...")
const SimpleStorage = await SimpleStorageFactory.deploy()
await SimpleStorage.deployed()
console.log(`Contract deployed at address: ${SimpleStorage.address}`)
}
main()
.then(() => process.exit(0))
.catch((error) => {
console.error(error)
process.exit(1)
})hardhat.config.js:
require("@nomicfoundation/hardhat-toolbox")
require("dotenv").config()
const SEPOLIA_RPC_URL = process.env.SEPOLIA_RPC_URL
const PRIVATE_KEY = process.env.PRIVATE_KEY
/** @type import('hardhat/config').HardhatUserConfig */
module.exports = {
defaultNetwork: "hardhat",
networks: {
Sepolia: {
url: SEPOLIA_RPC_URL,
accounts: PRIVATE_KEY,
chainId: 11155111,
},
},
solidity: "0.8.18",
}发布于 2023-03-24 13:07:48
您应该将您的帐户放在一个数组:accounts: [PRIVATE_KEY]中,并确保.env文件中的所有内容都是正确的。如果仍有错误,请尝试console.log()您的env变量以查看dotenv包是否正常工作。
https://ethereum.stackexchange.com/questions/147869
复制相似问题