Ann
Ann

Reputation: 53

How to deploy two smart contracts that inherit from each other to test network together?

I have two smarts contracts

I working in remix IDE and when I click "Deploy", I can deploy only one smart contract. And when I copy ABI, I can copy only one ABI from one contract.

Is there a way to deploy this two contracts together, or should I deploy them seperatly? And if I will deploy them seperatly how numberTwo contract will find where is numberOne contract?

Thank you.

pragma solidity ^0.4.25;
contract numberOne{
}
contract numberTwo is numberOne{
}

Upvotes: 3

Views: 1505

Answers (2)

Vitaly Migunov
Vitaly Migunov

Reputation: 4457

The way you wrote it is that your numberTwo contract inherit numberOne so you don't need to deploy the first one separately.

But if you actually wanna deploy them separately you can do it like this. Just deploy them one by one and then connect the first one to the second one using the address of the first one.

contract NumberOne {
 uint256 public someData = 256;
}

contract NumberTwo {

  NumberOne numberOneContract;

  function initNumberOne(address _address) public {
    numberOneContract = NumberOne(_address);            
  }

  function getSomeData() view public returns (uint256) {
    return numberOneContract.someData();
  }

}

Upvotes: 2

Ann
Ann

Reputation: 53

I just made it. If simply deploy numberTwo contract that inherit from numberOne contract first, it will automaticly deploy two contracts. And if I will copy numberTwo contract's ABI it will have ABI from numberOne contract as well.

Upvotes: 2

Related Questions