首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >web3.eth.subscribe不工作吗?

web3.eth.subscribe不工作吗?
EN

Ethereum用户
提问于 2017-10-05 23:23:37
回答 2查看 2.1K关注 0票数 5

使用websocket运行geth:

代码语言:javascript
复制
geth --fast --cache=512 --ws --wsorigins="*" --wsapi "db,eth,net,ssh,miner,web3,personal,admin"

然后在一个web3应用程序中连接Node.js:

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

var web3 = new Web3(new Web3.providers.WebsocketProvider("ws://localhost:8546"));

console.log(web3.version);

web3.eth.subscribe('pendingTransactions', function(err, res) {
    console.log('Here')
    console.log(err)
    console.log(res)
}).on('data', function(transaction) {
    console.log('Here 2')
    console.log(transaction)
});

“这里”、“这里2”不要打印到控制台。订阅似乎没有激活。web3.version和其他web3命令可以正常工作。

Geth版本:1.7.1-稳定

Web3版本: 1.0.0-beta.22

EN

回答 2

Ethereum用户

发布于 2018-05-11 04:19:07

请确保你是同步的。虽然geth正在快速同步,但是链是不完整的,所以没有任何事件被触发,因为还没有存在的事件。只有当链完全同步时,事件才会开始出现。

票数 1
EN

Ethereum用户

发布于 2018-05-15 05:30:34

您正在尝试获取挂起的事务,因此事件可能不会被触发,只有当事务挖掘成功时,事件才会被触发,在您的情况下,链始终是不完整的,因为您只是在调用挂起的事务。

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

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

复制
相关文章

相似问题

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