【问题标题】:Go-Ethereum iOS cannot unmarshal resultsGo-Ethereum iOS 无法解组结果
【发布时间】:2018-10-02 19:12:49
【问题描述】:

所以我在 iOS 中使用 go-ethereum 并且在尝试与部署到 Rinkeby 测试网的合约交互时遇到了很多麻烦,我对整个区块链技术非常陌生,所以任何帮助都是赞赏。

我要做的就是访问已部署的合约并获取字符串的值,但我遇到的问题是当我尝试调用绑定合约时出现此错误:

Thread 1: Fatal error: 'try!' expression unexpectedly raised an error: Error Domain=go Code=1 "abi: cannot unmarshal string in to []interface {}" UserInfo={NSLocalizedDescription=abi: cannot unmarshal string in to []interface {}}

这是我用来拨打电话的代码。

    // Declare the error variables
    var clientError: NSErrorPointer;
    var addressError: NSErrorPointer;
    var contractError: NSErrorPointer;

    // Get the bindContract from Rinkeby test network.
    let client = GethNewEthereumClient("https://rinkeby.infura.io/v3/398ed56d211646faaf010ca183de11f2", clientError);
    let contractAddress = GethNewAddressFromHex("0x7259667715d671Ee370d7788647f95Fe7C3B532d", addressError);

    guard let contractABI = ReadJsonResourceAsString(fileName: "InboxContractInterface", fileType: "json") else {
        print("[ViewController] failed to read the abi json as string.")
        return;
    }

    let boundContract = GethBindContract(contractAddress, contractABI, client, contractError);

    // Prepare the callOpts
    let callOpts = GethNewCallOpts();
    callOpts?.setGasLimit(300000);
    callOpts?.setContext(GethNewContext());


    // Prepare the results & params interfaces
    let results = GethNewInterfaces(1);
    let params = GethNewInterfaces(0);


    let stringResult = GethNewInterface();
    stringResult?.setDefaultString();
    try! results?.set(0, object: stringResult);

    // Make the call
    let methodName = "message";
    try! boundContract?.call(callOpts, out_: results, method: methodName, args: params);


    // Show results.
    print("[ViewController] message call result: " + (stringResult?.getString())!);

这是我的合同代码:

pragma solidity ^0.4.17;

contract Inbox {

    string public message;

    function Inbox (string initialMessage) public {
        message = initialMessage;
    }

    function setMessage (string newMessage) public {
        message = newMessage;

    }

}

【问题讨论】:

    标签: ios swift mobile ethereum go-ethereum


    【解决方案1】:

    对于在深入挖掘后可能会发现相同问题的任何人,我发现这个问题适用于 android:https://github.com/ethereum/go-ethereum/issues/14832

    幸运的是,这已经修复了,所以没有使用最新版本完全是我的错。 我使用的是 Geth v1.5.9,所以在更新到 v1.8.2 后它终于可以工作了,不确定中间的哪个版本得到了修复。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-02-22
      • 1970-01-01
      • 2020-04-29
      • 1970-01-01
      • 2014-02-06
      • 2021-12-14
      相关资源
      最近更新 更多