使用websocket运行geth:
geth --fast --cache=512 --ws --wsorigins="*" --wsapi "db,eth,net,ssh,miner,web3,personal,admin"然后在一个web3应用程序中连接Node.js:
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
发布于 2018-05-11 04:19:07
请确保你是同步的。虽然geth正在快速同步,但是链是不完整的,所以没有任何事件被触发,因为还没有存在的事件。只有当链完全同步时,事件才会开始出现。
发布于 2018-05-15 05:30:34
您正在尝试获取挂起的事务,因此事件可能不会被触发,只有当事务挖掘成功时,事件才会被触发,在您的情况下,链始终是不完整的,因为您只是在调用挂起的事务。
https://ethereum.stackexchange.com/questions/27882
复制相似问题