Probably what you want is to monitor pending transactions? If that's the case, you need to connect to a node via websocket and subscribe to the "PendingTransactions". Something like this:
var Web3 = require('web3')
const main = async () => {
// reconnect options
const options = {
reconnect: {
auto: true,
delay: 2000,
maxAttempts: 3,
onTimeout: false,
},
}
const web3 = new Web3(
new Web3.providers.WebsocketProvider('wss://your-node-endpoint/12345',
options
)
)
// subscribe to pendingTransactions events
web3.eth
.subscribe('pendingTransactions', async (error, result) => {
if (error) console.log('error', error)
})
.on('data', async (trxId) => {
// receives the transaction id
console.log('TRX ID >> ', trxId)
// query all transaction details using its id
const trxDetails = await web3.eth.getTransaction(trxId)
console.log(`TRX ${trxId} DETAILS >> `, trxDetails)
})
}
main()