使用安全帽和炼金术将智能合约部署到goerli测试网时出错:无法读取null的属性(读取'sendTransaction')



尝试从hardhat部署智能合约时出错。我已经读过:使用安全帽部署智能合约时出错--无法读取属性';sendTransaction';共个null和:使用Hardhat部署智能合约时出错--错误HH9:加载Hardhat';时出错;s配置这仍然不能解决我的问题,而且这些话题似乎已经结束了。错误详细信息:

TypeError: Cannot read properties of null (reading 'sendTransaction')
at ContractFactory.<anonymous> (E:CryptoDevhardhat-simple-storagenode_modules@ethersprojectcontractssrc.tsindex.ts:1247:38)
at step (E:CryptoDevhardhat-simple-storagenode_modules@ethersprojectcontractslibindex.js:48:23)
at Object.next (E:CryptoDevhardhat-simple-storagenode_modules@ethersprojectcontractslibindex.js:29:53)
at fulfilled (E:CryptoDevhardhat-simple-storagenode_modules@ethersprojectcontractslibindex.js:20:58)
at processTicksAndRejections (node:internal/process/task_queues:96:5)

我的hardhat.config.js文件:

require("@nomicfoundation/hardhat-toolbox");
require("dotenv").config();
const GOERLI_RPC_URL = process.env.GOERLI_RPC_URL;
const PRIVATE_KEY = process.env.PRIVATE_KEY;
module.exports = {
defaultNetwork: "hardhat",
networks: {
goerli: {
url: "https://eth-goerli.g.alchemy.com/v2/K9IsbfM7Z0jHrR5VTyg0rOsu0ghafL9D",
accounts: PRIVATE_KEY,
chainId: 5,
},
},
solidity: "0.8.9",
};

我的deploy.js:

const { ethers } = require("hardhat");
async function main() {
const SimpleStorageFactory = await ethers.getContractFactory("SimpleStorage");
console.log("Depoying contract. Please wait...");
const simpleStorage = await SimpleStorageFactory.deploy();
await simpleStorage.deployed();
console.log(`Deployed contract address: ${simpleStorage.address}`);
}
main()
.then(() => process.exit(0))
.catch((error) => {
console.error(error);
process.exitCode = 1;
});

此外,当我使用时:

goerli: {
url: GOERLI_RPC_URL,
accounts: PRIVATE_KEY,
chainId: 5,
},

它抛出了另一个错误:

* Invalid value undefined for HardhatConfig.networks.goerli.url - Expected a value of type string.

至少知道如何修复:TypeError:无法读取null(读取"sendTransaction"(错误的属性,因为它不允许我继续。

保留数组中帐户的值

networks: {
goerli: {
url: "https://eth-goerli.g.alchemy.com/v2/K9IsbfM7Z0jHrR5VTyg0rOsu0ghafL9D",
**accounts: [PRIVATE_KEY]**,
chainId: 5,
},
},

最新更新