Go Ethereum – How to Get the List of Incoming Pending Transactions with Web3

go-ethereum

I would like to verify if somebody send ETH to a particular address. How can I get the list of incoming (pending) transactions with web3 ?

I tried the example in the web3 documentation with subscribe(“pendingTransactions”):

http://web3js.readthedocs.io/en/1.0/web3-eth-subscribe.html#id7

var subscription = web3.eth.subscribe('pendingTransactions', function(error, result){
    if (!error)
        console.log(transaction);
})
.on("data", function(transaction){
});

But I get the following error:
TypeError: web3.eth.subscribe is not a function

Is there a way to get that list ?

Best Answer

There is a filter function in web3 javascript API and you can get pending txs by it. A simple print script as follows:

web3.eth.filter("pending").watch(
    function(error,result){
        if (!error) {
            console.log(result);
        }
    }
)

Hope it helps~