代码之家  ›  专栏  ›  技术社区  ›  Baek Ryun

Go-Ethereum iOS无法取消标记结果

  •  0
  • Baek Ryun  · 技术社区  · 6 年前

    因此,我在iOS中与Go Ethereum一起玩,在尝试与部署到Rinkeby Testnet的合同交互时遇到了不少困难,我对整个区块链技术非常陌生,因此任何帮助都会受到赞赏。

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

    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;
    
        }
    
    }
    
    1 回复  |  直到 6 年前
        1
  •  0
  •   Baek Ryun    6 年前

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

    幸运的是,这个问题已经解决了,所以不使用最新版本完全是我的错。 我使用的是Gethv1.5.9,所以在更新到v1.8.2之后,它最终工作了,不确定两者之间的哪个版本得到了修复。