It is possible to swap tokens, interacting directly with the pair, and not with router?

If it's possible I can receive an example (explanation, not necessarily the code)

For example:

Blockchain: Fantom,
Pair (WFTM - USDC): https://ftmscan.com/address/0x2b4c76d0dc16be1c31d4c1dc53bf9b45987fc75c

I want to swap 1 WFTM for min USDC. And in reverse too, swap max USDC for 1 WFTM.

The pair is using the UniswapV2 idea.

1 Answer 1


Yes, it is definitely possible. You need to do some extra work for this to happen though. The swap function assumes that the pair contract has one token amount more than its reserves, which is technically how it should be. So you got to manually send some tokens to the contract first and then use the swap function.

   function swap(
        uint256 amount0Out,
        uint256 amount1Out,
        address to,
        bytes calldata data
    ) external lock {}
  • Yes the contract has swap, but I don't understand what is data.
    – KunLun
    Commented Feb 9, 2023 at 9:54
  • 1
    Just send empty data to it 0x00 Commented Feb 9, 2023 at 13:56
  • I still fail it. I get reverted. In my case: I want to buy 0.5 wftm (1wftm = $0.45). Transfer 0.5 usdc(~1wftm) to pair. After call swap with 0.5 wftm (amount1out). Theoretically I am doing it right?
    – KunLun
    Commented Feb 10, 2023 at 10:23

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.