简体   繁体   中英

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{
}

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();
  }

}

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM