I have an issue when I try to call a contract in my local ethereum with web3. I have tried I lot of things but i'm stuck.
Web3 version: 0.18.2
My smart contract
pragma solidity ^0.4.2;
contract Test{
function greet() constant returns(string) {
return "HELLO WORLD!";
}
}
My code :
var myContract = web3.eth.contract(contract.abi)
var instance = myContract.at([contract.contractAddress]);
exports.unlockAccount(account.address, account.password);
instance.greet.call({from:account.address}, function(err, receipt) {
if (!err) {
console.log("Receipt: " + receipt);`enter code here`
observer.onNext(web3.toDecimal(receipt));
observer.onCompleted();
} else {
console.log(err);
observer.onCompleted();
}
});
My API:
[{"constant":true,"inputs":[],"name":"greet","outputs:[{"name":"","type":"string"}],"payable":false,"type":"function"}]
My error:
Error: invalid argument 0: cannot unmarshal non-string as hex data
at Object.InvalidResponse (C:\Utilisateurs\Documents\Git\poc-blockch
ain-server\myapp\node_modules\web3\lib\web3\errors.js:35:16)
at RequestManager.send (C:\Utilisateurs\Documents\Git\poc-blockchain
-server\myapp\node_modules\web3\lib\web3\requestmanager.js:61:22)
at Eth.send (C:\Utilisateurs\Documents\Git\poc-blockchain-server\mya
pp\node_modules\web3\lib\web3\method.js:145:58)
at SolidityFunction.call (C:\Utilisateurs\Documents\Git\poc-blockcha
in-server\myapp\node_modules\web3\lib\web3\function.js:113:32)
at AnonymousObservable.__subscribe (C:/Utilisateurs//Documents/Git/po
c-blockchain-server/myapp/controller/web3Functions.js:25:40)
at AnonymousObservable.tryCatcher (C:\Utilisateurs\Documents\Git\poc
-blockchain-server\myapp\node_modules\rx\dist\rx.js:63:31)
at Rx.internals.ScheduledItem.setDisposable [as action] (C:\Utilisateurs\Documents\Git\poc-blockchain-server\myapp\node_modules\rx\dist\rx.js:5845:4
4)
at Rx.internals.ScheduledItem.ScheduledItem.invokeCore (C:\Utilisateurs\Documents\Git\poc-blockchain-server\myapp\node_modules\rx\dist\rx.js:896:33)at Rx.internals.ScheduledItem.ScheduledItem.invoke (C:\Utilisateurs\\
Documents\Git\poc-blockchain-server\myapp\node_modules\rx\dist\rx.js:884:40)
at runTrampoline (C:\Utilisateurs\Documents\Git\poc-blockchain-serve
r\myapp\node_modules\rx\dist\rx.js:1125:37)