> ## Documentation Index
> Fetch the complete documentation index at: https://docs.compasslabs.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Withdraw Funds

> Exit positions, then send tokens from the product account back to the user's wallet.

Getting money out takes two steps. First exit the position, which returns the tokens to the product account. Then move them from the account to the user's wallet with the product's `transfer` endpoint and `action: "WITHDRAW"`.

This works the same way in Earn, Credit and Tokenized Assets. For Perpetual Trading, [withdraw USDC from Hyperliquid](/v2/api-reference/perpetual-trading/withdraw-usdc-from-perpetual-trading-account) instead.

## 1. Exit the position

| Product | How to exit |
| - | - |
| Earn | [`manage`](/v2/api-reference/earn/manage-earn-position) with `action: "WITHDRAW"` for the vault, Aave market or Pendle PT position. |
| Credit | [`repay`](/v2/api-reference/credit/repay-debt-and-withdraw-collateral) pays back the loan and withdraws collateral in one transaction. [`unloop`](/v2/api-reference/credit/unwind-a-leveraged-loop) closes a leveraged loop. For collateral with no loan against it, use [`bundle`](/v2/api-reference/credit/execute-multiple-credit-actions) with a `CREDIT_WITHDRAW` action. |
| Tokenized Assets | Sell back to USDC: a sell order for equities, or [`transact/sell`](/v2/api-reference/tokenized-assets/sell-an-rwa-yield-token) for RWA yield tokens, deRWA and IXS vaults. See [Tokenized Assets](/v2/Products/Tokenized-Assets). |

For example, take 75 USDC out of a vault in the Earn Account:

<CodeGroup>
  ```python Python theme={"system"}
  import httpx

  response = httpx.post(
      "https://api.compasslabs.ai/v2/earn/manage",
      json={
          "owner": "0xYourWalletAddress",
          "chain": "base",
          "venue": {"type": "VAULT", "vault_address": "0xVaultAddress"},
          "action": "WITHDRAW",
          "amount": "75",
      },
      headers={"x-api-key": "YOUR_API_KEY"},
  )
  result = response.json()

  # result["transaction"]: unsigned tx for the owner to sign and send
  # Once it confirms, the USDC is back in the Earn Account
  ```

  ```typescript TypeScript theme={"system"}
  const response = await fetch(
    "https://api.compasslabs.ai/v2/earn/manage",
    {
      method: "POST",
      headers: {
        "Content-Type": "application/json",
        "x-api-key": "YOUR_API_KEY",
      },
      body: JSON.stringify({
        owner: "0xYourWalletAddress",
        chain: "base",
        venue: { type: "VAULT", vault_address: "0xVaultAddress" },
        action: "WITHDRAW",
        amount: "75",
      }),
    }
  );
  const result = await response.json();

  // result.transaction: unsigned tx for the owner to sign and send
  // Once it confirms, the USDC is back in the Earn Account
  ```
</CodeGroup>

Most exits settle in the same transaction. Two settle later, so wait for them before step 2:

* **Equity sell orders** fill asynchronously. Poll the order status until it's `filled`.
* **IXS vault redemptions** are settled by the vault operator. Poll [`/v2/tokenized_assets/redemptions`](/v2/api-reference/tokenized-assets/list-redemption-requests) until the request is `finalized`.

## 2. Send tokens to the wallet

Send 100 USDC from the Earn Account back to the user's wallet:

<CodeGroup>
  ```python Python theme={"system"}
  response = httpx.post(
      "https://api.compasslabs.ai/v2/earn/transfer",
      json={
          "owner": "0xYourWalletAddress",
          "chain": "base",
          "token": "USDC",
          "amount": "100",
          "action": "WITHDRAW",
      },
      headers={"x-api-key": "YOUR_API_KEY"},
  )
  result = response.json()

  # result["transaction"]: unsigned tx that tells the account to send the USDC
  # The owner signs and sends it
  ```

  ```typescript TypeScript theme={"system"}
  const response = await fetch(
    "https://api.compasslabs.ai/v2/earn/transfer",
    {
      method: "POST",
      headers: {
        "Content-Type": "application/json",
        "x-api-key": "YOUR_API_KEY",
      },
      body: JSON.stringify({
        owner: "0xYourWalletAddress",
        chain: "base",
        token: "USDC",
        amount: "100",
        action: "WITHDRAW",
      }),
    }
  );
  const result = await response.json();

  // result.transaction: unsigned tx that tells the account to send the USDC
  // The owner signs and sends it
  ```
</CodeGroup>

| Field | Description |
| - | - |
| `owner`, `chain`, `token`, `amount` | The same as for [deposits](/v2/account-lifecycle/fund-account). `amount` is in token units. |
| `action` | `WITHDRAW` moves tokens from the account to the wallet. |
| `recipient` | Earn only, optional. Sends the tokens to another address instead of the owner. |
| `gas_sponsorship` | `true` returns `eip_712` for the user to sign instead of a transaction. Relay it through [`prepare`](/v2/api-reference/gas-sponsorship/prepare-gas-sponsored-transaction) with `product` set, as with a [sponsored deposit](/v2/account-lifecycle/fund-account#sponsored-deposits). Withdrawals don't need the one-time token approval or a `spender`. |

Either way, the owner signs the instruction to their account. The account only follows its owner's signature, so nobody else (including Compass) can withdraw.

## Good to know

* **Only tokens sitting in the account can move.** If the account holds less than `amount`, the call returns `400 Insufficient balance`. Read the amount from [`balances`](/v2/account-lifecycle/balances-and-positions) first.
* **Pay out a loan while it's open.** Borrowed tokens land in the Credit Account. Send them to the user's wallet with `transfer` and `WITHDRAW`; this works while the loan is open. Collateral stays in the lending protocol until you withdraw it with `repay` or `bundle`.
* **Credit and Tokenized Assets always pay the owner.** Only Earn takes a `recipient`.
* **Exit and withdraw with one signature.** In Earn and Credit, a [`bundle`](/v2/Products/Bundling) can combine the exit with a `V2_TRANSFER_TO_EOA` action, so the user signs once.

## Next

<CardGroup cols={2}>
  <Card title="Gas Sponsorship" icon="gas-pump" href="/v2/Products/gas-sponsorship">
    Pay gas for your users, so they never need ETH.
  </Card>

  <Card title="Embedded Fees" icon="coins" href="/v2/Products/Embedded-fees">
    Earn a fee on deposits, withdrawals, loans and trades.
  </Card>
</CardGroup>
