用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
使用node编译sol文件报错

后来我给变量改了个名字,如下:

contractABI = JSON.parse(compiledCode.contracts[’:Voting’].interface);
contractByteode = compiledCode.contracts[’:Voting’].bytecode;

没有再报错,不清楚为什么会这样。

相关文章:

  • 2021-06-30
  • 2022-01-17
  • 2021-08-07
  • 2021-11-24
  • 2021-11-05
  • 2022-01-20
  • 2021-06-26
  • 2021-11-10
猜你喜欢
  • 2022-01-19
  • 2022-12-23
  • 2021-11-25
  • 2021-08-26
  • 2021-09-28
  • 2021-05-16
  • 2022-02-23
相关资源
相似解决方案