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

# Quickstart: Withdraw from an Earn vault

> Withdraw USDC from an Earn vault to recover your deposit and accrued yield

Redeem your vault shares back to USDC on Arc Testnet, including any yield earned
since deposit. This quickstart uses Circle Wallets, but you can use any
compatible [adapter setup](/app-kit/tutorials/adapter-setups).

## Prerequisites

Before you begin, ensure that you've:

* Completed the [deposit quickstart](/app-kit/quickstarts/earn-deposit) so you
  have USDC deposited in a vault.
* Installed [Node.js v22+](https://nodejs.org/).
* Obtained an
  [API key](https://developers.circle.com/api-reference/keys#creating-an-api-key-for-developer-services)
  and
  [entity secret](https://developers.circle.com/wallets/dev-controlled/register-entity-secret)
  from the
  [Circle Console](https://developers.circle.com/w3s/circle-developer-account).
* Created a developer-controlled wallet on Arc Testnet using the Circle Console.

<Note>
  Earn operations work without an API key. For higher rate limits, pass an
  optional [API key](/app-kit/earn#api-key) as `apiKey` in the operation config.
  Keep the API key server-side. The App Kit SDK rejects an API key passed from a
  browser context.

  <Accordion title="Example: passing an API key">
    ```typescript TypeScript theme={null}
    const result = await kit.earn.deposit({
      from: { adapter, chain: "Arc_Testnet" },
      vaultAddress: "0x...",
      amount: "10.00",
      config: { apiKey: process.env.API_KEY as string },
    });
    ```
  </Accordion>
</Note>

## Step 1. Set up the project

<Note>
  If you completed the [deposit quickstart](/app-kit/quickstarts/earn-deposit),
  add the withdraw run script in step 1.1 to your existing project and skip to
  Step 2.
</Note>

### 1.1. Create the project and install dependencies

Create a new directory and install the App Kit SDK with the Circle Wallets
adapter and supporting tools:

```bash Shell theme={null}
# Set up your directory and initialize a Node.js project
mkdir app-kit-earn-withdraw-circle-wallets
cd app-kit-earn-withdraw-circle-wallets
npm init -y
npm pkg set type=module

# Set up run scripts
npm pkg set scripts.withdraw="tsx --env-file=.env withdraw.ts"

# Install runtime dependencies
npm install @circle-fin/app-kit @circle-fin/adapter-circle-wallets tsx

# Install dev dependencies
npm install --save-dev typescript @types/node
```

<Tip>
  Only need Earn and want a lighter install than the full App Kit? Install the
  standalone package instead: `@circle-fin/earn-kit`
</Tip>

### 1.2. Configure TypeScript (optional)

<Info>
  This step is optional. It helps prevent missing types in your IDE or editor.
</Info>

Create a `tsconfig.json` file configured for ESM and Node:

```bash Shell theme={null}
cat <<'EOF' > tsconfig.json
{
  "compilerOptions": {
    "target": "ESNext",
    "module": "ESNext",
    "moduleResolution": "bundler",
    "strict": true,
    "types": ["node"]
  }
}
EOF
```

### 1.3. Set environment variables

Create an `.env` file in the project directory:

```bash Shell theme={null}
touch .env
```

Add your credentials. Replace `YOUR_API_KEY` with your Circle Developer API key,
`YOUR_ENTITY_SECRET` with your entity secret:

```text .env theme={null}
CIRCLE_API_KEY=YOUR_API_KEY
CIRCLE_ENTITY_SECRET=YOUR_ENTITY_SECRET
```

<Tip>
  Edit `.env` files in your IDE or editor so credentials are not leaked to your
  shell history.
</Tip>

## Step 2. Withdraw USDC

### 2.1. Create the withdrawal script

Create a `withdraw.ts` file. Replace `YOUR_SELECTED_VAULT_ADDRESS` with the
vault address you deposited into and `YOUR_CIRCLE_WALLET_ADDRESS` with the
address of your Circle Wallets wallet. This script withdraws 10.00 USDC from the
vault:

```typescript withdraw.ts theme={null}
import { AppKit } from "@circle-fin/app-kit";
import { createCircleWalletsAdapter } from "@circle-fin/adapter-circle-wallets";

const kit = new AppKit();
const amount = "10.00";
const vaultAddress = "YOUR_SELECTED_VAULT_ADDRESS";

const adapter = createCircleWalletsAdapter({
  apiKey: process.env.CIRCLE_API_KEY!,
  entitySecret: process.env.CIRCLE_ENTITY_SECRET!,
});

async function main() {
  const result = await kit.earn.withdraw({
    from: {
      adapter,
      chain: "Arc_Testnet",
      address: "YOUR_CIRCLE_WALLET_ADDRESS",
    },
    vaultAddress,
    amount,
  });

  console.dir(result, { depth: null, colors: true });
}

void main();
```

<Note>
  The first withdrawal from a vault requires an approval transaction to allow the
  vault contract to redeem your shares. The App Kit SDK handles this
  automatically, so you may see two transactions in your wallet instead of one.
</Note>

The amount you receive depends on the current vault share price at the time of
redemption.

<Tip>
  Preview the expected outcome of a withdrawal before submitting with
  [`kit.earn.getWithdrawalQuote`](/app-kit/tutorials/earn/preview-operations#preview-a-withdrawal).
</Tip>

### 2.2. Run the withdrawal script

In your terminal, run:

```bash Shell theme={null}
npm run withdraw
```

When the script completes, you'll see output like:

```bash Shell theme={null}
{
  txHash: "0x...",
  explorerUrl: "https://explorer.testnet.arc.io/tx/0x...",
  vaultAddress: "0x...",
  amount: "10.04",
}
```

The returned `amount` reflects the value of your shares at the time of
withdrawal, which may be greater than your original deposit due to accrued
yield. For details on any fees that apply, see
[How Earn fees work](/app-kit/concepts/earn-fees).

Use the `txHash` to verify the transaction on the Arc Testnet block explorer. To
confirm your updated vault balance, see
[Check your Earn position](/app-kit/tutorials/earn/check-position).
