【问题标题】:Error deploying smart contract using hardhat -- Cannot read property 'sendTransaction' of null使用 hardhat 部署智能合约时出错——无法读取 null 的属性 \'sendTransaction\'
【发布时间】:2022-11-24 05:52:10
【问题描述】:

尝试从 hardhat 部署智能合约时出现以下错误。错误详情

TypeError: Cannot read property 'sendTransaction' of null
    at ContractFactory.<anonymous> (C:\Collection\node_modules\@ethersproject\contracts\src.ts\index.ts:1249:38)
    at step (C:\Collection\node_modules\@ethersproject\contracts\lib\index.js:48:23)
    at Object.next (C:\Collection\node_modules\@ethersproject\contracts\lib\index.js:29:53)
    at fulfilled (C:\Collection\node_modules\@ethersproject\contracts\lib\index.js:20:58)

这是配置文件

  1. hardhat.config.js
    require('@nomiclabs/hardhat-waffle');
    require("@nomiclabs/hardhat-ethers");
    
    require("dotenv").config();
    // This is a sample Hardhat task. To learn how to create your own go to
    // https://hardhat.org/guides/create-task.html
    task("accounts", "Prints the list of accounts", async (taskArgs, hre) => {
      const accounts = await hre.ethers.getSigners();  
      for (const account of accounts) {
        console.log(account.address);
      }
    });
    
    // You need to export an object to set up your config
    // Go to https://hardhat.org/config/ to learn more
    
    /**
     * @type import('hardhat/config').HardhatUserConfig
     */
    module.exports = {
      solidity: "0.8.2",
      networks: {
        mumbai: {
          url: process.env.MUMBAI_URL,
          account: process.env.PRIVATE_KEY
        }
      }
    };
    
    
    1. 部署.js
    const {ethers} = require("hardhat");
    
    async function main() {
      const SuperMario = await ethers.getContractFactory("SuperMario");
      const superInstance = await SuperMario.deploy("SuperMarioCollection", "SMC");
      await superInstance.deployed();
      console.log("contract was deployed to:", superInstance.address());
    
      await superInstance.mint("https://ipfs.io/ipfs/XXXXXXX");
    }
    
    // We recommend this pattern to be able to use async/await everywhere
    // and properly handle errors.
    main()
      .then(() => process.exit(0))
      .catch((error) => {
        console.error(error);
        process.exit(1);
      });
    
    

    我正在尝试使用以下命令部署它 npx hardhat run scripts/deploy.js --network mumbai

    谢谢

【问题讨论】:

  • 我使用与您完全相同的配置和部署脚本,没有出错。只需使用superInstance.address 而不是superInstance.address() 但除此之外一切都很好
  • 不幸的是,即使从地址中删除 () 之后,它对我来说也是同样的错误。

标签: solidity hardhat


【解决方案1】:

在网络配置中将account更改为accounts

【讨论】:

    【解决方案2】:

    找到了解决方法。 hardhat.config 文件中有错误 而不是帐户:,它应该是 帐户:[process.env.PRIVATE_KEY]

    【讨论】:

      【解决方案3】:

      你打错了,改一下帐户帐户,它将起作用。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2022-12-24
        • 2021-10-09
        • 1970-01-01
        • 1970-01-01
        • 2021-11-15
        • 1970-01-01
        • 2022-11-11
        • 1970-01-01
        相关资源
        最近更新 更多