I want to compile my ethereum HelloWorld.sol smart contract. In all the tutorials is that you do it like this:
var solc = require('solc');
var compiledContract = solc.compile(fs.readFileSync('HelloWorld.sol').toString();
where HelloWorld.sol is:
pragma solidity ^0.5.1;
contract HelloWorld {
bytes32 message;
constructor(bytes32 myMessage) public {
message = myMessage;
}
function getMessage() public view returns(bytes32){
return message;
}
}
In other words, I put my raw Solidity contract code into the solc.compile() method. But this process gives me this error in compiledContract
:
'{"errors":[{"component":"general","formattedMessage":"* Line 1, Column 1\\n Syntax error: value, object or array expected.\\n* Line 1, Column 2\\n Extra non-whitespace after JSON value.\\n","message":"* Line 1, Column 1\\n Syntax error: value, object or array expected.\\n* Line 1, Column 2\\n Extra non-whitespace after JSON value.\\n","severity":"error","type":"JSONError"}]}'
I was looking for a solution for quite a long time, but the only thing I found is that
"The high-level API consists of a single method, compile, which expects the Compiler Standard Input and Output JSON."
(link). The standard input JSON looks like some combination of JSON and this solidity code. So my question is -
How to transfer the solidity contract code into a compiler standard input JSON?
Am I correct that this is the only way how to compile the contract?