Pending Transactions

Hi,
Is there any way to get pending transactions of single contract instead of getting all pending transaction on node?

Hi @hussam.mustafa
I believe this thread would be quite useful for you

Hi @Lily,

I already read that thread. I am working with the code given below. It hits all my limit within 5-10 minutes. I just only want Pending Transaction for my Specific Contract not all transactions on mainnet.

CODE:

web3.eth.subscribe(‘pendingTransactions’, function(error, result){
if (error)
console.log("Error: ",error);
})
.on(“data”,async function(TxHash) {
try {
let tx = await web3.eth.getTransaction(TxHash);

        if(tx && tx.to){
            if (tx.to.toLowerCase() === contractAddress) {
                console.log('Transaction Hash: ',TxHash );
                console.log('Transaction Confirmation Index: ',tx.transactionIndex );
                console.log('Transaction Received from: ',tx.from );
                console.log("\n");         
            }else{
                console.log("TXHash",TxHash);
            }  
        }   
    } catch (error) {
        console.log(error)
    }

});

1 Like

Hello @hussam.mustafa
I would suggest using eth_subscribe with the newPendingTransactions parameter. Here is a link with more detailed information: https://infura.io/docs/ethereum/wss/eth-subscribe.

Here are also some examples of looking at a particular contract address. https://github.com/ethereum/web3.js/issues/3083
https://medium.com/coinmonks/monitoring-an-ethereum-address-with-web3-js-970c0a3cf96d

HI @Lily,

newPendingTransactions” also give all transaction on node. I just want pending transactions for my contract address only.

1 Like

@hussam.mustafa At the moment, there’s not a direct way to get the pendingTransactions of a specific contract without getting all transactions from the node first. We will look into adding this feature to our product roadmap.

Still no way to monitor a specific address without receiving ALL the transaction and make a call to read ALL the transaction one by one, right?

Hi, have you found a better way than read ALL the transactions?