I am attempting to compile the following solidity code using solc in NodeJS.

pragma solidity ^0.4.11;

contract helloWorld {

  string public message;

  function constructor() public{
    message = "Hello World";

  function sayHi() constant public returns (string){
    return message;

The commands I've written in NodeJS to do this are:

var source = `source code above`
var compiled = solc.compile(source)

When I look at the 'compiled' object, I see the following errors:

   { errors:
      [ ':5:3: Error: Type "string" not supported for state variable.\n  string public message;\n  ^-------------------^\n' ] },
  sourceList: [ '' ],
  sources: { '': { AST: [Object] } } }

I have a working TestRPC instance open, and can run web3.eth.accounts from the node console to this TestRPC instance (over port 8485). The code compiles correctly in Remix. I'm following a guide on getting these libraries working on a windows computer, so I don't see why anything could be incompatible with one another.

The versions I am using are

  • solc - 0.4.11
  • web3 - 0.19.0
  • Could you try updating your compiler (solc), and change pragma solidity ^0.4.11; to pragma solidity ^0.4.22; (the latest version) Commented Apr 18, 2018 at 13:14

1 Answer 1


The error you getting are from the function

publicsayHi() constant public returns (string)

~~~I think Solidity function cannot return type string.~~~ (I was wrong about this)

  • 1
    This is incorrect, Solidity functions can return strings Commented Apr 18, 2018 at 13:06
  • You are right. But why the error said. Error: Type "string" not supported for state variable.
    – Geeroz
    Commented Apr 18, 2018 at 13:10
  • There are several sources on the web where people return strings, such as this one forum.ethereum.org/discussion/8053/… Commented Apr 18, 2018 at 13:11
  • I don't know, but I'm guessing possibly because it's an old verison of the compiler. Commented Apr 18, 2018 at 13:13
  • I spot something. function constructor() public Should this be function helloWorld() public ?
    – Geeroz
    Commented Apr 18, 2018 at 13:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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