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

# withdraw

> Resolves a yield, builds the exit action, and signs and submits every transaction in one call.

**Function Signature**

```swift theme={null}
public func withdraw(params: YieldWithdrawParams, options: YieldSubmitOptions?) async throws -> YieldWithdrawResult
```

A convenience overload drops the options argument:

```swift theme={null}
public func withdraw(params: YieldWithdrawParams) async throws -> YieldWithdrawResult
```

**Description**

Runs a complete withdrawal from a yield position: resolves the yield, builds the exit action, then for each returned transaction signs it, submits it, waits for on-chain confirmation, and reports the hash back to Yield.xyz.

Behavior, parameters, and result shape are identical to [`deposit`](./yielddeposit) — `YieldWithdrawParams` and `YieldWithdrawResult` are type aliases for `YieldDepositParams` and `YieldDepositResult`.

Transactions execute sequentially. A transaction confirmed as failed on-chain stops execution with `.failed`; a confirmation timeout stops execution with `.partialSuccess`.

The wallet address is resolved from your `Portal` instance for the chain the yield resolves to — there is no `address` parameter.

**Parameters**

`YieldWithdrawParams` (alias for `YieldDepositParams`):

| Parameter   | Type                      | Required | Description                                                                              |
| ----------- | ------------------------- | -------- | ---------------------------------------------------------------------------------------- |
| `target`    | `YieldActionTarget`       | Yes      | `.yieldId(String)`, or `.chainAndToken(chain:token:)` where `chain` is a full CAIP-2 id. |
| `amount`    | `String`                  | Yes      | Amount to withdraw. Merged into the action arguments.                                    |
| `arguments` | `YieldXyzEnterArguments?` | No       | Protocol-specific inputs.                                                                |

`YieldSubmitOptions`:

| Option                | Type                               | Default | Description                                                                                      |
| --------------------- | ---------------------------------- | ------- | ------------------------------------------------------------------------------------------------ |
| `onProgress`          | `((YieldSubmitProgress) -> Void)?` | `nil`   | Fired per transaction with `.signing`, `.submitted`, `.confirming`, `.confirmed`.                |
| `pollIntervalSeconds` | `Int`                              | `4`     | Seconds between confirmation polls. Clamped to a minimum of `1`.                                 |
| `timeoutSeconds`      | `Int`                              | `900`   | Seconds before a transaction is treated as uncertain. Clamped to at least `pollIntervalSeconds`. |

**Returns**

**`YieldWithdrawResult`** (alias for `YieldDepositResult`):

| Property                  | Type                      | Description                                                            |
| ------------------------- | ------------------------- | ---------------------------------------------------------------------- |
| `hashes`                  | `[String]`                | Submitted transaction hashes, in order. Present regardless of outcome. |
| `yieldId`                 | `String`                  | The resolved yield id.                                                 |
| `status`                  | `YieldSubmitResultStatus` | `.success`, `.partialSuccess`, or `.failed`.                           |
| `chain`                   | `String?`                 | Set only when resolved via `.chainAndToken`.                           |
| `token`                   | `String?`                 | Set only when resolved via `.chainAndToken`.                           |
| `yieldOpportunityDetails` | `YieldOpportunityDetails` | Action metadata.                                                       |

<Warning>
  A non-empty `hashes` array does not mean success. Always branch on `status`.
</Warning>

**Throws**

Throws `YieldXyzError` — the same cases as [`deposit`](./yielddeposit), including `invalidChainId`, `noYieldForChainToken`, `yieldNotFound`, `addressUnavailable`, `noTransactions`, `unsupportedNetwork`, `transactionFailed`, and `apiError`.

**Example Usage**

```swift theme={null}
import PortalSwift

do {
    let result = try await portal.yield.yieldxyz.withdraw(
        params: YieldWithdrawParams(
            target: .yieldId("ethereum-sepolia-link-aave-v3-lending"),
            amount: "0.001"
        )
    )

    print("Status: \(result.status.rawValue)")
    print("Hashes: \(result.hashes)")
} catch let error as YieldXyzError {
    print("Withdraw failed: \(error.errorDescription ?? "unknown")")
}
```

**Related Documentation**

* [Earn with Yield.xyz](../guide/yield-xyz)
* [deposit](./yielddeposit)
* [getValidators](./yieldgetvalidators)
* [Yield.xyz Integration](/integrations/Yield/yield-xyz)
