3
votes

Is there a way to check which direction is transfer() of erc-20 token if someone is selling or buying our tokens for eth (i mean uniswap for example)?

2

2 Answers

1
votes

Uniswap transactions are swaps, not buys or sells. It can have two input token and two output token at the same time.

One way define Uniswap token transaction as a buy or sell is to define one of token0 and token1 as quote token (USD, ETH) and then if the amount of quote token was less after the swap, it was buy.

0
votes

You can differentiate it by checking whether your account received or transfered the tokens.

Eg:

transactionType: address === obj.from ? 'Sold' : 'Bought'

From is your account address.

Obj - Is the transaction details.