Categories
Cryptocurrency Ethereum Mastering Development

the best way to monitor my own account transactions in openethereum

Please I want to know if I subscribe to pendingTransactions with web3 will it monitor and send notifications of accounts pending Transactions only or all pending transactions on Ethereum network. my project requires users to create Ethereum address now I need to monitor incoming transaction of each user address to complete their services


var Web3 = require('web3')
var Web3WsProvider = require('web3-providers-ws')

var web3 = new Web3(new Web3WsProvider('ws://localhost:8547'))

web3.eth.subscribe('pendingTransactions', function (error, result) {
        
    }).on("connected", function (subscriptionId) {
                            console.log('subscriptionId :>> ', subscriptionId);
                        })
                        .on("data", function (transactionHash) {
                            web3.eth.getTransaction(transactionHash)
                                .then(function (transaction) {
                                });
                            
                        })
                        .on("error", console.error);

web3.eth.subscribe('newBlockHeaders', function (error, result) {

            console.error(error);
        })
        .on("connected", function (subscriptionId) {
            console.log('subscriptionId :>> ', subscriptionId);
        }).on("data", (blockHeader) => {
            web3.eth.getBlock(blockHeader.hash, true).then(async (r) => {
                var txs = r.transactions
                console.log('acclist :>> ', acclist);
                txs.forEach(async  (txId) => {
                    
                    console.log('txId :>> ', txId);
                })
            });
            
        })
        .on("error", console.error);

Leave a Reply

Your email address will not be published. Required fields are marked *