Karthikeyan Thangavel
Karthikeyan Thangavel

Reputation: 219

How to add and remove liquidity from uniswap3 using smart contract and sdk?

I am trying to build a web application using uniswap v3 for adding and removing the liquidity. I could able to add liquidity but for removing it I need a token, How to get it from uniswap?

Upvotes: 1

Views: 3225

Answers (1)

Dylan Kerler
Dylan Kerler

Reputation: 2187

When you add liquidity on uniswap v3 an NFT is minted and sent to your address. The Transfer event is emitted which contains the tokenId. You can see an example here on etherscan.

To remove the liquidity, you have to listen for this event and tokenId and then submit the same tokenId to remove the liquidity by burning the NFT token. An example here.

Alternatively, you could query the tokenOfOwnerByIndex function on the uni NFT contract and iterate from 0->n to get all of the NFTs liquidity positions owned by a user. This will give you all the tokenIds of NFTs which the user owns.

Upvotes: 4

Related Questions