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

# Deposit

> Build a ready-to-sign deposit into an opportunity, including the swap-mode variant, and broadcast it

> [!NOTE]
>
> Requires an API key via the `X-API-Key` header. See [API Keys](https://docs.turtle.xyz/sdk/authentication/api-keys.md).&#x20;

> [!NOTE]
>
> The user must be a registered [Turtle member](https://docs.turtle.xyz/sdk/authentication/register-wallet.md) before you can deposit on their behalf. A non-member request fails (see Error Handling).

Depositing is three moves: build the deposit, have the user broadcast the returned transactions in order, then attribution lands on its own. Direct and swap deposits use the same endpoint and differ only by the `mode` field. For the concept behind direct vs swap and instant vs async, see [Deposit modes](https://docs.turtle.xyz/sdk/concepts/deposit-modes.md).

## Overview

`POST /v2/actions/deposit/{opportunityId}`

The endpoint returns an `actionId` and an ordered `transactions` array. The user signs and submits each transaction in sequence (for an ERC-20 deposit, typically an `approve` followed by a `deposit`).

## Build the deposit

Pass the user's address, the input token, the amount in the token's smallest unit, and your `distributorId`. Use `mode: "direct"` to deposit the vault's native token.

```bash curl theme={null}
curl -X POST "https://earn.turtle.xyz/v2/actions/deposit/{opportunityId}" \
  -H "X-API-Key: pk_live_xxxxx" \
  -H "Content-Type: application/json" \
  -d '{
    "userAddress": "0x1234...",
    "tokenIn": "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
    "amount": "1000000",
    "distributorId": "your-distributor-id",
    "mode": "direct",
    "slippageBps": 50
  }'
```

```typescript TypeScript theme={null}
const opportunityId = '550e8400-e29b-41d4-a716-446655440000';

const response = await fetch(
  `https://earn.turtle.xyz/v2/actions/deposit/${opportunityId}`,
  {
    method: 'POST',
    headers: { 'X-API-Key': 'pk_live_xxxxx', 'Content-Type': 'application/json' },
    body: JSON.stringify({
      userAddress: '0x1234...',
      tokenIn: '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48', // USDC
      amount: '1000000', // 1 USDC (6 decimals)
      distributorId: 'your-distributor-id',
      mode: 'direct',
      slippageBps: 50,
    }),
  }
);
const data = await response.json();
```

**Path Parameters**

**opportunityId** `uuid` *required*

The opportunity to deposit into. Get it from [Get Opportunities](https://docs.turtle.xyz/sdk/opportunities/get-opportunities.md). IDs are UUIDs.

**Body Parameters**

**userAddress** `string` *required*

The user's EVM wallet address. Must belong to a registered Turtle member.

**tokenIn** `string` *required*

Address of the token being deposited. Must be supported on the opportunity's chain. Cannot be the vault's receipt token.

**amount** `string` *required*

Deposit amount in the token's smallest unit (wei). Must be greater than 0.

**distributorId** `string` *required*

Your distributor ID. Embedded into the deposit calldata for [automatic attribution](https://docs.turtle.xyz/sdk/concepts/distributor-model.md).

**mode** `string` (default: direct)

`direct` deposits the vault's native token. `swap` routes a different input token through a DEX first. See the swap-mode section below.

**slippageBps** `integer` (default: 50)

Maximum acceptable slippage in basis points, applied in `swap` mode. `50` = 0.5%.

**referralCode** `string`

Optional referral code for deposit attribution.

**Response**

```json theme={null}
{
  "actionId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
  "transactions": [
    {
      "type": "approve",
      "transaction": {
        "to": "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
        "data": "0x095ea7b3000000000000000000000000...",
        "value": "0",
        "gasLimit": "60000",
        "chainId": 1
      },
      "description": "Approve USDC spending"
    },
    {
      "type": "deposit",
      "transaction": {
        "to": "0x...",
        "data": "0x...",
        "value": "0",
        "gasLimit": "250000",
        "chainId": 1
      },
      "description": "Deposit USDC into vault"
    }
  ]
}
```

### Transaction Object

Each transaction in the `transactions` array contains:

**type** `string` *required*

Transaction type, e.g. `approve`, `deposit`, `withdraw`, `claimDeposit`, `cancelDeposit`.

**transaction** `object` *required*

The raw transaction data to sign and submit.

**transaction.to** `string` *required*

Target contract address.

**transaction.data** `string` *required*

Encoded calldata (hex string with `0x` prefix).

**transaction.value** `string` *required*

Value in wei. Usually `"0"` for token interactions; non-zero for native token deposits.

**transaction.gasLimit** `string` *required*

Estimated gas limit.

**transaction.chainId** `integer` *required*

Chain ID for the transaction.

**description** `string` *required*

Human-readable description of what this transaction does.

**metadata** `object`

Optional metadata for swap transactions, including provider info, amount out, gas estimate, and route details.

## Swap mode

When the user wants to deposit a token that is not the vault's native deposit token, set `mode` to `swap` and pass that token as `tokenIn`. The API routes the swap through a DEX before depositing. Swap mode is available when `swapRouteEnabled` is `true` on the opportunity. See [Deposit modes](https://docs.turtle.xyz/sdk/concepts/deposit-modes.md) for the full availability matrix.

```bash curl theme={null}
curl -X POST "https://earn.turtle.xyz/v2/actions/deposit/{opportunityId}" \
  -H "X-API-Key: pk_live_xxxxx" \
  -H "Content-Type: application/json" \
  -d '{
    "userAddress": "0x1234...",
    "tokenIn": "0xInputTokenAddress",
    "amount": "1000000",
    "distributorId": "your-distributor-id",
    "mode": "swap",
    "slippageBps": 100
  }'
```

```typescript TypeScript theme={null}
const opportunityId = '550e8400-e29b-41d4-a716-446655440000';

const response = await fetch(
  `https://earn.turtle.xyz/v2/actions/deposit/${opportunityId}`,
  {
    method: 'POST',
    headers: { 'X-API-Key': 'pk_live_xxxxx', 'Content-Type': 'application/json' },
    body: JSON.stringify({
      userAddress: '0x1234...',
      tokenIn: '0xInputTokenAddress',
      amount: '1000000',
      distributorId: 'your-distributor-id',
      mode: 'swap',
      slippageBps: 100,
    }),
  }
);
const action = await response.json();
```

The swap-mode response carries swap details in each transaction's `metadata` (provider, amount out, route). The rest of the broadcast flow is identical.

## Broadcast

Sign and submit each transaction in the returned order. Wait for each to confirm before sending the next, since a later transaction often depends on an earlier one (a `deposit` cannot land before its `approve`).

```typescript theme={null}
// 1. Build the deposit action
const depositResponse = await fetch(
  `https://earn.turtle.xyz/v2/actions/deposit/${opportunityId}`,
  {
    method: 'POST',
    headers: { 'X-API-Key': 'pk_live_xxxxx', 'Content-Type': 'application/json' },
    body: JSON.stringify({
      userAddress: walletAddress,
      tokenIn: '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48',
      amount: '1000000000', // 1000 USDC
      distributorId: 'your-distributor-id',
      mode: 'direct',
    }),
  }
);
const { actionId, transactions } = await depositResponse.json();

// 2. Sign and submit each transaction in order
for (const tx of transactions) {
  const txResponse = await wallet.sendTransaction(tx.transaction);
  await txResponse.wait(); // wait for on-chain confirmation before the next
}

// 3. Attribution is automatic. Turtle detects the tracking signature in
//    the deposit calldata and attributes it to your distributor.
```

## Verify the deposit

Attribution is automatic, so there is nothing to call to record it. If you want to confirm a specific deposit carried your tracking data, pass its transaction hash to the verify endpoint. That step has its own page: [Verify Attribution](https://docs.turtle.xyz/sdk/earn/verify-attribution.md).

If the opportunity is async (`complex` settlement), the deposit will sit pending until you claim it. Handle that on [Async Deposits](https://docs.turtle.xyz/sdk/earn/async-deposits.md).

## Operational Notes

> [accordion] Amount is in the token's smallest unit
>
> `amount` is in wei for the input token's decimals. 1 USDC (6 decimals) is `"1000000"`; 1 DAI (18 decimals) is `"1000000000000000000"`. Pass the raw integer string. Never send a human-readable decimal.

> [accordion] Submit transactions in order
>
> The `transactions` array is ordered. An ERC-20 deposit returns an `approve` then a `deposit`. Confirm each before broadcasting the next.

> [accordion] Swap mode needs swapRouteEnabled
>
> `mode: "swap"` only works when the opportunity has `swapRouteEnabled: true`. Read availability off the opportunity object. See [Deposit modes](https://docs.turtle.xyz/sdk/concepts/deposit-modes.md).

> [accordion] Async vaults need a claim step
>
> For opportunities with `complex` settlement (for example Mellow, Lagoon), the deposit queues and is not active until claimed. See [Async Deposits](https://docs.turtle.xyz/sdk/earn/async-deposits.md).

> [accordion] Membership is required
>
> The user must be a registered Turtle member. Complete the [membership flow](https://docs.turtle.xyz/sdk/authentication/register-wallet.md) first.

## Error Handling

> [accordion] User is not a Turtle member
>
> **Status:** 403 Forbidden
>
> ```json theme={null}
> {
>   "error": "not_a_member",
>   "message": "User is not a Turtle member. Please complete the membership flow first.",
>   "docsUrl": "https://docs.turtle.xyz/sdk/authentication/register-wallet"
> }
> ```
>
> **Solution:** Complete the [membership flow](https://docs.turtle.xyz/sdk/authentication/register-wallet.md) before depositing.&#x20;

> [accordion] Distributor not found
>
> **Status:** 404 Not Found
>
> ```json theme={null}
> {
>   "error": "distributor_not_found",
>   "message": "Distributor not found with the provided ID"
> }
> ```
>
> **Solution:** Verify your distributor ID is correct and active.

> [accordion] Opportunity not found
>
> **Status:** 404 Not Found
>
> ```json theme={null}
> {
>   "error": "opportunity_not_found",
>   "message": "Opportunity not found"
> }
> ```
>
> **Solution:** Check the opportunity ID with [Get Opportunities](https://docs.turtle.xyz/sdk/opportunities/get-opportunities.md).

> [accordion] Deposits disabled
>
> **Status:** 400 Bad Request
>
> ```json theme={null}
> {
>   "error": "deposits_disabled",
>   "message": "Deposits are disabled for this opportunity"
> }
> ```
>
> **Solution:** Deposits are temporarily disabled for this opportunity. Try a different one.

> [accordion] Unsupported token
>
> **Status:** 400 Bad Request
>
> ```json theme={null}
> {
>   "error": "invalid_token",
>   "message": "Token 0x... not supported for chain 1"
> }
> ```
>
> **Solution:** Use a supported deposit token. Check the opportunity's `depositTokens` array.

> [accordion] Insufficient token balance
>
> **Status:** 400 Bad Request
>
> ```json theme={null}
> {
>   "code": 400,
>   "status": "INVALID_ARGUMENT",
>   "error": "insufficient token balance"
> }
> ```
>
> The API reads the user's on-chain balance of `tokenIn` before building the transactions and rejects the request when the wallet holds less than `amount`. Native-token deposits are checked against the wallet's native balance.
>
> **Solution:** Reduce `amount` to at most the wallet's balance of `tokenIn`, or top the wallet up before retrying.


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