3

Everything was working fine until today that when I try to use readFileSync it gives me [Function] for every kind of file. In my example when I try to compile the contract it gives me

'Error parsing input JSON: * Line 1, Column 1\n Syntax error: value, object or array expected.\n'

> code = fs.readFileSync('Voting.sol').toString
[Function]

> compiledCode = solc.compile(code)
{ errors: [ 'Error parsing input JSON: * Line 1, Column 1\n  Syntax error: value, object or array expected.\n' ] }

I reinstall nodejs and npm but still I get the same error. Any help?

2

This returns a function:

fs.readFileSync('Voting.sol').toString

while this calls the function:

fs.readFileSync('Voting.sol').toString();

and returns not the function but the value returned by the function.

What your code did was saving the reference to the function itself in the code variable and passing it to the solc.compile() which expected a string and implicitly converted the function to a string, which in turn resulted in getting the function's source code and trying to parse it, which failed.

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.