Skip to main content
POST
/
rpc
/
Trails
/
YieldCreateExitAction
YieldCreateExitAction generates unsigned withdrawal transaction calldata for a yield position.
curl --request POST \
  --url https://trails-api.sequence.app/rpc/Trails/YieldCreateExitAction \
  --header 'Content-Type: application/json' \
  --data '
{
  "earnMarketId": "<string>",
  "userWalletAddress": "<string>",
  "args": {}
}
'
{
  "payload": {}
}

Documentation Index

Fetch the complete documentation index at: https://docs.trails.build/llms.txt

Use this file to discover all available pages before exploring further.

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

FieldTypeRequiredDescription
earnMarketIdstringYesMarket ID from YieldGetMarkets
userWalletAddressstringYesAddress of the withdrawing wallet
argsobjectNoMarket-specific arguments (e.g. amount, shares)

Response

Returns payload containing unsigned transaction data:
FieldDescription
transactionsArray of transaction objects to execute
transactions[].toContract address
transactions[].dataABI-encoded calldata
transactions[].valueETH value (for native token withdrawals)

Examples

Withdraw from an Aave lending position

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):
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

// 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

Body

application/json
earnMarketId
string
required

Market ID from YieldGetMarkets

userWalletAddress
string
required

Wallet address of the user performing the action

args
object

Optional market-specific arguments (e.g. referral codes, slippage)

Response

OK

payload
object
required

JSON object containing unsigned transaction payloads