ethereum - 尝试监控以太坊区块时获取“web3.eth.filter 不是功能”
问题描述
我正在尝试使用 web3 监视第 12 次确认。我使用以下代码:
let filter = web3.eth.filter('latest',
filter.watch(function(error, result) {
if (!error) {
let confirmedBlock = web3.eth.getBlock(web3.eth.blockNumber - 11)
if (confirmedBlock.transactions.length > 0) {
confirmedBlock.transactions.forEach(function(txId) {
let transaction = web3.eth.getTransaction(txId)
if (transaction.to == account) {
// Do something useful.
console.log("12 confirmations received");
}
})
}
}
});
但是这会引发错误web3.eth.filter is not a function
。
解决方案
看来您正在使用 web3.js v1.0。v1中订阅新区块头信息的方式是web3.eth.subscribe('newBlockHeaders', callback);
有关更多信息,请参阅文档。
推荐阅读
- spring - 当我提交注册表时,它不会执行 post 控制器
- javascript - 如何从调用函数之外的axios响应中获取数据
- mysql - WINDOWS 上的 MySQL LOAD DATA LOCAL INFILE 不工作
- watchos - 如何在 watchOS 5 上使用 WebKit?
- ios - 如何阅读“com.apple.configuration.managed”使用 MDM 通过 UserDefaults 配置企业应用程序 - Swift 3 或 4
- websphere - uid=wpadmin 的身份验证失败
- cordova - Cordova (PhoneGap) 是否在应用程序内保存页面?
- c# - 如何使用 ExcelDataReader 从文件中删除空单元格和行?
- php - Laravel 存储 GET 参数以重定向回来
- haproxy - 使用后端 ssl 服务器进行 HAProxy 运行状况检查