在Solidity中的对象组成

时间:2017-12-17 17:59:26

标签: oop solidity smartcontracts

对象组合如何在Solidity中工作?我还没有找到全面的指南,所有的例子似乎都处理了hello world level或ERC20令牌实现。

  1. 我可以与其他合同的公共财产签订合同吗?
  2. 这些合约实例可以作为合约之间的函数参数传递吗?

1 个答案:

答案 0 :(得分:2)

对这两个问题都是肯定的 - 一个简单的例子可以说明如下:

|      ID |  A |  B |   C |   D |   E |   F |
|---------|----|----|-----|-----|-----|-----|
| 4169137 | no | no | yes | yes | yes | yes |

部署 contract HelperContract { function foo() public pure returns(uint) { return(0); } } contract MainContract { HelperContract helperContract; function MainContract(address helperAddress) public { helperContract = HelperContract(helperAddress); } function bar() public view returns(uint) { return helperContract.foo(); } } ,然后使用现在部署的HelperContract地址创建HelperContract的实例后,我们可以拨打MainContract,然后拨打bar

您可以将此代码复制粘贴到remix并快速验证是否存在。

如果您希望查看foo类型之外的真实世界示例,则可以查看CryptoKitties来源here,它们使用此类型的模式。

需要深入研究一下代码,但您可以查找Hello world!合约,其中包含方法KittyAuctionsetSaleAuctionAddress。这些函数分别设置对单独部署的setSiringAuctionAddressSaleClockAuction合同的引用。

相关问题