3

I'm attempting to compile the following contract using geth console attached to a testrpc instance:

contract UnitCounter {
    mapping (address => uint256) public UnitsFrom;
    uint256 public TotalUnits;

    function submitUnits(uint256 Units) {
        UnitsFrom[msg.sender] = Units;
        TotalUnits += Units;
    }
}

After running testrpc and connecting:

testrpc -a 1000

I attached a geth cosole

geth attach rpc:http://localhost:8545

and did the following:

> eth.getCompilers()
["solidity"]
> co=eth.compile.solidity("contract UnitCounter {mapping (address => uint256) public UnitsFrom;uint256 public TotalUnits;function SubmitUnits(uint256 Units) {UnitsFrom[msg.sender] = Units;TotalUnits += Units;}}")

Which gives this error:

Error: Invalid JSON RPC response: {"error":{"code":-32603,"json: cannot unmarshal array into Go value of type string":"json: cannot unmarshal array into Go value of type string"},"id":11,"version":"2.0"}
    at web3.js:3119:20
    at web3.js:6023:15
    at web3.js:4995:36
    at <anonymous>:1:4  

What does this error mean? What steps should I take to debug?

1
  • 2
    This smells like geth bug, as JSON-RPC calls should convert everything to JSON before returning. Try use solc command line version to compile your contract locally. Here are some examples: tokenmarket.net/blog/… – Mikko Ohtamaa Jan 7 '17 at 3:45
2

You can use tcpdump to intercept communication between geth and testrpc.

This will dump all packets going through loopback interface lo from/to port 8545:

$ sudo tcpdump -A -i lo port 8545

Now you can run eth.compile.solidity(..) command in geth console and get JSON-RPC request and response:

request

{
  "jsonrpc": "2.0",
  "id": 14,
  "method": "eth_compileSolidity",
  "params": [
    "contract UnitCounter {mapping (address => uint256) public UnitsFrom;uint256 public TotalUnits;function SubmitUnits(uint256 Units) {UnitsFrom[msg.sender] = Units;TotalUnits += Units;}}"
  ]
}

response

{
  "id": 14,
  "jsonrpc": "2.0",
  "error": {
    "message": [
      ":1:1: Warning: Source file does not specify required compiler version!Consider adding \"pragma solidity ^0.4.4\ncontract UnitCounter {mapping (address => uint256) public UnitsFrom;uint256 public TotalUnits;function SubmitUnits(uint256 Units) {UnitsFrom[msg.sender] = Units;TotalUnits += Units;}}\n^-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------^\n"
    ],
    "code": -32000
  }
}

Form here you can see that:

  • actual error is missing pragma solidity ^0.4.4; in your code
  • testrpc returns malformed response (error.message must be a string but array is provided, see JSON-RPC spec)
    • this is fixed in provider-engine@8.1.18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.