[英]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.我在混音 IDE 中工作,当我单击“部署”时,我只能部署一个智能合约。 And when I copy ABI, I can copy only one ABI from one contract.
当我复制 ABI 时,我只能从一份合约中复制一份 ABI。
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?
如果我将单独部署它们,numberTwo 合约将如何找到 numberOne 合约在哪里?
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.你写它的方式是你的 numberTwo 合约继承 numberOne 所以你不需要单独部署第一个。
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.
如果简单地先部署继承自 numberOne 合约的 numberTwo 合约,它会自动部署两个合约。 And if I will copy numberTwo contract's ABI it will have ABI from numberOne contract as well.
如果我要复制 numberTwo 合同的 ABI,它也会有来自 numberOne 合同的 ABI。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.