Getting web3 eth filter is not a function while trying to monitor Ethereum blocks

0 votes

I'm trying to monitor for the 12th confirmation using web3. I use the following code:

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");
                }
            })
        }
    }
});

however this throws the error web3.eth.filter is not a function

Oct 9, 2018 in Blockchain by slayer
• 29,300 points
934 views

1 answer to this question.

0 votes

It appears you are using web3.js v1.0. The way to subscribe to new block header information in v1 is web3.eth.subscribe('newBlockHeaders', callback);

For more information, see the docs.

answered Oct 9, 2018 by Omkar
• 69,110 points

Related Questions In Blockchain

0 votes
1 answer

Why is it downloading the blocks when I am trying to deploy the ethereum private network?

Once you have installed the Ethereum wallet, ...READ MORE

answered May 3, 2018 in Blockchain by Shashank
• 10,400 points
133 views
0 votes
1 answer
+1 vote
1 answer
0 votes
1 answer

Truffle tests not running after truffle init

This was a bug. They've fixed it. ...READ MORE

answered Sep 11, 2018 in Blockchain by Christine
• 15,830 points
555 views
0 votes
1 answer
+3 votes
2 answers

How to run ethereumjs using Node.JS

You need to install testrpc globally on ...READ MORE

answered Mar 27, 2018 in Blockchain by ned_crew
• 1,610 points
383 views
0 votes
2 answers

Why is network already up to date while trying to deploy a contract on truffle?

I guess you have ganache running already ...READ MORE

answered Apr 23, 2018 in Blockchain by Shashank
• 10,400 points
1,274 views
0 votes
1 answer

TypeError: XMLHttpRequest is not a function when using web3 on meteor server side

I had the same problem. Instead ethereum:web3 Meteor package ...READ MORE

answered Oct 10, 2018 in Blockchain by Omkar
• 69,110 points
311 views