Ethereum web3 Error invalid argument 0 cannot unmarshal non-string as hex data when I call a contract

0 votes

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)
Oct 8, 2018 in Blockchain by digger
• 26,740 points
1,966 views

1 answer to this question.

0 votes

I have the same problem. But with the newer version 0.18.4 the problem is the converted json-rcp call. It converts only the method name to the data attribute. The 64 zeros are missing:

{"jsonrpc":"2.0",
 "id":6,
 "method":"eth_call",
 "params":[{"to":["0xb8a8b5161dfb893f903b003358579d4d6db35b77"],
            "data":"0xcfae3217"},
            "latest"]}

the "data":"0xcfae3217" should be followed by 64 zeros.

The call to the contract works if I call it direct over the web3.eth.call method:

var result = this.getWeb3().eth.call({
            to: "0xb8a8b5161dfb893f903b003358579d4d6db35b77",
            data: "0xcfae32170000000000000000000000000000000000000000000000000000000000000000"
        });
answered Oct 8, 2018 by Omkar
• 69,220 points

Related Questions In Blockchain

0 votes
1 answer

Web3 1.0: What does `web3.eth.call(tx)` return for a contract creation?

The returned bytestring is the deployedBytecode of the contract, ...READ MORE

answered Sep 17, 2018 in Blockchain by digger
• 26,740 points
1,220 views
0 votes
1 answer

Can a hacker change data of a smart sontract without call contract function?

A contract's content cannot be changed internally. ...READ MORE

answered Apr 8, 2018 in Blockchain by Shashank
• 10,400 points
683 views
0 votes
1 answer

How do I withdraw the balance from a contract on Ethereum test blockchain?

Your need to improvise your code a ...READ MORE

answered Aug 3, 2018 in Blockchain by Perry
• 17,100 points
2,663 views
0 votes
1 answer

Truffle tests not running after truffle init

This was a bug. They've fixed it. ...READ MORE

answered Sep 11, 2018 in Blockchain by Christine
• 15,790 points
1,923 views
0 votes
1 answer

Hyperledger Sawtooth vs Quorum in concurrency and speed Ask

Summary: Both should provide similar reliability of ...READ MORE

answered Sep 26, 2018 in IoT (Internet of Things) by Upasana
• 8,620 points
1,451 views
+3 votes
2 answers

How to run ethereumjs using Node.JS

You need to install testrpc globally on ...READ MORE

answered Mar 27, 2018 in Blockchain by ned_crew
• 1,610 points
1,414 views
+1 vote
2 answers

Can I include real world data in a smart contract? If so, how?

You cant access/embed real world data using ...READ MORE

answered Jul 18, 2018 in Blockchain by sapan
1,162 views
0 votes
2 answers

How do I interact with a smart contract on a private network through web3.js

I found a blog that explains how ...READ MORE

answered Aug 20, 2018 in Blockchain by slayer
• 29,370 points
3,951 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP