Error: invalid address (argument="address", value=undefined, code=INVALID_ARGUMENT, version=address/5.1.0)

Viewed 5654

I'm Getting this error when trying to deploy a smart contract with a function:

"Error: invalid address (argument="address", value=undefined, code=INVALID_ARGUMENT, version=address/5.1.0) (argument="tokenAddress", value=undefined, code=INVALID_ARGUMENT, version=abi/5.0.7)"

Here is my code:

 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:

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

    safuFactoryAddress = payable(_safuFactoryAddress);
    safuDevAddress = payable(_safuDevAddress);
}
2 Answers

since there are still no answers yet, but over 1k views though, I'll leave here a solution if anyone else is facing the same error.

The solidity constructor in your example expects 2 arguments of type address. This means if you deploy your contract you also need to provide those 2.

As for the deployment: No matter how you deploy your contract, providing all constructor arguments should solve your problem and your contract should be able to get deployed now.

If you work with truffle, you need to adjust your deployer .../migrations/2_deploy_contracts.js and pass 2 addresses to satisfy the constructor parameters.

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

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

The same applies for test: let's say:

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

For those in Remix, select the drop down next to "deploy" and you will need to provide a "to" & "from" address for this to work

Remix Drop Down Option

Related