web3 - new BigNumber() ist keine Basis-16-Zahl, wenn eine Vertragskonstantenfunktion aufgerufen wird

Ich kämpfe mit einem einfachen Hallo-Welt-Vertrag:

Vertrag:

pragma solidity ^0.4.4;

contract Greeter {

    function Greeter() {}

    function sayHello() constant returns(string) {
        return "hello";
    }
}

web3 - Javascript-Code:

if (typeof web3 !== 'undefined') {
  web3 = new Web3(web3.currentProvider);
} else {
  // set the provider you want from Web3.providers
  web3 = new Web3(new Web3.providers.HttpProvider("http://localhost:8545"));
}

var contractArray = JSON.parse('{"contract_name": "Greeter","abi": [{"constant": false,"inputs": [],"name": "sayHello","outputs": [{"name": "","type": "string"}],"payable": false,"type": "function"},{"inputs": [],"payable": false,"type": "constructor"}],"unlinked_binary": "0x6060604052341561000c57fe5b5b5b5b6101118061001e6000396000f300606060405263ffffffff60e060020a600035041663ef5fb05b81146020575bfe5b3415602757fe5b602d60a9565b6040805160208082528351818301528351919283929083019185019080838382156070575b805182526020831115607057601f1990920191602091820191016052565b505050905090810190601f168015609b5780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b60af60d3565b50604080518082019091526005815260d860020a6468656c6c6f0260208201525b90565b604080516020810190915260008152905600a165627a7a723058205c8157cef185e2881f9f3c49092242ef4418bb30363100e00c373e157ebb6a540029","networks": {"1496042639874": {"events": {},"links": {},"address": "0xc90f7594a02ecc8fe27dad58023537da569ebbc6","updated_at": 1496042652979}},"schema_version": "0.0.5","updated_at": 1496042652979}');

var MyContract = web3.eth.contract(contractArray.abi);
var contractAddress = '0x95c9aa274cc63ec2a0b52f1b19e0e67c3d059194';
var contractInstance = MyContract.at(contractAddress);

var result = contractInstance.sayHello.call();
console.log(result);

Der Aufruf contractInstance.sayHello.call();löst diesen Fehler aus:

bignumber.js:1190 Uncaught Error: new BigNumber() not a base 16 number: 
    at raise (http://localhost:3000/bower_components/web3/dist/web3.js:14728:25)
    at http://localhost:3000/bower_components/web3/dist/web3.js:14716:33
    at new BigNumber (http://localhost:3000/bower_components/web3/dist/web3.js:13750:28)
    at SolidityTypeString.formatOutputString [as _outputFormatter] (http://localhost:3000/bower_components/web3/dist/web3.js:1110:19)
    at http://localhost:3000/bower_components/web3/dist/web3.js:1634:25
    at SolidityTypeString.SolidityType.decode (http://localhost:3000/bower_components/web3/dist/web3.js:1635:11)
    at http://localhost:3000/bower_components/web3/dist/web3.js:826:29
    at Array.map (native)
    at SolidityCoder.decodeParams (http://localhost:3000/bower_components/web3/dist/web3.js:825:26)
    at SolidityFunction.unpackOutput (http://localhost:3000/bower_components/web3/dist/web3.js:4064:24)

AKTUALISIEREN:

Ich sehe einen POST an meine testrpc-Instanz ( http://localhost:8545/) mit dieser Nutzlast:

{"jsonrpc":"2.0","id":1,"method":"eth_call","params":[{"to":"0x95c9aa274cc63ec2a0b52f1b19e0e67c3d059194","data":"0xef5fb05b"},"latest"]}

Das ist das Ergebnis des Aufrufs:

{"id":1,"jsonrpc":"2.0","result":"0x"}

Antworten (2)

Sie benötigen ein Promise (repräsentiert das Ergebnis einer asynchronen Operation)

Mit call().then(...

http://truffleframework.com/docs/getting_started/contracts#making-a-call

Hallo! Ich rufe vom Browser aus an, nicht von der Truffle-Konsole. Jedenfalls habe ich es mit einem Versprechen versucht und der Fehler ist derselbe:contractInstance.sayHello.call().then(function(result){ alert(result); });
Ok, kein Problem, vielleicht sollten Sie Ihre eigene Antwort akzeptieren, um die Lösung vorzuschlagen :) Guten Tag!

Das Problem war, dass ich nicht die Adresse des Vertrags verwendet habe, sondern eines der automatisch erstellten Konten, die von testrcp erstellt wurden.

Ich musste es einfach in die Adresse ändern, die ich bei der Bereitstellung des Vertrags erhalten habe:

Running migration: 2_deploy_contracts.js
  Deploying Greeter...
  Greeter: 0x5b0b6ec4fdb542210bcfc9bc7a278a4dd6d40e0c
Saving successful migration to network...
Saving artifacts...