如何部署使用彼此功能的多个实体智能合约?

时间:2018-10-07 04:45:53

标签: blockchain ethereum solidity smartcontracts truffle

我有三个智能合约,分别是a.sol,b.sol和c.sol ...在这三个合约中,前两个是独立的智能合约,而c.sol使用a.sol和b.sol和因此,c.sol需要“导入”前两个智能合约。 “导入”在本地工作,但是如何通过renet / truffle在测试网上部署所有这些,以便c.sol仍然可以访问a.sol和b.sol的功能?

2 个答案:

答案 0 :(得分:1)

您的合同a和b是否都想成为独立合同,而与合同c无关?即:用户将数据存储在合同a中,合同c将使用该数据

如果是这样,那么您可以像这样将合约a和b作为合约c的变量

a.sol

contract A {
  function doSomething() {
    ...
  }
}

c.sol

contract C {
  A a;

  function setA(address addressOfContractA) {
    a = A(address);
  }

  function makeADoSomething() {
    a.doSomething();
  }
}

信用:https://zupzup.org/smart-contract-interaction/

答案 1 :(得分:0)

如果您的项目是使用Truffle创建的,则可以通过以下方式设置const handlers = { 'LaunchRequest': function () { this.emit(':ask', 'welcome to dog pictures'); }, 'ShowAllDogPicturesIntent': function() { this.emit(':ask', 'you asked for all pictures'); }, 'ShowDogPictureIntent': function() { var dogPictureNumber = this.event.request.intent.slots.number.value; var messagesRef = firebase.database().ref('settings'); var newMessageRef = messagesRef.push(); newMessageRef.set({ picture: dogPictureNumber, }); this.emit(':ask', "Thank you for updating"); }, 'AMAZON.HelpIntent': function () { this.emit(':tell', 'you can ask for any dog picture'); }, 'AMAZON.CancelIntent': function () { this.emit(':tell', 'bye bye, have a nice day'); }, 'AMAZON.StopIntent': function () { this.emit(':tell', 'have a nice day'); }, 'Unhandled': function () { this.emit(':ask', 'There was a problem here'); }, };

c.sol

如果这是代码的结构,则可以使用import "./a.sol"; import "./b.sol"; contract c is a, b { ... } 部署Truffle项目(前提是正确设置了迁移)。