node.js - npm solc : AssertionError [ERR_ASSERTION]: Invalid callback specified

标签 node.js npm ethereum solidity

我正在尝试使用 npm solc 编译 solidity 智能合约。我试图遵循不同的例子。 示例链接:https://medium.com/coinmonks/how-to-compile-a-solidity-smart-contract-using-node-js-51ea7c6bf440

我的代码如下:

const path = require('path');
const fs = require('fs');
const solc = require('solc');



const helloPath = path.resolve(__dirname, 'contracts', 'hello.sol');
console.log("First" + helloPath);
const source = fs.readFileSync(helloPath, 'UTF-8');
console.log("Second" + source);
console.log(solc.compile(source, 1));

运行上述代码时出现以下错误。

AssertionError [ERR_ASSERTION]: Invalid callback specified.
    at wrapCallback (C:\Users\mouazzamj058\solc_example\node_modules\solc\wrapper.js:16:5)
    at runWithReadCallback (C:\Users\mouazzamj058\solc_example\node_modules\solc\wrapper.js:37:42)
    at compileStandard (C:\Users\mouazzamj058\solc_example\node_modules\solc\wrapper.js:78:14)
    at Object.compileStandardWrapper (C:\Users\mouazzamj058\solc_example\node_modules\solc\wrapper.js:85:14)
    at Object.<anonymous> (C:\Users\mouazzamj058\solc_example\example.js:4:19)
    at Module._compile (module.js:652:30)
    at Object.Module._extensions..js (module.js:663:10)
    at Module.load (module.js:565:32)
    at tryModuleLoad (module.js:505:12)
    at Function.Module._load (module.js:497:3)

请帮忙。

最佳答案

您使用的是哪个版本的 solc?

前几天solc发布了一个破解版,这个错误与此有关。

npm uninstall solc
npm install solc@0.4.25

关于node.js - npm solc : AssertionError [ERR_ASSERTION]: Invalid callback specified,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53353167/

相关文章:

javascript - 使用 Passport 使用 NodeJs mongodb(mongoose) Express 进行注册表单

node.js - 部署不同环境时如何更改admin.initializeApp

javascript - 当通配符匹配时, Node 快速 GET 路由会失败所有其他请求

node.js - Node 命令行工具未在 vagrant 上编译

angular - 如何使用深度相等(Angular 7)

ethereum - 如何让合约从账户中获取以太币

javascript - eccrypto.getPublic() 不适用于 "custom"私钥

node.js - 带有字符串而不是数组的nodejs spawn命令?

angular - 升级到最新版本后,ng-select 下拉菜单在 UI 上中断 - Angular 6

ethereum - 基于合约的钱包和钱包中的主账户有什么区别?