【问题标题】:Setting up web3 with Geth使用 Geth 设置 web3
【发布时间】:2018-04-30 21:36:59
【问题描述】:

我一直在尝试设置我的 dapp,但没有找到任何可以彻底解释它的资源。我想使用 Geth 和 web3 将我的应用程序连接到以太坊。到目前为止,我的 index.js 文件如下所示:

var Web3 = require('web3')

 if (typeof web3 !== 'undefined') {
   web3 = new Web3(web3.currentProvider)
 } else {
   web3 = new Web3(new 
   Web3.providers.HttpProvider('http://localhost:8545'))
 }

然后我输入:

geth --testnet --rpc

在我的命令行中启动节点。我有一个运行 geth 并同时编译 index.js 的 npm 脚本。有什么我想念的吗?我还有一个问题。使用 ES6 模块 (import ... from ...) 导入 web3 的正确方法是什么?提前谢谢你!

【问题讨论】:

  • --rpccorsdomain "*" 错过

标签: ethereum web3 geth


【解决方案1】:

我推荐这个命令

geth --rpc --rpcaddr 0.0.0.0 --rpcport 8545 --rpccorsdomain "*" console

geth 有很多选项,因此您应该阅读 geth 文档。

【讨论】:

  • --rpcaddr 0.0.0.0 使用起来很危险
猜你喜欢
  • 2019-01-26
  • 2020-12-27
  • 2023-01-15
  • 2018-10-01
  • 2021-10-06
  • 2021-09-29
  • 1970-01-01
  • 2022-08-16
  • 2019-05-23
相关资源
最近更新 更多