首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >NodeJS3.10.9,installation web3,ReferenceError: web3未定义

NodeJS3.10.9,installation web3,ReferenceError: web3未定义
EN

Ethereum用户
提问于 2016-10-24 16:01:44
回答 2查看 3.2K关注 0票数 3

我在跑:

  • nodejs 3.10.9
  • geth 1.4.18-稳定-c72f5459

我做了折叠的步骤:

  1. 运行geth --testnet --rpc
  2. 通过web3通过npm install web3 -g安装。
  3. 运行node (控制台)
  4. 当我在节点控制台运行时:console.log(web3);

我知道错误:

代码语言:javascript
复制
ReferenceError: web3 is not defined
at repl:1:1
at REPLServer.defaultEval (repl.js:262:27)
at bound (domain.js:287:14)
at REPLServer.runBound [as eval] (domain.js:300:12)
at REPLServer.<anonymous> (repl.js:431:12)
at emitOne (events.js:82:20)
at REPLServer.emit (events.js:169:7)
at REPLServer.Interface._onLine (readline.js:211:10)
at REPLServer.Interface._line (readline.js:550:8)
at REPLServer.Interface._ttyWrite (readline.js:827:14)

当我在节点控制台中运行require('web3')时,我会得到相同的错误。

我还尝试安装没有web3的-g (npm install web3);同样的结果。

我做错了什么?为什么在通过web3安装之后,节点无法识别npm install web3 -g

我试图按照以下线程进行安装:如何将NodeJS连接到Ethereum网络?

和文档:https://www.npmjs.com/package/web3

EN

回答 2

Ethereum用户

发布于 2016-10-24 16:20:04

您需要先实例化它。在节点类型中的npm install web3之后:

代码语言:javascript
复制
var web3 = require('web3');

然后console.log(web3)将输出

代码语言:javascript
复制
{ [Function: Web3]
  providers: { HttpProvider: [Function], IpcProvider: [Function] } }
undefined

欲了解更多信息,请阅读:https://www.npmjs.com/package/web3

票数 4
EN

Ethereum用户

发布于 2016-10-24 16:16:40

Windows问题,NODE_PATH没有正确指向节点模块目录。现在起作用了。

票数 1
EN
页面原文内容由Ethereum提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://ethereum.stackexchange.com/questions/9565

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档