Published in


removeLiquidity() — the hard way

The meteoric rise and proliferation of decentralised finance has brought many projects to the attention of users around the globe in the past 18 months. Some great projects have since continued BUIDLing with sustainable teams, development and tokenomics, while sadly some have been abandoned, with developers dropping their projects and moving on, leaving their protocol users with almost zero support thereafter.

While we’ve previously described the basics of cloning a decentralized front end, in some cases direct interaction with the smart contract may be a better option or the only option.

As such, today we will be covering direct smart contract interaction with a ‘uniswap’ clone on exiting a liquidity pool/pair.

Real life example : Swipeswap

At the time of writing swipeswap is facing a long term subgraph sync issue, resulting in their UI being unusable for the purpose of liquidity removal.

We will use ACS-SXP LP to show how to interact with the smart contract to remove liquidity and get your tokens back to your wallet.

Major Steps for removing liquidity

  1. find out the exact balance of LP tokens
  2. approve LP tokens for swap routers
  3. remove liquidity via swap router

Step 1

We can find out our exact LP token balance easily by calling the following function, via the ‘read contract’ section, of the LP token contract.

ACS-SXP LP token contract is the following :

Input your wallet address that holds the ACS-SXP LP and click Query. You will get a large number representing your balance.

for the purpose of this example,

let’s say balanceof : 10000000000000000000

representing 10 ACS-SXP LP

Step 2

Approve ACS-SXP SLP to be spent by swipeswap router with infinity approval.

a. We navigate to the ‘write contract’ portion of the LP token contract

b. connect to web3 wallet

c. send a write transaction on approve

with swipeswap router address as spender, and value of ‘-1

spender : 0x816278BbBCc529f8cdEE8CC72C226fb01def6E6C

value : -1

(you may revoke this later on for your sanity via

Step 3

The final step to remove liquidity /unpairing from swipeswap router.

a. Navigate to swipe swap router, write contract section: 0x816278BbBCc529f8cdEE8CC72C226fb01def6E6C

b. connect to web3 wallet

c. send a write transaction on removeLiquidity()

tokenA : 0x4197c6ef3879a08cd51e5560da5064b773aa1d29
tokenB: 0x47bead2563dcbf3bf2c9407fea4dc236faba485a
liquidity : number of balanceof from step1
amountAmin : 0
amountBmin: 0
deadline : <see below step (d)>

d. for deadline:

navigate to

get the current unix time via ‘The current Unix epoch time is 1632113496
remember to take this number JUST before you removeLiquidity, add about 300sec to the number.

This should gives you about 5 mins to act.

1632113496 + 300 = 1632113796

After finishing the 3 steps, you should receive both ACS + SXP in your wallet.



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store

getUnrekt — Ethereum and BSC Smart Contract approval toolbox