使用node编译sol文件报错
用node编译sol文件时报错:
{“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”}]}
原因:solc版本错误。我使用的是0.6.6,代码中写的是^0.4.25
进行如下操作:
npm uninstall solc
npm install [email protected]
编译成功。
还有一个比较奇怪的问题是,我在编译完sol文件后,需要其中的interface和bytecode,运行以下命令:
var abi = JSON.parse(compiledCode.contracts[’:Voting’].interface);
var byteCode = compiledCode.contracts[’:Voting’].bytecode;
会突然报错,出现一大串数字,然后退出node
后来我给变量改了个名字,如下:
contractABI = JSON.parse(compiledCode.contracts[’:Voting’].interface);
contractByteode = compiledCode.contracts[’:Voting’].bytecode;
没有再报错,不清楚为什么会这样。