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

问题描述 投票:0回答:4

我在尝试部署带有函数的智能合约时遇到此错误:

错误:无效地址(参数=“地址”,值=未定义,代码=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);
    });
  }

Solidity 构造函数:

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

    safuFactoryAddress = payable(_safuFactoryAddress);
    safuDevAddress = payable(_safuDevAddress);
}
solidity web3js
4个回答
3
投票

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

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

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

如果您使用 truffle,则需要调整您的 deployer ...

/migrations/2_deploy_contracts.js
并传递 2 个地址以满足构造函数参数。

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

module.exports = function(deployer) {
  deployer.deploy(SafeHubPresale, [address1], [address2]);
};

测试同样适用: 让我们说:

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

1
投票

对于 Remix 中的用户,选择“部署”旁边的下拉菜单,您需要提供“收件人”和“发件人”地址才能正常工作


0
投票

在您的智能合约中,可能会出现多个参数,并且在您部署时无法实现其价值。当您部署时,您将获取这些值并调用

deploy()
,它可以正常工作。

在你的构造函数中

constructor(address _safuFactoryAddress, address _safuDevAddress)

存在多个地址值,您在部署时可能不会提供该值。


0
投票

我在尝试测试Chainlink VRF时遇到了这个问题。

我有两个问题:

1.我部署了错误的合约

在 Remix 侧边栏中,我需要将合约切换为

VRFD20.sol
:

2.我正在使用 Remix VM

Chainlink VRF 服务仅适用于真实网络(如主网或 sepolia)。将 Remix 环境更改为“注入的提供程序 - MetaMask”修复了错误。

© www.soinside.com 2019 - 2024. All rights reserved.