web3 - новый BigNumber() не является базовым числом 16 при вызове постоянной функции контракта

Я борюсь с простым контрактом hello world:

Договор:

pragma solidity ^0.4.4;

contract Greeter {

    function Greeter() {}

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

web3 - код Javascript:

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);

Вызов contractInstance.sayHello.call();заканчивается этой ошибкой:

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)

ОБНОВЛЯТЬ:

Я вижу POST для моего экземпляра testrpc ( http://localhost:8545/) с этой полезной нагрузкой:

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

Вот результат вызова:

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

Ответы (2)

Вам нужно обещание (представляет результат асинхронной операции)

С call().then(...

http://truffleframework.com/docs/getting_started/contracts#вызов

Привет! Я звоню из браузера, а не из консоли трюфеля. Во всяком случае, я попытался с обещанием, и ошибка та же:contractInstance.sayHello.call().then(function(result){ alert(result); });
Хорошо, нет проблем, возможно, вам следует принять свой собственный ответ, чтобы предложить решение :) Добрый день!

Проблема заключалась в том, что я использовал не адрес контракта, а одну из автоматически созданных учетных записей, созданных testrcp.

Мне просто пришлось изменить его на адрес, полученный при развертывании контракта:

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