# Withdraw

### Querying Redeem Amounts

If you would like your platform to display the amount of underlying tokens the user would receive for redeeming cTokens, you may use the `convertToAsset()` function present in all cToken contracts using the following arguments:

<table><thead><tr><th width="109">Type</th><th width="102">Name</th><th>Description</th></tr></thead><tbody><tr><td>uint256</td><td>tokens</td><td>The number of cToken shares to theoretically convert to underlying assets</td></tr></tbody></table>

Conversely, if you want to let the user choose how much underlying assets to withdraw, you may use the `convertToShares()` function:

<table><thead><tr><th width="109">Type</th><th width="102">Name</th><th>Description</th></tr></thead><tbody><tr><td>uint256</td><td>amount</td><td>The number of underlying tokens to theoretically convert to cTokens</td></tr></tbody></table>

### Withdraw from cTokens (cUSDC example)

To withdraw USDC from cUSDC directly, you may use the `withdraw(assets)` or  `redeem(shares)` functions present in all cToken contracts using the following arguments:

{% hint style="info" %}
Withdrawing/Redeeming does not force collateral removal.
{% endhint %}

<table><thead><tr><th width="114">Type</th><th width="239">Name</th><th>Description</th></tr></thead><tbody><tr><td>uint256</td><td>assets (if withdraw)<br>shares (if redeem)</td><td>The number of assets/shares to withdraw/redeem.</td></tr><tr><td>address</td><td>recipient</td><td>The account who will receive the underlying assets</td></tr></tbody></table>

Below is an example of using `withdraw()`:

```javascript
// Get the cUSDC contract with signer
const cUSDC = new ethers.Contract(ADDRESSES.EUSDC, CTOKEN_ABI, signer);

// Get the amount of shares to redeem from the user's input amount
// userInputAmount being equal to "1000", representing 1000 USDC
// which should be formatted to 1000 * 10^6
var USDCWithdrawAmountFormatted = ethers.utils.parseUnits(userInputAmount, 6);

// Convert the underlying amount to shares
const cUSDCSharesToRedeem = await cUSDC.convertToShares(USDCWithdrawAmountFormatted);

// Redeem cUSDC for USDC
const underlyingRedeemed = await cUSDC.redeem(depositAmount, recipientAddress);
```

Below is an implementation of using `redeem()`, letting the user choose how much underlying to redeem:

```javascript
// Get the cUSDC contract with signer
const cUSDC = new ethers.Contract(ADDRESSES.CUSDC, CTOKEN_ABI, signer);

// Get the amount of shares to redeem from the user's input amount
// userInputAmount being equal to "1000", representing 1000 USDC
// which should be formatted to 1000 * 10^6
var USDCWithdrawAmountFormatted = ethers.utils.parseUnits(userInputAmount, 6);

// Convert the underlying amount to shares
const cUSDCSharesToRedeem = await cUSDC.convertToShares(USDCWithdrawAmountFormatted);

// Redeem cUSDC for USDC
const underlyingRedeemed = await cUSDC.redeem(depositAmount);
```

#### Using redeemFor

If your app requires you to withdraw on users' behalf, you can use the `redeemFor()` function in the cToken contract using the following function arguments:&#x20;

{% hint style="info" %}
Make sure your platforms' address is approved as a delegate. Visit [Plugin Integration](/app/developer-docs/quick-start-guides/plugin-integration.md) for more information.
{% endhint %}

<table><thead><tr><th width="109">Type</th><th width="243">Parameter</th><th>Description</th></tr></thead><tbody><tr><td>uint256</td><td>assets (if withdrawFor)<br>shares (if redeemFor)</td><td>The number of assets/shares to withdraw/redeem.</td></tr><tr><td>address</td><td>recipient</td><td>The account that should receive the underlying assets.</td></tr></tbody></table>

## Withdrawing Collateral

When withdrawing from collateralized cTokens, you have a few choices of functions to call depending on the needs of your platform.

* `redeemCollateral()` - If you would like to redeem cTokens that *are* currently being used as collateral.
* `redeemCollateralFor()` - If you would like to redeem cTokens that are currently being used as collateral, on behalf of a user. Requires the user to delegate your platform.

{% hint style="info" %}
ERC20 approval is not required for redeeming cTokens.
{% endhint %}

{% hint style="danger" %}
Removing collateral should be done with extreme caution. Removing collateral can increase the user's loan to value ratio, which increases the risk of liquidation.
{% endhint %}


---

# 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.curvance.com/app/developer-docs/quick-start-guides/loans-and-collateral/withdraw.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.
