How to call function of my contract in uniswap

I’m trying to call function of my own contract in uniswap.
For example, I want to call my own function of my contract instead of swapETHForExactTokens of UniswapV2Router02 contract.

Hi Stepan,

You cannot make Uniswap’s Router nor Uniswap’s Pair contracts call your own functions. The reason is because their code is their own, you can’t modify it.

BUT - there are ways around this.

In your contract you could monitor the LP balance of someone. If LP is created then do something else.

If swaps happen (by transferring tokens into and out of the pair address) then you can monitor and do something when that happens.

For example
if(from == uniswapV2Pair){ // if it was a buy....
In this line I am checking to see if this was a “buy” from Uniswap and I do something else in my code.

I could be wrong, but maybe you don’t want your token to use Uniswap? Maybe you want to use a different kind of DEX and develop your own. This would be hard, but possible.

thanks very much for your response.
I’ve implemented this problem.