微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

为什么我不能运行 node compile.js?

如何解决为什么我不能运行 node compile.js?

我为正在编写的智能合约编写了一个 compile.js 文件(出于教育目的),但是当我使用 node compile.js 命令运行它时,我收到一个错误消息,显示 ReferenceError: compile is not defined

我在 Sublime Text 3 (windows 10) 中使用了 solidity ^0.4.17

这是它的样子:

C:\Users\zakja\Desktop\inBox>node compile.js
C:\Users\zakja\Desktop\inBox\compile.js:1
compile.js
^

ReferenceError: compile is not defined
    at Object.<anonymous> (C:\Users\zakja\Desktop\inBox\compile.js:1:1)
←[90m    at Module._compile (internal/modules/cjs/loader.js:1063:30)←[39m
←[90m    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)←[39m
←[90m    at Module.load (internal/modules/cjs/loader.js:928:32)←[39m
←[90m    at Function.Module._load (internal/modules/cjs/loader.js:769:14)←[39m
←[90m    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:72:12)←[39m
←[90m    at internal/main/run_main_module.js:17:47←[39m

下面是compile.js文件

compile.js
const path = require('path');
const fs = require('fs');
const solc = require('solc');

const inBoxPath = path.resolve(__dirname,'contracts','InBox.sol');
const source = fs.readFileSync(inBoxPath,'utf8');


console.log(solc.compile(source,1));


Any help is appreciated. (Note: Newbie here)

解决方法

第一行是你的文件是'compile.js'文件的名字。如果是,则删除第一行。您不需要文件名作为文件中的内容。删除第一行并运行。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。