0

Suppose I have 3 contracts, namely Owner, B and C:

contract Owned {
    address public owner;

    constructor() public {
        owner = msg.sender;
    }

    modifier onlyOwner {
        require(msg.sender == owner);
        _;
    }
}

Contract B

contract B is Onwed{
     constructor() public{
        uint256 totalSupply = 10000000000;     // any amount
     }
}

Contract C

I want to create an instance of contract B, in contract C. There are 2 ways to do it

contract C{
     constructor() public{
          B instance = B(address_of_deployed_B);  // Method 1
          B instance = new B();                   // Method 2
          B instance2 = new B();                  // 2 instances of B
    }

}

What I actually want here is, the owner of the contract is set to contract C's address.

But the following is happening.

Method 1 works fine when I try to instantiate this way, but since it's already deployed, I can't set owner properly. Method 2 is not able to deploy 2 instances of the contract in the constructor(shows revert).

[Edit 1] Method 2 is working fine. But it isn't working if you initialise 2 instances of the same contract.

  • It shows txn mined but the execution failed in remix IDE. – Aman Pandey Jun 15 at 6:08
0

The problem here is that it runs out of gas.

Maybe, in this case, it works, but if you have big contracts like ERC20 TOKEN, it may go out of gas and may not get deployed.

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.