# Raydium SDK Liquidity Withdrawal Guide

#### Step 1: Clone the Repository

1. Clone the Raydium SDK V2 demo repository:
   * git clone[ https://github.com/raydium-io/raydium-sdk-V2-demo.git](https://github.com/raydium-io/raydium-sdk-V2-demo.git)
2. After cloning, navigate into the new directory and install dependencies:
   * cd raydium-sdk-V2-demo
   * yarn install

***

#### Step 2: Update Addresses

1. Search for the address <mark style="color:green;">CAMMCzo5YL8w4VFF8KVHrK22GGUsp5VTaW7grrKgrWqK</mark> in the directory and replace all instances with <mark style="color:green;">cLmhcuG6pHbGHLzEKphgq6DBJvSiiY4h8D4kAppw7jd</mark>. Be thorough, as this address will appear in multiple files.
2. Ensure this replacement is done especially in the node\_modules file at:
   * raydium-sdk-V2-demo/node\_modules/@raydium-io/raydium-sdk-v2/src/common/programId.ts

***

**Step 3: Configure Settings**

1. Update the config.ts.template file to match your configuration, then rename it to config.ts.
2. Replace the following placeholders:
   * <mark style="color:green;">\<YOUR\_WALLET\_SECRET\_KEY></mark> with your own wallet secret key.
   * <mark style="color:green;">\<YOUR\_RPC\_URL></mark> with your preferred RPC URL.
   * <mark style="color:green;">\<API\_HOST></mark> : usually, the Raydium API host isn’t needed unless you’re testing on devnet.

***

**Step 4: Set Up Liquidity Withdrawal**

1. Navigate to the decreaseLiquidity.ts script located at:\
   <https://github.com/raydium-io/raydium-sdk-V2-demo/blob/master/src/clmm/decreaseLiquidity.ts>
2. Replace the poolId with the ID of the pool you wish to withdraw from. For example:
   * <mark style="color:green;">const poolId = '6UmmUiYoBjSrhakAobJw8BvkmJtDVxaeBtbt7rxWo1mg';</mark> (for the RAY-USDC pool)
3. Update the following part of the script:

```typescript
/
  if (raydium.cluster === 'mainnet') {
    // note: api doesn't support get devnet pool info, so in devnet else we go rpc method
    // if you wish to get pool info from rpc, also can modify logic to go rpc method directly
    const data = await raydium.api.fetchPoolById({ ids: poolId })
    poolInfo = data[0] as ApiV3PoolInfoConcentratedItem
    if (!isValidClmm(poolInfo.programId)) throw new Error('target pool is not CLMM pool')
  } else {
    const data = await raydium.clmm.getPoolInfoFromRpc(poolId)
    poolInfo = data.poolInfo
    poolKeys = data.poolKeys
  }

to:
 // Fetch pool info directly from RPC method regardless of the cluster
  const data = await raydium.clmm.getPoolInfoFromRpc(poolId)
  poolInfo = data.poolInfo
  poolKeys = data.poolKeys


  if (!isValidClmm(poolInfo.programId)) throw new Error('target pool is not CLMM pool')
```

4. *This enables the use of RPC instead of the Raydium API. If errors occur, consider switching to a different RPC or even a paid RPC.*

***

#### Step 5: Run the Withdrawal Script Execute the following command to withdraw your liquidity:&#x20;

* #### yarn dev src/amm/decreaseLiquidity.ts

If your transaction is not successful, try switching RPC providers. If it is still not successful, it might be due to Solana network congestion. You can try adjusting the gas price or wait for an interval where network demand is lower.
