# Withdrawing Tokens

The `withdraw()` method lets a user transfer shielded tokens from their private Shielder account back to a public address — using a **relayer** to maintain privacy.

### When to Use

Use `withdraw()` when a user wants to exit the private set and receive tokens on a public Ethereum address — anonymously, via relayer.

```typescript
async withdraw(
  token: Token,
  amount: bigint,
  quotedFees: QuotedFees,
  withdrawalAddress: Address,
  pocketMoney: bigint
): Promise<`0x${string}`>
```

#### What It Does

* Fetches the latest state and constructs a withdrawal proof.
* Sends a withdrawal request to the configured relayer backend.
* The relayer pays gas and broadcasts the transaction to the network.
* Funds arrive at the withdrawalAddress, minus relayer fees.

### Example

{% code title="src/App.tsx" %}

```typescript
...

import { initializeShielderClient } from "./shielder";
import { nativeToken } from "@cardinal-cryptography/shielder-sdk";

const amountToWithdraw = 500_000_000_000_000n; // 0.0005 ETH
const withdrawalAddress = "0x..." as const;

(async () => {
  const shielder = await initializeShielderClient();
  const token = nativeToken();

  // Sync to ensure up-to-date state
  await shielder.syncShielder();

  // Get fee quote from relayer for this withdrawal
  const quotedFees = await shielder.getWithdrawFees(token, 0n); // pocketMoney = 0n for native

  // Withdraw through relayer
  const txHash = await shielder.withdraw(
    token,
    amountToWithdraw,
    quotedFees,
    withdrawalAddress,
    0n // pocketMoney, usually 0 for native token
  );

  console.log("Withdraw tx hash:", txHash);
})();

...
```

{% endcode %}

### Pocket Money (for ERC-20s only)

If the withdrawal token is not the native token, you may want to request a small native token payment from the relayer to cover gas for the recipient.

```typescript
const pocketMoney = 100_000_000_000_000n; // 0.0001 ETH
const quotedFees = await shielder.getWithdrawFees(token, pocketMoney)
```

### Tips

* `amountToWithdraw` passed to `withdraw()` function includes the fee, more precisely `withdrawalAddress` will receive `amountToWithdraw - quotedFees.fee_details.total_cost_fee_token`


---

# Agent Instructions: Querying This Documentation

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

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.common.fi/knowledge-base/withdrawing-tokens.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
