> For the complete documentation index, see [llms.txt](https://docs.ston.fi/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.ston.fi/developer-section/dex/sdk/burn-lp-tokens.md).

# Withdraw liquidity

Burn issued LP tokens and release the underlying pool assets.

This operation withdraws assets by burning issued LP tokens; the example burns the full balance. For tokens still pending in an LP account, use [Recover pending liquidity](/developer-section/dex/sdk/refund-liquidity.md). Use a wallet owning the LP tokens and matching DEX v2 router metadata; see [Setup and environments](/developer-section/dex/sdk/v2.md).

## Mainnet workflow

1. Locate the target pool via the STON.fi API (for example with `getPoolsByAssetPair` or `getPool`).
2. Fetch the router metadata with `getRouter(pool.routerAddress)`.
3. Build the pool and LP wallet contracts dynamically with `dexFactory` and `TonClient`.
4. Read the LP balance and generate the burn transaction parameters.

```typescript
import { Client, dexFactory } from "@ston-fi/sdk";
import { StonApiClient } from "@ston-fi/api";

const tonClient = new Client({
  endpoint: "https://toncenter.com/api/v2/jsonRPC",
  apiKey: process.env.TON_API_KEY, // optional but recommended for higher rate limits
});

const apiClient = new StonApiClient();

// Discover the pool you want to exit (replace addresses with your assets)
const [poolInfo] = await apiClient.getPoolsByAssetPair({
  asset0Address: "<token A address or 'ton'>",
  asset1Address: "<token B address>",
});

if (!poolInfo) {
  throw new Error("Liquidity pool not found for the provided asset pair");
}

// Load router metadata and initialise contracts
const routerMetadata = await apiClient.getRouter(poolInfo.routerAddress);
const dexContracts = dexFactory(routerMetadata);

const pool = tonClient.open(
  dexContracts.Pool.create(poolInfo.address),
);

if (!("getPoolType" in pool)) {
  throw new Error("Use the DEX v1 burn guide for a v1 pool");
}

// Fetch the LP wallet owned by the user and read the balance
const lpWallet = tonClient.open(
  await pool.getJettonWallet({ ownerAddress: "<your wallet address>" }),
);

const { balance } = await lpWallet.getWalletData();

const burnTxParams = await pool.getBurnTxParams({
  amount: balance,
  userWalletAddress: "<your wallet address>",
  queryId: 12345,
});
```

Send the resulting transaction parameters using your preferred wallet integration (see the [transaction sending guide](/developer-section/common/transaction-sending.md)).

> **Tip**: If one side of the pool is TON, the API already exposes the correct `routerMetadata.ptonMasterAddress`. You do not need to hardcode the proxy TON contract. `dexFactory` picks the right implementation for you.

## Testnet burn (manual setup)

To burn LP tokens on TON testnet, configure testnet contracts and use a wallet that holds LP tokens from the selected pool. The `api.ston.fi` endpoint serves mainnet data.

```typescript
import { TonClient } from "@ton/ton";
import { DEX } from "@ston-fi/sdk";

const client = new TonClient({
  endpoint: "https://testnet.toncenter.com/api/v2/jsonRPC",
});

const router = client.open(
  DEX.v2_1.Router.CPI.create("kQALh-JBBIKK7gr0o4AVf9JZnEsFndqO0qTCyT-D-yBsWk0v"), // CPI Router v2.1.0 (testnet)
);

const pool = client.open(
  await router.getPool({
    token0: "kQDLvsZol3juZyOAVG8tWsJntOxeEZWEaWCbbSjYakQpuYN5", // TesREED jetton (testnet)
    token1: "kQB_TOJSB7q3-Jm1O8s0jKFtqLElZDPjATs5uJGsujcjznq3", // TestBlue jetton (testnet)
  }),
);

const lpWallet = client.open(
  await pool.getJettonWallet({ ownerAddress: "<your testnet wallet>" }),
);

const { balance } = await lpWallet.getWalletData();

const txParams = await pool.getBurnTxParams({
  amount: balance,
  userWalletAddress: "<your testnet wallet>",
  queryId: 12345,
});
```

This manual approach is strictly **for testing**. Switch back to the API-driven workflow for any mainnet-facing integration.

## Check the result

After the burn is processed, inspect the LP wallet balance and the returned underlying asset transfers. A broadcast alone is not a completed withdrawal. Pending LP-account balances are separate; use [Recover pending liquidity](/developer-section/dex/sdk/refund-liquidity.md) for those.

Use the [REST transaction action tree](/developer-section/dex/api/reference.md#transaction-action-tree) to inspect the submitted operation.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.ston.fi/developer-section/dex/sdk/burn-lp-tokens.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
