Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/cmake/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js Web3如何订阅活动?无法读取属性';currentProvider';未定义的_Node.js_Events_Ethereum_Smartcontracts_Web3 - Fatal编程技术网

Node.js Web3如何订阅活动?无法读取属性';currentProvider';未定义的

Node.js Web3如何订阅活动?无法读取属性';currentProvider';未定义的,node.js,events,ethereum,smartcontracts,web3,Node.js,Events,Ethereum,Smartcontracts,Web3,尝试订阅私有以太坊区块链上的事件时,我收到以下错误消息: 无法读取未定义的属性“currentProvider” 设置Web3: const Web3=require(“Web3”); this.web3=新的web3(web3.givenProvider | |“ws://localhost:8545”) 作品: this.factoryContract.getPastEvents( "allEvents", { fromBlock: 0, toBlock: "late

尝试订阅私有以太坊区块链上的事件时,我收到以下错误消息:

无法读取未定义的属性“currentProvider”

设置Web3:

const Web3=require(“Web3”);
this.web3=新的web3(web3.givenProvider | |“ws://localhost:8545”)

作品:

this.factoryContract.getPastEvents(
  "allEvents",
  {
    fromBlock: 0,
    toBlock: "latest"
  },
  (err, events) => {
    console.log(events);
  }
);
抛出错误:

this.factoryContract.events
  .allEvents(
    {
      fromBlock: 0
    },
    (error, event) => {
      console.log(event);
    }
  )
  .on("data", event => {
    console.log(event);
  });

  this.factoryContract.events
  .TaskCreated(
    {
      fromBlock: 0
    },
    (error, event) => {
      console.log(event);
    }
  );
有没有办法解决这个问题/错误是什么

节点版本:10.14.2
Web3:1.0.0

此问题是当前Web3 1.0.0.51版本的问题,应该在下一版本中修复。

您使用什么来运行您的私有以太坊区块链?@foba ganache。已尝试更改web 3的设置,以确保ganache用作websocket提供程序,但仍无法正常工作