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

# Plan Earn

> Create a plan to earn yield on a DeFi protocol

# Plan Earn

Creates a plan to deposit assets into a DeFi yield protocol. Returns a plan ID and an EIP-712 digest that must be signed by the account's signer to authorize execution.

## Request

```
POST /accounts/:account_id/plan/earn
```

### Path parameters

| Parameter    | Type   | Description        |
| ------------ | ------ | ------------------ |
| `account_id` | string | The sub-account ID |

### Body parameters

| Parameter  | Type   | Required | Description                                                                                    |
| ---------- | ------ | -------- | ---------------------------------------------------------------------------------------------- |
| `amount`   | string | Yes      | Amount in the asset's smallest unit (e.g., `"1000000"` = 1 USDC)                               |
| `asset`    | string | Yes      | Asset symbol (e.g., `"USDC"`)                                                                  |
| `network`  | string | Yes      | Target network (e.g., `"base"`, `"mainnet"`). Funds on other chains are bridged automatically. |
| `protocol` | string | Yes      | Protocol to earn on (e.g., `"compound"`, `"morpho"`, `"aave"`)                                 |

## Examples

<CodeGroup>
  ```bash cURL theme={null}
  curl -X POST https://prime-api.legend.xyz/accounts/acc_2o0yiljtp378/plan/earn \
    -H "Authorization: Bearer $LEGEND_QUERY_KEY" \
    -H "Content-Type: application/json" \
    -d '{
      "amount": "1000000",
      "asset": "USDC",
      "network": "base",
      "protocol": "compound"
    }'
  ```

  ```typescript TypeScript theme={null}
  const plan = await client.plan.earn("acc_2o0yiljtp378", {
    amount: "1000000",
    asset: "USDC",
    network: "base",
    protocol: "compound",
  });
  ```

  ```python Python theme={null}
  plan = await client.plan.earn(
      "acc_2o0yiljtp378",
      amount="1000000",
      asset="USDC",
      network="base",
      protocol="compound",
  )
  ```

  ```rust Rust theme={null}
  use legend_client::EarnParams;

  let plan = client.plan.earn("acc_2o0yiljtp378", &EarnParams {
      amount: "1000000".into(),
      asset: "USDC".into(),
      network: "base".into(),
      protocol: "compound".into(),
      market: None,
  }).await?;
  ```
</CodeGroup>

```json Response (201 Created) theme={null}
{
  "plan_id": "pln_71mcui082png",
  "details": {
    "quark_operation_actions": [
      {
        "operation": {
          "expiry": "1750012800",
          "is_replayable": false,
          "nonce": "0xcafe...cafe",
          "script_address": "0x72e7e6ce7cb4d28ffe830708be3d30aee286ec24",
          "script_calldata": "0x4d618e3b..."
        },
        "action": {
          "action_context": {
            "action_type": "COMET_SUPPLY",
            "amount": "1000000",
            "asset_symbol": "USDC",
            "chain_id": "8453"
          }
        }
      }
    ],
    "eip712_data": {
      "digest": "0x8a3f...b7c2",
      "domain_separator": "0x...",
      "hash_struct": "0x..."
    }
  },
  "expires_at": "2025-06-15T10:32:00Z"
}
```

### Response fields

| Field                        | Type   | Description                                                 |
| ---------------------------- | ------ | ----------------------------------------------------------- |
| `plan_id`                    | string | Unique identifier for this plan (`pln_` prefix)             |
| `details`                    | object | Transaction details including EIP-712 signing data          |
| `details.eip712_data.digest` | string | The hash to sign with the account's signer key              |
| `expires_at`                 | string | ISO 8601 timestamp — plan must be executed before this time |

## Errors

| Status | Code             | Description                                                  |
| ------ | ---------------- | ------------------------------------------------------------ |
| 400    | `invalid_params` | Missing required parameters or invalid values                |
| 400    | `plan_failed`    | Could not generate a valid plan (e.g., insufficient balance) |
| 400    | `no_wallet`      | Account has no wallets                                       |
| 408    | `timeout`        | Folio computation timed out                                  |

## Notes

* Plans are ephemeral — they're stored temporarily and expire after 2 minutes
* No on-chain state changes until you call [Execute Plan](/api-reference/plan-execute)
* The `amount` is in the asset's smallest unit. For USDC (6 decimals), `"1000000"` = 1 USDC
* Use [List Assets](/api-reference/list-assets) to check supported assets and their decimals
* Use [List Networks](/api-reference/list-networks) to check supported networks
