0

I am trying to get mempool transactions ASAP. My purpose is to get the pending transactions on Uniswapv2 router before the transaction is confirmed.

I tried several providers from Quicknode, Alchemy, Infura and Rivet. And also I tried with localnode and Blocknative API. Ofc, I can get the pending transactions hash's using those providers and API. But after receive it, I can see that the receiving time is always after the transaction confirmation.

For example: https://etherscan.io/tx/0x362397df699548b52d9819b20170053cf45897742c1d2428acdf8005f93f766d

I received this transaction on Aug-30-2022 04:59:25. But it is already confirmed on Aug-30-2022 04:59:14. Same thing is happening with most of the transactions. I want to receive these transaction hashes about 5 seconds ago.

If someone help me with this, it would be very helpful!!!

1 Answer 1

4

You can get the pending transactions using Chainstack's WSS Node.

In your code, you first need to declare a provider

// Connecting to the Chainstack's WSS Node
const provider = new ethers.providers.WebSocketProvider(
  "WSS_NODE_HERE"
);

Then, if you want to want to get the pending transactions, you can use the below code.

provider.on("pending", (tx) => {
  provider.getTransaction(tx).then(function (transaction) {
    console.log(transaction);
  });
});

Here is how the response should look like:

{
  hash: '0xda4b05e28cccb82fd679b55373397628d046584a129fd8b57f3f73426f4bb1a8',
  type: 0,
  accessList: null,
  blockHash: null,
  blockNumber: null,
  transactionIndex: null,
  confirmations: 0,
  from: '0x250ABd1D4EBC8e70a4981677D5525f827660bDE4',
  gasPrice: BigNumber { _hex: '0x47c78e2153', _isBigNumber: true },
  gasLimit: BigNumber { _hex: '0x07a120', _isBigNumber: true },
  to: '0x886ccA828224F2D196aD386F35A76573604702c2',
  value: BigNumber { _hex: '0x00', _isBigNumber: true },
  nonce: 14310051,
  data: '0xc98075390000000000000000000000000000000000000000000000000000000000000080000000000000000000000000000000000000000000000000000000000000032000000000000000000000000000000000000000000000000000000000000004000001010000010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000028000000000000000000000005e86e3478aeb2b21c1f73e141f67bcb8000d5a0003000102030f060a0c070e0904080b0d05000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000060000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000c9ef63ce00000000000000000000000000000000000000000000000000000000c9ef63ce00000000000000000000000000000000000000000000000000000000c9f5f0ea00000000000000000000000000000000000000000000000000000000c9fc7e0700000000000000000000000000000000000000000000000000000000c9fc7e0700000000000000000000000000000000000000000000000000000000ca163b0700000000000000000000000000000000000000000000000000000000ca16424200000000000000000000000000000000000000000000000000000000ca3d20b600000000000000000000000000000000000000000000000000000000ca4ba2e700000000000000000000000000000000000000000000000000000000ca4c548000000000000000000000000000000000000000000000000000000000ca51401300000000000000000000000000000000000000000000000000000000ca544c6900000000000000000000000000000000000000000000000000000000ca655f7000000000000000000000000000000000000000000000000000000000ca6b77a600000000000000000000000000000000000000000000000000000000ca7d466700000000000000000000000000000000000000000000000000000000ca8c001700000000000000000000000000000000000000000000000000000000000000067cfb501437c4906d375f6c94b61fdbe8adbe49cffeb4dd5287b9b8345052b609eb21be838adf48d73586362a5df0b3e7230249e7a8c7a0d662312940e615802583bdc14663163ae07d8e76a9ce3d7addc43d86d45ca56e1ef286c79944d611ede376f7e88894abac287c68fd6a0456c4fec7e74fa04bc07066ebe6d3bab29540f9ec923ff046865657c8487d7b6498eff07b8e076a25ab5d5943ec1f7efa0de5ce99ead6e406efc78f58747f474fef8e1a43f2df7295d70476aeed834b0500850000000000000000000000000000000000000000000000000000000000000006249e150d0ff415e2a85ecd0b24edbd96e8e33f9ae4fd79922cd121b9364bc8094f1423d053393ca729617f234652d0470a0739f01cf37b320b7e745b4706b88b657eadabe792b9f54cbe795fcb527631abcf477122a462b93036701af2a660f25b3a04b9cffe1e30bbd6eaa8c471cc062dff4788eb13182aaff59eba63830da9248c0246854aea0d5d759fde068ce2d7a54cbab70fab22b035f2fd139531b4725bdf004fdfc7b8c4a5406ed92c6668dc7f9d4b8905b61fb9ea81b01b7400d75d',
  r: '0xa2575d515a9c4bcb9b473c4cc827343f2e499d6e8e549e6b5f34db2ec17e689a',
  s: '0x1a35e96ae6e7e71896ef3c57927c1087d84164fb714e6fa3b0f40cc54534d69a',
  v: 310,
  creates: null,
  chainId: 137,
  wait: [Function (anonymous)]
}
{
  hash: '0x7bde2f94d638af4d2aff1177f77cb27b7502d0a11b703ce10f12b3a282b573d0',
  type: 0,
  accessList: null,
  blockHash: null,
  blockNumber: null,
  transactionIndex: null,
  confirmations: 0,
  from: '0x67631470bE83F7b449d2efc4A03dad3aEe779D1B',
  gasPrice: BigNumber { _hex: '0x288aa092c9', _isBigNumber: true },
  gasLimit: BigNumber { _hex: '0x0f4515', _isBigNumber: true },
  to: '0xe6E7D667b5234748eA264D3Fa7Dd8B4C3883Dafc',
  value: BigNumber { _hex: '0x00', _isBigNumber: true },
  nonce: 40684,
  data: '0x7898e0c20000000000000000000000000000000000000000000000000000000000000060000000000000000000000000000000000000000000000000000000002baf7c2600000000000000000000000000000000000000000000000000000000630dc4c30000000000000000000000000000000000000000000000000000000000000007444f542f55534400000000000000000000000000000000000000000000000000',
  r: '0x6fd11697c57b23d46e684df78310c4e5f6a862a2ce845cfd3d872d8f328665cd',
  s: '0x47797e0ee8e2a551e6fdc91242e4c0068a2db59dd7cf33bb7b55cac605c291ba',
  v: 310,
  creates: null,
  chainId: 137,
  wait: [Function (anonymous)]
}
{
  hash: '0x9e52869044bb2f6b77350b485295e9759c9d874df06744c6f25229d2fa098b45',
  type: 2,
  accessList: [],
  blockHash: null,
  blockNumber: null,
  transactionIndex: null,
  confirmations: 0,
  from: '0x27f2CC189c6718C6338B6e97244741f9245383Bb',
  gasPrice: BigNumber { _hex: '0x2e90edd000', _isBigNumber: true },
  maxPriorityFeePerGas: BigNumber { _hex: '0x1ae4562300', _isBigNumber: true },
  maxFeePerGas: BigNumber { _hex: '0x2e90edd000', _isBigNumber: true },
  gasLimit: BigNumber { _hex: '0x0f3e58', _isBigNumber: true },
  to: '0xBaF13c00BdBc3a752715E3a8B7684896871Ae7B4',
  value: BigNumber { _hex: '0x00', _isBigNumber: true },
  nonce: 79,
  data: '0xd96a094a0000000000000000000000000000000000000000000000000000000000000000',
  r: '0x346dbc10bbe727ffe4d75a03dcae77e6a96bb1031ca4ed184ba60c96a0270d19',
  s: '0x6790c4ad217c93267f25990ce230e9e7b2ae2e8b2defc951d5854984d3e01130',
  v: 0,
  creates: null,
  chainId: 137,
  wait: [Function (anonymous)]
}
{
  hash: '0x72cc29b66331102772dc8d0f73bace8390ee735013b4f0de592f516e80d26c07',
  type: 0,
  accessList: null,
  blockHash: null,
  blockNumber: null,
  transactionIndex: null,
  confirmations: 0,
  from: '0xa1ab1c841898Fe94900d00d9312ba954e4F81501',
  gasPrice: BigNumber { _hex: '0x570007a669', _isBigNumber: true },
  gasLimit: BigNumber { _hex: '0x07a120', _isBigNumber: true },
  to: '0xa0EEfe4dA82d88991c26a2bA7868c5a1C485A72E',
  value: BigNumber { _hex: '0x00', _isBigNumber: true },
  nonce: 13736334,
  data: '0xc98075390000000000000000000000000000000000000000000000000000000000000080000000000000000000000000000000000000000000000000000000000000032000000000000000000000000000000000000000000000000000000000000004000100000100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000028000000000000000000000009da8323d5cdb0a9a980e3f323ccd1241000d9d4203040e05080003090d01020a070c0f060b00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000608e9d000000000000000000000000000000000000000000000000000000000060929700000000000000000000000000000000000000000000000000000000006096fd0000000000000000000000000000000000000000000000000000000000609d8d0000000000000000000000000000000000000000000000000000000000609d8d000000000000000000000000000000000000000000000000000000000060adc4000000000000000000000000000000000000000000000000000000000060ae5e000000000000000000000000000000000000000000000000000000000060ae70000000000000000000000000000000000000000000000000000000000060ae70000000000000000000000000000000000000000000000000000000000060af58000000000000000000000000000000000000000000000000000000000060b02c000000000000000000000000000000000000000000000000000000000060b686000000000000000000000000000000000000000000000000000000000060b73d000000000000000000000000000000000000000000000000000000000060b73d000000000000000000000000000000000000000000000000000000000060b9b8000000000000000000000000000000000000000000000000000000000060bda00000000000000000000000000000000000000000000000000000000000000006e46f1e8c7b0cfdd09fdcbed66cd7c7e7dfa9b8be25f5027e1025bb28e65d8108e3931b98ee48da71668a7c871d842e8de066c83700b4a37ed2927df0b4b49a502398a9cee267e0beff172eddf8c280601f2d7ae689cf70040a08301b7c7d3d0d96c359bebc030d53e24958f325dac9f9b03df6940aebf10972d91cba8350e3959c532808d16448264d44830358836b705defcef4e2c78ac0e921c3995b3e70e40d006a472721dde96ef7c37933fcb89a827d841409ec7ea0994ef47330cfd42c00000000000000000000000000000000000000000000000000000000000000063bc795108beccdf521f870d42c15b773e65cf999558877d198f74e810debf19c2478dc33985b1842ce6a16daeb299ae1e2ead84d5838265a57ee519cce48733417e87225fdf14d22712e72b70f323d34353c70a705a9da8144a6205775507b6d483961db2ca82c8d5b0e4bbf913547efb7e6621402553bbfb9b5edc7eec2f395305b32e025669cd86565d8c6dd9f9915d36529dbfc26faea4234c10593699edb4056316bc8c98319d651c79093f26a8aba55f21af3227546c085b0970947d664',
  r: '0xfbf6b9de4e9f02c85bae9d1d8180d71100cca3d4072aaf3818b935d5ad77bfb9',
  s: '0x2fcca174587b07d889a0a2fd4826a8db978ee4f4e7a87d185067b84171ee432c',
  v: 310,
  creates: null,
  chainId: 137,
  wait: [Function (anonymous)]
}

The above code is to get the pending transactions (i.e: not yet confirmed from EVM, but the process should be similar with Uniswap too)

2
  • Thanks for your help @Suhail. But I used this code before posting this and it's not working good. Commented Aug 30, 2022 at 8:27
  • Take a look at this repo: github.com/suhailkakar/evm-pending-transactions I have built a simple Next.js app that fetches all the pending transactions from EVM : ) btw, it would be great if you share the piece of code that you are using. Commented Aug 30, 2022 at 8:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.