1

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?

1

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.