簡體   English   中英

使用安全帽和煉金術將智能合約部署到 goerli 測試網時出錯:無法讀取 null 的屬性(讀取“sendTransaction”)

[英]Error deploying smart contract to goerli testnet using hardhat and alchemy : Cannot read properties of null (reading 'sendTransaction')

嘗試從安全帽部署智能合約時出現錯誤。 我已經閱讀: 使用安全帽部署智能合約時出錯——無法讀取 null 的屬性“sendTransaction”和:使用安全帽部署智能合約時出錯——錯誤 HH9:加載安全帽配置時出錯這仍然不能解決我的問題和主題看起來像解決方案。 錯誤詳情:

TypeError: Cannot read properties of null (reading 'sendTransaction')
    at ContractFactory.<anonymous> (E:\CryptoDev\hardhat-simple-storage\node_modules\@ethersproject\contracts\src.ts\index.ts:1247:38)
    at step (E:\CryptoDev\hardhat-simple-storage\node_modules\@ethersproject\contracts\lib\index.js:48:23)
    at Object.next (E:\CryptoDev\hardhat-simple-storage\node_modules\@ethersproject\contracts\lib\index.js:29:53)
    at fulfilled (E:\CryptoDev\hardhat-simple-storage\node_modules\@ethersproject\contracts\lib\index.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",
};

我的部署.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: Cannot read properties of null (reading 'sendTransaction') 錯誤,因為它不允許我繼續。

將帳戶的值保存在數組中

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM