【发布时间】: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