【问题标题】:How to include another Contract as dependency?如何包含另一个合同作为依赖项?
【发布时间】:2021-03-31 15:44:25
【问题描述】:

生成新合约的合约中的函数可以在 Remix 中正常执行,但在从我的自定义应用程序调用时失败,除了“交易失败”之外没有提供任何详细信息。我很确定这样做的原因是两个合同都写在 Remix 中的同一个文件中,所以它确切地知道如何定义子合同,而我的应用程序只接受源/父级的 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",
    )
  ]));

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

【问题讨论】:

    标签: flutter solidity smartcontracts web3


    【解决方案1】:

    每当你想与链上合约交互时,你需要做 4 件事:

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

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

    【讨论】:

      猜你喜欢
      • 2021-11-16
      • 1970-01-01
      • 1970-01-01
      • 2014-04-04
      • 1970-01-01
      • 2019-06-26
      • 2021-12-24
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多