错误:地址无效(参数=“地址”,值=未定义,代码=INVALID_ARGUMENT,版本=地址/5.1.0)

Nat*_*han 6 solidity web3js

尝试使用函数部署智能合约时出现此错误:

错误:无效地址(参数=“地址”,值=未定义,代码=INVALID_ARGUMENT,版本=地址/5.1.0)(参数=“tokenAddress”,值=未定义,代码=INVALID_ARGUMENT,版本=abi/5.0.7)

这是我的代码:

 const handlePresale = async (e) => {
    e.preventDefault();
    const web3 = await getWeb3();
    const abiData = SafeHubPresaleAbi;
    const contractAddress = "0x4498F943E0a13D70B28e7565CF4E33bF443e6Bf9";

    const duration = {
      seconds: function (val) {
        return val;
      },
      minutes: function (val) {
        return val * this.seconds(60);
      },
      hours: function (val) {
        return val * this.minutes(60);
      },
      days: function (val) {
        return val * this.hours(24);
      },
      weeks: function (val) {
        return val * this.days(7);
      },
      years: function (val) {
        return val * this.days(365);
      },
    };

    const latestTime = new Date().getTime();
    const openingTime = latestTime + duration.minutes(1);
    const closingTime = openingTime + duration.minutes(10);
    const liqAddingTime = closingTime + duration.minutes(5);

    let _info = {
      address : "0x4498F943E0a13D70B28e7565CF4E33bF443e6Bf9",
      tokenPrice : web3.utils.toWei("10", "ether"),
      hardCap: web3.utils.toWei("100", "ether"),
      softCap: web3.utils.toWei("30", "ether"),
      minInv: web3.utils.toWei("0.1", "ether"),
      maxInv: web3.utils.toWei("5", "ether"),
      openingTime: openingTime,
      closingTime: closingTime,
  };

    let _uniInfo = {
      listingPrice: web3.utils.toWei("20", "ether"),
      liqTime: liqAddingTime,
      lockTime: 365,
      precentLock: 25,
    };

    let _stringInfo = {
      listingName: "WER sale",
    };

    const preslaeContract = await new web3.eth.Contract(
      abiData,
      contractAddress
    );
    // console.log(preslaeContract.methods)

    preslaeContract.methods
    .createPresale(_info,_uniInfo,_stringInfo)
    .call((err, result) => {
      console.log(result), console.log(err);
    });
  }
Run Code Online (Sandbox Code Playgroud)

坚固构造函数:

constructor(address _safuFactoryAddress, address _safuDevAddress) public {
    require(_safuFactoryAddress != address(0));
    require(_safuDevAddress != address(0));

    safuFactoryAddress = payable(_safuFactoryAddress);
    safuDevAddress = payable(_safuDevAddress);
}
Run Code Online (Sandbox Code Playgroud)

小智 3

因为仍然没有答案,但浏览次数超过 1k,如果其他人面临同样的错误,我将在这里留下一个解决方案。

您的示例中的 Solidity 构造函数需要 2 个地址类型的参数。这意味着如果您部署合约,您还需要提供这 2 个信息。

至于部署: 无论您如何部署合约,提供所有构造函数参数都应该可以解决您的问题,并且您的合约现在应该能够部署。

如果您使用 truffle,则需要调整您的部署程序.../migrations/2_deploy_contracts.js并传递 2 个地址以满足构造函数参数。

var SafeHubPresale = artifacts.require("./SafeHubPresale.sol");

module.exports = function(deployer) {
  deployer.deploy(SafeHubPresale, [address1], [address2]);
};
Run Code Online (Sandbox Code Playgroud)

这同样适用于测试: 比方说:

var myContract = await SafeHubPresale.new(accounts[1], accounts[2], {from: accounts[0], gas: 0});
Run Code Online (Sandbox Code Playgroud)