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

# Quickstart

> Get started with the Earn, Trade, and Borrow APIs. Authenticate, discover opportunities, construct transactions, sign, submit, and track positions.

Yield.xyz has three products, **Earn, Trade and Borrow**, and each has its own API. You can offer staking, DeFi, RWAs, perpetual futures and lending markets without building or maintaining the protocol and venue integrations yourself.

All three APIs use the same API key and the same flow: find an opportunity, request an action, sign the transactions that come back, and track the result. Each API has its own endpoints and transaction formats, which the examples below cover.

![Integration flow: you authenticate, Yield.xyz lists opportunities and builds unsigned transactions, you sign and execute them, and Yield.xyz tracks the result and returns balances and positions to your app](https://mintcdn.com/yieldxyz/IswwmcK-YTSPaIqU/images/documentation/get-started/integration-flow.png?fit=max\&auto=format\&n=IswwmcK-YTSPaIqU\&q=85\&s=e0a7df12bba2ef36b4fc1271d0ea006c)

> [card] [Earn API](#earn-api)
>
> Integrate staking, DeFi, stablecoin yield, and tokenized RWAs.

> [card] [Trade: Perps API](#perps-api)
>
> Open and manage perpetual futures positions on Hyperliquid.

> [card] [Borrow API](#borrow-api)
>
> Supply collateral, borrow assets, repay loans, and manage lending positions.

> [!NOTE]
>
> Yield.xyz builds every transaction and returns it unsigned, as transaction data or a signable payload. Your application, wallet or custody provider signs it, then either broadcasts it or returns it for Yield.xyz to submit. Yield.xyz never holds user funds or private keys.

## Before you start

Create a team and project in the [Yield.xyz dashboard](https://dashboard.yield.xyz), then generate an API key. Include the key in the `x-api-key` header when making requests to the APIs.

Your project determines which products and opportunities are available to your integration. Some capabilities, including Borrow and certain trading integrations, may require access to be enabled for your team.

| API | Base URL | What it covers |
| - | - | - |
| **Earn API** | `https://api.yield.xyz/v1` | Staking, DeFi, stablecoin yield, and RWAs |
| **Perps API** (Trade) | `https://perps.yield.xyz/v1` | Perpetual futures trading |
| **Borrow API** | `https://borrow.yield.xyz/v1` | Lending markets and collateralized borrowing |

> [!NOTE]
>
> Trade is live today through the Perps API, for perpetual futures on Hyperliquid. The Trade API, coming soon, replaces it with `buy`, `sell` and `manage` across perps, spot, prediction markets and tokenized stocks. See [Trade](https://docs.yield.xyz/documentation/trade/index.md).

For account, team and API key setup, see [Onboarding](https://docs.yield.xyz/documentation/get-started/onboarding.md).

## Earn API

The Earn API provides access to **4,000+ yield opportunities across 85+ networks**, including staking, DeFi, stablecoin strategies, and tokenized real-world assets.

The integration follows a consistent lifecycle: discover an opportunity, inspect its requirements, construct an action, sign and submit the transactions, and track the resulting position.

**1. Discover available yields**

Use [`GET /v1/yields`](https://docs.yield.xyz/api-reference/YieldsController_getYields) to retrieve the opportunities enabled for your project. You can filter the results by network, token, provider, or yield type, depending on the available query parameters.

Each opportunity has a unique `id`, which is used when requesting actions and retrieving position information.

```bash cURL theme={null}
curl --request GET \
  --url 'https://api.yield.xyz/v1/yields?network=ethereum&limit=10' \
  --header "x-api-key: $YIELD_API_KEY"
```

```typescript TypeScript theme={null}
const response = await fetch(
  'https://api.yield.xyz/v1/yields?network=ethereum&limit=10',
  {
    headers: {
      'x-api-key': process.env.YIELD_API_KEY!,
    },
  },
);

if (!response.ok) {
  throw new Error(`Failed to fetch yields: ${response.status}`);
}

const { items } = await response.json();
```

> [!NOTE]
>
> `GET /v1/yields` returns opportunities enabled for your project. Enable additional yields in the dashboard before attempting to discover or integrate them.

See [Discover](https://docs.yield.xyz/documentation/earn/core-concepts/discover.md) for available filters and discovery options.

**2. Inspect the required arguments**

Fetch the selected opportunity using [`GET /v1/yields/{yieldId}`](https://docs.yield.xyz/api-reference/YieldsController_getYield).

The response includes `mechanics.arguments.enter.fields`, which describes the inputs required to construct an enter action. These requirements can differ between opportunities.

For example, an ETH staking opportunity may require an `amount`, while validator-based staking can require additional information such as `validatorAddress`.

```bash cURL theme={null}
curl --request GET \
  --url 'https://api.yield.xyz/v1/yields/ethereum-eth-lido-staking' \
  --header "x-api-key: $YIELD_API_KEY"
```

```json Response (truncated) theme={null}
{
  "id": "ethereum-eth-lido-staking",
  "mechanics": {
    "arguments": {
      "enter": {
        "fields": [
          {
            "name": "amount",
            "required": true
          }
        ]
      }
    }
  }
}
```

Always inspect the opportunity's metadata rather than assuming the same arguments apply to every yield.

See [Yield metadata](https://docs.yield.xyz/documentation/earn/core-concepts/yield-metadata.md) for the complete schema.

**3. Construct an enter action**

Call [`POST /v1/actions/enter`](https://docs.yield.xyz/api-reference/ActionsController_enterYield) with the selected `yieldId`, the user's wallet `address`, and the required `arguments`.

The response contains an action with an ordered `transactions` array. Each transaction includes the unsigned transaction data required for execution.

```bash cURL theme={null}
curl --request POST \
  --url 'https://api.yield.xyz/v1/actions/enter' \
  --header "x-api-key: $YIELD_API_KEY" \
  --header 'content-type: application/json' \
  --data '{
    "yieldId": "ethereum-eth-lido-staking",
    "address": "0xYOUR_WALLET_ADDRESS",
    "arguments": {
      "amount": "0.1"
    }
  }'
```

```typescript TypeScript theme={null}
const response = await fetch(
  'https://api.yield.xyz/v1/actions/enter',
  {
    method: 'POST',
    headers: {
      'x-api-key': process.env.YIELD_API_KEY!,
      'content-type': 'application/json',
    },
    body: JSON.stringify({
      yieldId: 'ethereum-eth-lido-staking',
      address: '0xYOUR_WALLET_ADDRESS',
      arguments: {
        amount: '0.1',
      },
    }),
  },
);

if (!response.ok) {
  throw new Error(`Failed to create action: ${response.status}`);
}

const action = await response.json();

// Execute action.transactions in the returned order.
```

Some opportunities require multiple transactions, such as token approvals followed by a deposit. Execute the transactions in the order returned by the API.

See [Actions](https://docs.yield.xyz/documentation/earn/core-concepts/actions.md) for supported action types and transaction handling.

**4. Sign, submit, and track transactions**

Pass each `unsignedTransaction` to your application's signer, which can be an EOA, smart account, MPC wallet, or institutional custody provider.

Once a transaction has been signed and broadcast, report its hash using [`PUT /v1/transactions/{transactionId}/submit-hash`](https://docs.yield.xyz/api-reference/TransactionsController_submitTransactionHash).

```bash cURL theme={null}
curl --request PUT \
  --url "https://api.yield.xyz/v1/transactions/$TRANSACTION_ID/submit-hash" \
  --header "x-api-key: $YIELD_API_KEY" \
  --header 'content-type: application/json' \
  --data '{
    "hash": "0xYOUR_TRANSACTION_HASH"
  }'
```

The transaction status is updated as execution progresses. Track the action until the required transactions reach a terminal state, such as `SUCCESS` or `FAILED`.

> [!NOTE]
>
> Reporting a transaction hash allows Yield.xyz to track execution. It does not replace broadcasting the signed transaction through your wallet or transaction provider.

**5. Retrieve the resulting position**

After execution, use [`POST /v1/yields/{yieldId}/balances`](https://docs.yield.xyz/api-reference/YieldsController_getYieldBalances) to retrieve the user's position.

```bash cURL theme={null}
curl --request POST \
  --url 'https://api.yield.xyz/v1/yields/ethereum-eth-lido-staking/balances' \
  --header "x-api-key: $YIELD_API_KEY" \
  --header 'content-type: application/json' \
  --data '{
    "address": "0xYOUR_WALLET_ADDRESS"
  }'
```

Position data can include lifecycle states such as `active`, `entering`, `exiting`, `withdrawable`, `claimable`, and `locked`.

Some positions also expose `pendingActions`, including reward claims or withdrawal-related actions. These can be handled through the corresponding manage flow using `POST /v1/actions/manage`.

See [Balances and positions](https://docs.yield.xyz/documentation/earn/core-concepts/balances-positions.md) for lifecycle states, pending actions, and position management.

## Perps API

The Perps API lets applications offer perpetual futures trading on Hyperliquid without integrating the venue directly.

The API returns markets, builds trading actions for you to sign, submits the signed orders to the venue and tracks positions. The following example opens a leveraged position on Hyperliquid.

**1. Discover trading markets**

Use `GET /v1/markets` to retrieve available markets. Filter by `providerId` to select a supported trading venue.

Market information includes identifiers, leverage limits, trading fees, funding rates, and minimum position requirements.

```bash cURL theme={null}
curl --request GET \
  --url 'https://perps.yield.xyz/v1/markets?providerId=hyperliquid&limit=10' \
  --header "x-api-key: $YIELD_API_KEY"
```

Select a market and retain its `id` for the trading action.

**2. Construct a trading action**

Use `POST /v1/actions` to construct an order.

The request includes the trading venue, wallet address, action type, and market-specific arguments.

To open a position, provide the market, direction, margin or position size, and leverage.

```bash cURL theme={null}
curl --request POST \
  --url 'https://perps.yield.xyz/v1/actions' \
  --header "x-api-key: $YIELD_API_KEY" \
  --header 'content-type: application/json' \
  --data '{
    "providerId": "hyperliquid",
    "address": "0xYOUR_WALLET_ADDRESS",
    "action": "open",
    "args": {
      "marketId": "YOUR_MARKET_ID",
      "side": "long",
      "amount": "100",
      "leverage": 5
    }
  }'
```

In this example, `amount` represents the margin in USD, while `leverage` determines the corresponding position notional.

You can alternatively provide `size` to specify the position size in USD. The position notional must meet the venue's minimum requirement, which is at least 10 USD for the example described here.

> [!NOTE]
>
> The trading account must have sufficient available margin before opening a position. If funding is required, use the supported `fund` action before submitting the order.

**3. Sign and submit the transaction**

The action response contains transactions with a `signingFormat` and `signablePayload`.

Trading actions may use typed-data signing, such as `EIP712_TYPED_DATA`, rather than a standard unsigned blockchain transaction.

Sign the returned payload using your wallet or signing provider, then submit the signature through `POST /v1/transactions/{transactionId}/submit`.

```bash cURL theme={null}
curl --request POST \
  --url "https://perps.yield.xyz/v1/transactions/$TRANSACTION_ID/submit" \
  --header "x-api-key: $YIELD_API_KEY" \
  --header 'content-type: application/json' \
  --data '{
    "signedPayload": "0xYOUR_SIGNATURE"
  }'
```

Yield.xyz submits the signed payload to the supported trading venue.

**4. Track open positions**

Use `POST /v1/positions` to retrieve positions associated with the user's wallet and trading venue.

```bash cURL theme={null}
curl --request POST \
  --url 'https://perps.yield.xyz/v1/positions' \
  --header "x-api-key: $YIELD_API_KEY" \
  --header 'content-type: application/json' \
  --data '{
    "address": "0xYOUR_WALLET_ADDRESS",
    "providerId": "hyperliquid"
  }'
```

Position data can be used to display open positions, unrealized PnL, and other available trading information.

The same API also supports additional trading actions for managing positions, subject to the capabilities of the selected venue.

See [Perpetual futures](https://docs.yield.xyz/documentation/trade/perps.md) for supported actions, funding, position management, and builder fees.

## Borrow API

The Borrow API lets users borrow against their crypto across Aave V3, SparkLend, Morpho Blue and Lista, with Compound V3 being added. Every market is returned in the same shape.

You can discover lending markets, supply assets, enable collateral where required, borrow, repay and withdraw through the same action model.

**1. Discover lending markets**

Use `GET /v1/markets` to retrieve supported lending markets.

Markets can be filtered by network or integration, and each result includes an `id` and the `integrationId` identifying the underlying protocol integration.

```bash cURL theme={null}
curl --request GET \
  --url 'https://borrow.yield.xyz/v1/markets?network=base&limit=10' \
  --header "x-api-key: $YIELD_API_KEY"
```

Select the appropriate market based on the user's collateral asset, borrowing requirements, and available market information.

**2. Construct a lending action**

Call `POST /v1/actions` with the market's `integrationId`, the user's address, the requested action, and its arguments.

Supported actions include:

| Action | Description |
| - | - |
| `supply` | Supply an asset to a lending market |
| `borrow` | Borrow an asset against available collateral |
| `repay` | Repay an outstanding borrowing position |
| `withdraw` | Withdraw supplied assets |
| `enableCollateral` | Enable a supplied asset as collateral on supported pooled markets |
| `disableCollateral` | Disable collateral usage on supported pooled markets |

The example below constructs a supply action.

```bash cURL theme={null}
curl --request POST \
  --url 'https://borrow.yield.xyz/v1/actions' \
  --header "x-api-key: $YIELD_API_KEY" \
  --header 'content-type: application/json' \
  --data '{
    "integrationId": "YOUR_INTEGRATION_ID",
    "action": "supply",
    "address": "0xYOUR_WALLET_ADDRESS",
    "args": {
      "marketId": "YOUR_MARKET_ID",
      "amount": "100"
    }
  }'
```

Some markets require additional arguments. For example, pooled lending markets such as Aave and SparkLend may require a `tokenAddress` to identify the asset.

> [!NOTE]
>
> `enableCollateral` and `disableCollateral` apply to supported pooled markets.

**3. Sign and submit transactions**

The action response contains transactions with a `signingFormat` and `signablePayload`.

Sign and submit the transactions one at a time, in the order returned, using `POST /v1/transactions/{transactionId}/submit`. Before you submit the next one, poll `GET /v1/actions/{id}` until the previous transaction is `CONFIRMED`: a `SUPPLY` submitted before its `APPROVAL` confirms reverts.

If you have already broadcast the transaction, provide its hash:

```bash cURL theme={null}
curl --request POST \
  --url "https://borrow.yield.xyz/v1/transactions/$TRANSACTION_ID/submit" \
  --header "x-api-key: $YIELD_API_KEY" \
  --header 'content-type: application/json' \
  --data '{
    "transactionHash": "0xYOUR_TRANSACTION_HASH"
  }'
```

Alternatively, you can provide `signedPayload` and let Yield.xyz broadcast the signed transaction.

An action can return several transactions, for example an `APPROVAL` before a `SUPPLY`. Submit them in order, and wait for each one to confirm before you submit the next. Every transaction comes back in the first response: Borrow actions return `hasNextStep: false`, so there is no next step to request.

**4. Retrieve the borrowing position**

Use `GET /v1/positions` with the user's wallet address, network, and protocol integration.

```bash cURL theme={null}
curl --request GET \
  --url 'https://borrow.yield.xyz/v1/positions?integrationId=YOUR_INTEGRATION_ID&network=base&address=0xYOUR_WALLET_ADDRESS' \
  --header "x-api-key: $YIELD_API_KEY"
```

The returned position data can be used to display supplied collateral, outstanding debt, borrowing rates, and available position health information.

Continue monitoring the position as users borrow, repay, or withdraw assets.

See [Borrow](https://docs.yield.xyz/documentation/borrow/index.md) for lending markets, collateral management, positions, and supported borrowing actions, and the [Borrow API guide](https://docs.yield.xyz/guides/borrow/index.md) for the full lifecycle with every request.

## Before you go live

Before making your integration available to users, verify that your project configuration, transaction handling, and security controls are ready.

| Area | What to verify |
| - | - |
| **API access** | Your credentials are valid and the required products are enabled in the dashboard |
| **Product configuration** | Required yields, trading markets, and lending markets are enabled for your project |
| **Transaction handling** | Your application correctly handles signing, submission, execution order, and transaction failures |
| **Position tracking** | Balances, positions, and transaction states are updated correctly |
| **Security** | API keys are stored securely and transaction validation is integrated where applicable |
| **Compliance** | Required geographic restrictions and other applicable controls are configured |
| **Monetization** | Supported fee configurations and payout destinations are verified |
| **Error handling** | Your application handles failed requests, rejected signatures, pending transactions, and incomplete actions |

For additional transaction protection, use [Shield](https://docs.yield.xyz/documentation/security/shield/index.md), which checks each transaction against the pattern expected for it before you sign.

## Next steps

Once you've completed your first API request, explore the guides and references for the product you're integrating. You can also build with AI development tools and AgentKit.

> [card] [Earn](https://docs.yield.xyz/documentation/earn/index.md)
>
> Explore yield discovery, transaction actions, balances, and position management.

> [card] [Trade](https://docs.yield.xyz/documentation/trade/index.md)
>
> Build perpetual futures trading, funding, and position management flows.

> [card] [Borrow](https://docs.yield.xyz/documentation/borrow/index.md)
>
> Integrate lending markets, collateral management, and borrowing actions.

> [card] [Build with AI](https://docs.yield.xyz/documentation/ai-agents/index.md)
>
> Use AI coding assistants, the MCP server, and AgentKit to build integrations.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.