如何将另一个合同作为依赖项包含在内?

How to include another Contract as dependency?

合约中生成新合约的函数在 Remix 中执行良好,但在从我的自定义应用程序调用时失败,除了“交易失败”外没有提供任何细节。我很确定这样做的原因是两个合同都写在 Remix 的同一个文件中,所以它确切地知道如何定义子合同,而我的应用程序只接受 source/parent 的 abi。
简化的分布式代码是这样的:

pragma solidity ^0.6.0;

contract Parent{
  address[] public children;

  function createChild (uint256[] memory distro)external payable{
    children.push(address(new Child(msg.sender,distro)));
  }
}

contract Child{
  address payable owner;
  uint256[] distribution;

  constructor(address payable admin,uint256[] memory distro)public payable{
    owner=admin;
    distribution=distro;
  }
}

在我的 Flutter 应用中,我使用如下字符串列表定义父合同:

  List<String> source = [
    "function createChild(int256[]) payable",
  ]

然后继续获取用户的钱包凭据并推送交易,如下所示:

  String address = "0xbAF01C91b2d53cC9eeb0ED1A300783Cb74563010"; //address of deployed Parent
  var contract = Contract(address, source, web3user); 
  contract.connect(web3user.getSigner()); // uses the connected wallet as signer
  var ponse = await promiseToFuture(callMethod(contract, "createChild", [
    [
    [30, 70], //the array of int256 it takes as parameters
    TxParams(
      value: "1000000000000", 
      gasLimit: "1000000",
    )
  ]));

如何让我的应用知道子合同?我认为它应该以某种方式包含在 source 函数列表中,以便 EVM 知道要编译和部署什么,但不清楚如何指定它。

每当你想与链上的合约进行交互时,你需要 4 个东西:

  1. ABI
  2. 地址
  3. 区块链
  4. 一个有资金支付 gas 的钱包

当您创建合同时,是的,您的应用程序需要知道子合同的 ABI 是什么。因此,当您创建子合同时,您需要传入 ABI。