> ## Documentation Index
> Fetch the complete documentation index at: https://anypay-docs-update-resources-2026-06-29.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# YieldCreateExitAction

> Generate unsigned withdrawal transaction calldata for a DeFi yield position

## Overview

`YieldCreateExitAction` returns the unsigned transaction payload needed to withdraw from a DeFi yield position. It is the counterpart to `YieldCreateEnterAction`.

Use this endpoint to build withdrawal UIs or construct exit calldata for Trails routes. For React apps, the composable action builders handle this automatically.

## Request Parameters

| Field               | Type   | Required | Description                                     |
| ------------------- | ------ | -------- | ----------------------------------------------- |
| `earnMarketId`      | string | Yes      | Market ID from `YieldGetMarkets`                |
| `userWalletAddress` | string | Yes      | Address of the withdrawing wallet               |
| `args`              | object | No       | Market-specific arguments (e.g. amount, shares) |

## Response

Returns `payload` containing unsigned transaction data:

| Field                  | Description                              |
| ---------------------- | ---------------------------------------- |
| `transactions`         | Array of transaction objects to execute  |
| `transactions[].to`    | Contract address                         |
| `transactions[].data`  | ABI-encoded calldata                     |
| `transactions[].value` | ETH value (for native token withdrawals) |

## Examples

### Withdraw from an Aave lending position

```typescript theme={null}
const response = await fetch('https://trails-api.sequence.app/rpc/Trails/YieldCreateExitAction', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
    'X-Access-Key': 'YOUR_ACCESS_KEY',
  },
  body: JSON.stringify({
    earnMarketId: 'base-usdc-aave-v3-lending',
    userWalletAddress: '0xYourWalletAddress',
  }),
})

const { payload } = await response.json()
const action = JSON.parse(payload)
```

### Withdraw a specific amount

Use `args` to pass withdrawal parameters for markets that require them (e.g. partial withdrawals):

```typescript theme={null}
const response = await fetch('https://trails-api.sequence.app/rpc/Trails/YieldCreateExitAction', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
    'X-Access-Key': 'YOUR_ACCESS_KEY',
  },
  body: JSON.stringify({
    earnMarketId: 'ethereum-usdc-morpho-0x...',
    userWalletAddress: '0xYourWalletAddress',
    args: {
      amount: '1000000', // 1 USDC in wei
    },
  }),
})
```

## Common pattern: check balance then exit

```typescript theme={null}
// 1. Check what positions the wallet holds
const balancesRes = await fetch('https://trails-api.sequence.app/rpc/Trails/YieldGetAggregateBalances', {
  method: 'POST',
  headers: { 'Content-Type': 'application/json', 'X-Access-Key': 'YOUR_ACCESS_KEY' },
  body: JSON.stringify({ queries: [{ address: '0xYourWallet', network: 'base' }] }),
})
const { payload: balPayload } = await balancesRes.json()
const balances = JSON.parse(balPayload)

// 2. Build exit calldata for each position
for (const position of balances) {
  const exitRes = await fetch('https://trails-api.sequence.app/rpc/Trails/YieldCreateExitAction', {
    method: 'POST',
    headers: { 'Content-Type': 'application/json', 'X-Access-Key': 'YOUR_ACCESS_KEY' },
    body: JSON.stringify({
      earnMarketId: position.yieldId,
      userWalletAddress: '0xYourWallet',
    }),
  })
  const { payload: exitPayload } = await exitRes.json()
  const exitAction = JSON.parse(exitPayload)
  // Use exitAction.transactions to build and submit the withdrawal
}
```

## See also

* [YieldCreateEnterAction](/api-reference/endpoints/yield-create-enter-action) — Deposit into a position
* [YieldGetAggregateBalances](/api-reference/endpoints/yield-get-balances) — Check existing positions before exiting
* [YieldGetMarkets](/api-reference/endpoints/yield-get-markets) — Discover market IDs


## OpenAPI

````yaml trails-api.gen.json post /rpc/Trails/YieldCreateExitAction
openapi: 3.0.0
info:
  title: Trails API
  version: 0.0.1
servers:
  - url: https://trails-api.sequence.app
    description: Trails API
security: []
paths:
  /rpc/Trails/YieldCreateExitAction:
    post:
      tags:
        - Trails
      summary: >-
        YieldCreateExitAction generates unsigned withdrawal transaction calldata
        for a yield position.
      description: >
        Returns the unsigned transaction payload needed to withdraw from a DeFi
        yield position.

        Counterpart to YieldCreateEnterAction.
      operationId: Trails-YieldCreateExitAction
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CreateYieldActionRequest'
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/CreateYieldActionResponse'
        4XX:
          description: Client error
          content:
            application/json:
              schema:
                oneOf:
                  - $ref: '#/components/schemas/ErrorWebrpcEndpoint'
                  - $ref: '#/components/schemas/ErrorWebrpcRequestFailed'
                  - $ref: '#/components/schemas/ErrorWebrpcBadRoute'
                  - $ref: '#/components/schemas/ErrorWebrpcBadMethod'
                  - $ref: '#/components/schemas/ErrorWebrpcBadRequest'
                  - $ref: '#/components/schemas/ErrorInvalidArgument'
                  - $ref: '#/components/schemas/ErrorUnavailable'
                  - $ref: '#/components/schemas/ErrorNotFound'
        5XX:
          description: Server error
          content:
            application/json:
              schema:
                oneOf:
                  - $ref: '#/components/schemas/ErrorWebrpcBadResponse'
                  - $ref: '#/components/schemas/ErrorWebrpcServerPanic'
                  - $ref: '#/components/schemas/ErrorWebrpcInternalError'
                  - $ref: '#/components/schemas/ErrorUnexpected'
components:
  schemas:
    CreateYieldActionRequest:
      type: object
      required:
        - earnMarketId
        - userWalletAddress
      properties:
        earnMarketId:
          type: string
          description: Market ID from YieldGetMarkets
        userWalletAddress:
          type: string
          description: Wallet address of the user performing the action
        args:
          type: object
          description: Optional market-specific arguments (e.g. referral codes, slippage)
          additionalProperties: true
    CreateYieldActionResponse:
      type: object
      required:
        - payload
      properties:
        payload:
          type: object
          description: JSON object containing unsigned transaction payloads
          additionalProperties: true
    ErrorWebrpcEndpoint:
      type: object
      required:
        - error
        - code
        - msg
        - status
      properties:
        error:
          type: string
          example: WebrpcEndpoint
        code:
          type: number
          example: 0
        msg:
          type: string
          example: endpoint error
        cause:
          type: string
        status:
          type: number
          example: 400
    ErrorWebrpcRequestFailed:
      type: object
      required:
        - error
        - code
        - msg
        - status
      properties:
        error:
          type: string
          example: WebrpcRequestFailed
        code:
          type: number
          example: -1
        msg:
          type: string
          example: request failed
        cause:
          type: string
        status:
          type: number
          example: 400
    ErrorWebrpcBadRoute:
      type: object
      required:
        - error
        - code
        - msg
        - status
      properties:
        error:
          type: string
          example: WebrpcBadRoute
        code:
          type: number
          example: -2
        msg:
          type: string
          example: bad route
        cause:
          type: string
        status:
          type: number
          example: 404
    ErrorWebrpcBadMethod:
      type: object
      required:
        - error
        - code
        - msg
        - status
      properties:
        error:
          type: string
          example: WebrpcBadMethod
        code:
          type: number
          example: -3
        msg:
          type: string
          example: bad method
        cause:
          type: string
        status:
          type: number
          example: 405
    ErrorWebrpcBadRequest:
      type: object
      required:
        - error
        - code
        - msg
        - status
      properties:
        error:
          type: string
          example: WebrpcBadRequest
        code:
          type: number
          example: -4
        msg:
          type: string
          example: bad request
        cause:
          type: string
        status:
          type: number
          example: 400
    ErrorInvalidArgument:
      type: object
      required:
        - error
        - code
        - msg
        - status
      properties:
        error:
          type: string
          example: InvalidArgument
        code:
          type: number
          example: 2000
        msg:
          type: string
          example: Invalid argument
        cause:
          type: string
        status:
          type: number
          example: 400
    ErrorUnavailable:
      type: object
      required:
        - error
        - code
        - msg
        - status
      properties:
        error:
          type: string
          example: Unavailable
        code:
          type: number
          example: 2002
        msg:
          type: string
          example: Unavailable resource
        cause:
          type: string
        status:
          type: number
          example: 400
    ErrorNotFound:
      type: object
      required:
        - error
        - code
        - msg
        - status
      properties:
        error:
          type: string
          example: NotFound
        code:
          type: number
          example: 8000
        msg:
          type: string
          example: Resource not found
        cause:
          type: string
        status:
          type: number
          example: 400
    ErrorWebrpcBadResponse:
      type: object
      required:
        - error
        - code
        - msg
        - status
      properties:
        error:
          type: string
          example: WebrpcBadResponse
        code:
          type: number
          example: -5
        msg:
          type: string
          example: bad response
        cause:
          type: string
        status:
          type: number
          example: 500
    ErrorWebrpcServerPanic:
      type: object
      required:
        - error
        - code
        - msg
        - status
      properties:
        error:
          type: string
          example: WebrpcServerPanic
        code:
          type: number
          example: -6
        msg:
          type: string
          example: server panic
        cause:
          type: string
        status:
          type: number
          example: 500
    ErrorWebrpcInternalError:
      type: object
      required:
        - error
        - code
        - msg
        - status
      properties:
        error:
          type: string
          example: WebrpcInternalError
        code:
          type: number
          example: -7
        msg:
          type: string
          example: internal error
        cause:
          type: string
        status:
          type: number
          example: 500
    ErrorUnexpected:
      type: object
      required:
        - error
        - code
        - msg
        - status
      properties:
        error:
          type: string
          example: Unexpected
        code:
          type: number
          example: 2001
        msg:
          type: string
          example: Unexpected server error
        cause:
          type: string
        status:
          type: number
          example: 500

````