Error when migrating, pls help

Hi.
I get this error message when I’m trying to migrate the multisig wallet contract. The contract compiles ok.

Deploying 'MSWallet'
   --------------------

Error:  *** Deployment Failed ***

"MSWallet" -- Invalid number of parameters for "undefined". Got 0 expected 2!.

    at /usr/local/lib/node_modules/truffle/build/webpack:/packages/deployer/src/deployment.js:365:1
    at processTicksAndRejections (node:internal/process/task_queues:93:5)
    at Migration._deploy (/usr/local/lib/node_modules/truffle/build/webpack:/packages/migrate/Migration.js:74:1)
    at Migration._load (/usr/local/lib/node_modules/truffle/build/webpack:/packages/migrate/Migration.js:61:1)
    at Migration.run (/usr/local/lib/node_modules/truffle/build/webpack:/packages/migrate/Migration.js:212:1)
    at Object.runMigrations (/usr/local/lib/node_modules/truffle/build/webpack:/packages/migrate/index.js:150:1)
    at Object.runFrom (/usr/local/lib/node_modules/truffle/build/webpack:/packages/migrate/index.js:110:1)
    at Object.run (/usr/local/lib/node_modules/truffle/build/webpack:/packages/migrate/index.js:87:1)
    at runMigrations (/usr/local/lib/node_modules/truffle/build/webpack:/packages/core/lib/commands/migrate.js:263:1)
    at Object.run (/usr/local/lib/node_modules/truffle/build/webpack:/packages/core/lib/commands/migrate.js:228:1)
    at Command.run (/usr/local/lib/node_modules/truffle/build/webpack:/packages/core/lib/command.js:140:1)

Here’s the migrations file (can’t see anyrhing wrong there, but still:

const MSWallet = artifacts.require("MSWallet");

module.exports = function (deployer) {
  deployer.deploy(MSWallet);
};
2 Likes

Hey @LaszloD, hope you are ok.

Does your multisig constructor requires some arguments to initialize? It would be great to check your contract, maybe you are not sending the arguments to deploy it properly.

Carlos Z

Yes, it does. It requires an array of owners and a uint for the approval limit. See code below.
Thanks mate.

// SPDX-License-Identifier: MIT
pragma solidity >=0.4.22 <0.9.0;
pragma abicoder v2;


contract MSWallet {
    
    address[] private owners;
    uint private approvalLimit;
    
    struct TransferRequest {
        address payable recipient;
        uint amount;
        uint approveCount;
    }
    
    TransferRequest[] transferRequests;
    
    constructor(address[] memory _owners, uint _approvalLimit) {
        owners = _owners;
        approvalLimit = _approvalLimit;
    }
    
    function deposit() public payable {
        //This actually works. Since function is payable, msg.value will be added to address(this).balance.
    }
    
    function t_transfer(address payable _address, uint _amount) public {
        require(address(this).balance >= _amount);
        require(msg.sender != _address);
        _address.transfer(_amount);
    }
    
    function createTransferRequest(address _owner, address payable _recipient, uint _amount) public {
        require(checkOwner(_owner));
        TransferRequest memory newTransferRequest = TransferRequest(_recipient, _amount, 0);
        transferRequests.push(newTransferRequest);
    }
    
    function approveRequest(uint _index, address _owner) public {
        require(transferRequests.length != 0);
        require(checkOwner(_owner));
        transferRequests[_index].approveCount += 1;
        if (transferRequests[_index].approveCount == approvalLimit) {
            t_transfer(transferRequests[_index].recipient, transferRequests[_index].amount);
        }
    }
    
    function checkOwner(address _address) private view returns(bool _bool) {
        for (uint i=0; i<owners.length; i++) {
            if (owners[i] == _address) {
                return true;
            } else {
                return false;
            }
        }
    }
    
    //Getter just to check balance of contract.
    function getBalance() public view returns(uint) {
        return address(this).balance;
    }
    
    //Getter to check transfer requests.
    function getTransfersRequest() public view returns(TransferRequest[] memory) {
        return transferRequests;
    }
}

Hi @LaszloD

As @thecil was suggesting, your constructor requires 2 arguments, you need to provide them during the contract deployment.

Regards,
Dani

Hi Dan.
Ok, I sort of figured that, but how do I provide the arguments to the constructor? Maybe you should include this in the assignment instructions since I guess most students run into the same problem.

Regards
Laszlo

2 Likes

In your migration file, you have to do something like this, at the end of the deployment, you can add the arguments that the constructor needs.

const MSWallet = artifacts.require("MSWallet");

module.exports = function (deployer) {
  deployer.deploy(MSWallet, ["address1","address2","address3"], 2);
};

Your constructor requires an array and uint values to initialize, so im just sending it an array with addresses and the approvals limit.

    constructor(address[] memory _owners, uint _approvalLimit) {
        owners = _owners;
        approvalLimit = _approvalLimit;
    }

Carlos Z

2 Likes

Ok, but that’s Solidity code in a javascript file.

Works fine, I just had to copy-paste “real” addresses.
Thanks!