Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Blockchain by (12.7k points)

I am getting the following error on compiling the code with:-

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

solc = require('solc')

compiledCode = solc.compile(code)

It throws out this error:-

'{"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"}]}'

1 Answer

0 votes
by (29.5k points)

Hi there could be various reasons behind this, you should consider checking the following

  • npm version conflicts. Make sure that you have the right version of solc.
  •  File.sol was raw solidity smart contract, but you need to put Compiler Standard Input JSON into solc.compile()
  • You have to specify what type of encoding is used for the solidity file.

        code = fs.readFileSync('Voting.sol', 'utf8');

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...