Nicht erfasster Fehler: Konnte nicht decodiert werden, json: Array kann nicht in einen Go-Wert vom Typ String (…) entpackt werden

Ich versuche, meinen bereits bereitgestellten Vertrag mit web3.js von meiner Konsole aus zu verwenden, aber ich habe Probleme.

Ich bekomme meinen zusammengestellten Vertrag von Browser-Solidity und mache dann:

var web3 = new Web3(new Web3.providers.HttpProvider("http://localhost:8545"));
var MyContract = web3.eth.contract(abi);
var myContractInstance = MyContract.at('address');
web3.eth.getCode(address)  => returns my contract code

Wenn ich dann eingebe myContractinstance, erhalte ich die Liste der Methoden, die ich in solidity eingebaut habe.

Problem ist: Ich erhalte diesen Fehler für alle Funktionsaufrufe.

Nicht erfasster Fehler: Konnte nicht decodiert werden, json: Array kann nicht in einen Go-Wert vom Typ „String“ entpackt werden

Hat jemand eine Ahnung, was passieren könnte?

Edit: Entschuldigung für die späte Bearbeitung

Ich verwende eine leicht modifizierte Version dieses standardisierten Vertrags:

Vertragswährung {

                struct Account {
                    uint balance;
                    mapping ( address => uint) withdrawers;
                }

                mapping ( address => Account ) accounts;

                event CoinSent(address indexed from, uint256 value, address indexed to);

                function currency() {
                    accounts[msg.sender].balance = 1000000;
                }

                function sendCoin(uint _value, address _to) returns (bool _success) {
                    if (accounts[msg.sender].balance >= _value && _value < 340282366920938463463374607431768211456) {
                        accounts[msg.sender].balance -= _value;
                        accounts[_to].balance += _value;
                        CoinSent(msg.sender, _value, _to);
                        _success = true;
                    }
                    else _success = false;
                }

                function sendCoinFrom(address _from, uint _value, address _to) returns (bool _success) {
                    uint auth = accounts[_from].withdrawers[msg.sender];
                    if (accounts[_from].balance >= _value && auth >= _value && _value < 340282366920938463463374607431768211456) {
                        accounts[_from].withdrawers[msg.sender] -= _value;
                        accounts[_from].balance -= _value;
                        accounts[_to].balance += _value;
                        CoinSent(_from, _value, _to);
                        _success = true;
                        _success = true;
                    }
                    else _success = false;
                }

                function coinBalance() constant returns (uint _r) {
                    _r = accounts[msg.sender].balance;
                }

                function coinBalanceOf(address _addr) constant returns (uint _r) {
                    _r = accounts[_addr].balance;
                }

                function approve(address _addr) {
                    accounts[msg.sender].withdrawers[_addr] = 340282366920938463463374607431768211456;
                }

                function isApproved(address _proxy) returns (bool _r) {
                    _r = (accounts[msg.sender].withdrawers[_proxy] > 0);
                }

                function approveOnce(address _addr, uint256 _maxValue) {
                    accounts[msg.sender].withdrawers[_addr] += _maxValue;
                }

                function isApprovedOnceFor(address _target, address _proxy) returns (uint256 _r) {
                    _r = accounts[_target].withdrawers[_proxy];
                }

                function disapprove(address _addr) {
                    accounts[msg.sender].withdrawers[_addr] = 0;
                }
            }

Mein Vertrag abi :

    var currencyContract = web3.eth.contract([{"constant":false,"inputs":[{"name":"_addr","type":"address"}],"name":"disapprove","outputs":[],"type":"function"},{"constant":false,"inputs":[{"name":"_target","type":"address"},{"name":"_proxy","type":"address"}],"name":"isApprovedOnceFor","outputs":[{"name":"_r","type":"uint256"}],"type":"function"},{"constant":false,"inputs":[{"name":"_proxy","type":"address"}],"name":"isApproved","outputs":[{"name":"_r","type":"bool"}],"type":"function"},{"constant":false,"inputs":[{"name":"_from","type":"address"},{"name":"_value","type":"uint256"},{"name":"_to","type":"address"}],"name":"sendCoinFrom","outputs":[{"name":"_success","type":"bool"}],"type":"function"},{"constant":false,"inputs":[{"name":"_addr","type":"address"},{"name":"_maxValue","type":"uint256"}],"name":"approveOnce","outputs":[],"type":"function"},{"constant":true,"inputs":[{"name":"_addr","type":"address"}],"name":"coinBalanceOf","outputs":[{"name":"_r","type":"uint256"}],"type":"function"},{"constant":false,"inputs":[{"name":"_value","type":"uint256"},{"name":"_to","type":"address"}],"name":"sendCoin","outputs":[{"name":"_success","type":"bool"}],"type":"function"},{"constant":true,"inputs":[],"name":"coinBalance","outputs":[{"name":"_r","type":"uint256"}],"type":"function"},{"constant":false,"inputs":[{"name":"_addr","type":"address"}],"name":"approve","outputs":[],"type":"function"},{"inputs":[],"type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"name":"from","type":"address"},{"indexed":false,"name":"value","type":"uint256"},{"indexed":true,"name":"to","type":"address"}],"name":"CoinSent","type":"event"}]);

dann

var currency = currencyContract.at(["0x956440edc6115aab375ab1b96603b79376484d86"]);

Und immer wenn ich eine Methode aufrufe, bekomme ich den Fehler. (currency.coinBalance())

Go-Version go-Version go1.5.3 darwin/amd64

Es gibt eine Reihe von typografischen Problemen mit Ihrer Frage - es ist nicht klar, ob Sie Ihren Code für die Frage geändert haben oder ob das Problem in diesen Tippfehlern liegt. Sie geben beispielsweise die Vertragsadresse als Zeichenfolge „Adresse“ anstelle der eigentlichen Vertragsadresse an.
Es ist auch hilfreich, ein Beispiel des tatsächlichen Anrufs zu zeigen, auch wenn es zunächst nur foo mit einigen Parametern ist.
Ein Ausschnitt der Solidität oder einfach nur die Angabe, welche Typen der Vertrag akzeptieren sollte, wäre ebenfalls hilfreich.
Geben Sie vielleicht auch die Version des Go-Clients an, den Sie verwenden.
Aktualisiert! folgte zunächst diesen Anweisungen: github.com/ethereum/wiki/wiki/JavaScript-API#web3ethcontract

Antworten (1)

Ich habe herausgefunden, was ich in meinem Bereitstellungsprozess falsch gemacht habe und warum der Zugriff auf den Vertrag nach der Erstellung möglich ist, aber den Fehler mit der Adresse auslösen würde.

Es stellt sich heraus, dass dies nicht der Vertrag ABI ist:

var currencyContract = web3.eth.contract([{"constant":false,"inputs":[{"name":"_addr","type":"address"}],"name":"disapprove","outputs":[],"type":"function"},{"constant":false,"inputs":[{"name":"_target","type":"address"},{"name":"_proxy","type":"address"}],"name":"isApprovedOnceFor","outputs":[{"name":"_r","type":"uint256"}],"type":"function"},{"constant":false,"inputs":[{"name":"_proxy","type":"address"}],"name":"isApproved","outputs":[{"name":"_r","type":"bool"}],"type":"function"},{"constant":false,"inputs":[{"name":"_from","type":"address"},{"name":"_value","type":"uint256"},{"name":"_to","type":"address"}],"name":"sendCoinFrom","outputs":[{"name":"_success","type":"bool"}],"type":"function"},{"constant":false,"inputs":[{"name":"_addr","type":"address"},{"name":"_maxValue","type":"uint256"}],"name":"approveOnce","outputs":[],"type":"function"},{"constant":true,"inputs":[{"name":"_addr","type":"address"}],"name":"coinBalanceOf","outputs":[{"name":"_r","type":"uint256"}],"type":"function"},{"constant":false,"inputs":[{"name":"_value","type":"uint256"},{"name":"_to","type":"address"}],"name":"sendCoin","outputs":[{"name":"_success","type":"bool"}],"type":"function"},{"constant":true,"inputs":[],"name":"coinBalance","outputs":[{"name":"_r","type":"uint256"}],"type":"function"},{"constant":false,"inputs":[{"name":"_addr","type":"address"}],"name":"approve","outputs":[],"type":"function"},{"inputs":[],"type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"name":"from","type":"address"},{"indexed":false,"name":"value","type":"uint256"},{"indexed":true,"name":"to","type":"address"}],"name":"CoinSent","type":"event"}]);

Um das Problem zu beheben, musste ich Folgendes tun:

var MyContract = web3.eth.contract(currencyContract. abi );

MeinVertrag.at("0xADRESSE")

Bitte klären / bearbeiten Sie die Antwort. Welchen Wert hat currencyContractvorher var MyContract = web3.eth.contract(currencyContract.abi);?
der im OP nach "Mein Vertrag abi:"
Die Antwort wäre eigentlich klarer, wenn sie lautete: var MyContract = web3.eth.contract(<put correct abi here>); . (Warum zweimal anrufen, web3.eth.contractwenn ein einziger reicht)