When looking at the pending transactions, in Mempool that is, and the ones that have to do with Uniswap (to == Uniswap router address), how can it be identified whether a certain tx is a "buy" or "sell" one?

How to get to know if tx is a "buy" or "sell" from the transaction details programmatically?

  • It depends on your point of view. If you exchange USDC for WETH, then you are selling USDC and buying WETH. For token pairs where WETH is one of them you could assume that if you receive the ERC20 then you are buying and when you receive WETH you are selling. For pairs where both are ERC20 then buy or sell doesn't matter much.
    – Ismael
    Commented Jul 1, 2022 at 21:48
  • @Ismael but there's no official, proper way to say whether a transaction is "buy" or "sell" on a DEX? Commented Jul 2, 2022 at 0:16
  • It doesn't make much sense to put that definition in a standard. Technically when you swap T1 fro T2 then you are selling T1 and buying T2. Uniswap generates two transfer events T1 from sender to uniswap pair, and T2 from uniswap pair to recipient.
    – Ismael
    Commented Jul 2, 2022 at 17:03

1 Answer 1


If you consider WETH to be your base token, and that a transaction that swaps WETH to a hypothetical Token 1 (WETH -> Token 1) to be a buy transaction, and a tx that swaps Token 1 for WETH (Token 1 -> WETH) to be a sell transaction, you can just watch the swap method.

In the case of swapETHForExactTokens or swapExactETHForTokens you have a buy transaction.

In the case of swapTokensForExactETH or swapExactTokensForETH you have a sell transaction.

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.