Solidity and Remix – How to Pass Arguments to Constructor

remixsolidity

I got a constructor like this:

contract Test{
    constructor(uint256 _num) public {
    num = _num
    ;}
}

Now I want to use this contract in another contract. Like this:

contract Call{
Test test;

   function addTest(address addr){
      test = Test(addr)
   }
}

How can I pass the Argument _num to the constuctor?

Best Answer

enter image description hereYou can pass the argument _num to the constructor as follows:

contract Test {
    uint public num;
    constructor(uint256 _num) public {
        num = _num;
    }
}

contract Call {
    Test test;
    function addTest(uint256 _newNum){
        test = new Test(_newNum)
    }
}

Please go through Creating contracts via new keyword

The above link will help you in understanding things better.