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

# lockCollateral: Deposit Funds into a Market Deployer

> Move funds from your chain-level balance into a market deployer cross margin pool, making them available as margin for trading that deployer's contracts.

When you want to trade contracts under a specific market deployer (MD), you first need to move funds from your chain-level balance into that deployer's cross margin pool. The `lockCollateral` action performs this transfer — your total funds remain constant, since this is a reallocation rather than a deposit or mint. Once locked, those funds are available as margin for any contracts offered by that market deployer.

<Note>
  You must be enrolled in the target market deployer before calling `lockCollateral`. If you haven't enrolled yet, see [`enrollUserToMarketDeployer`](/exchange/enroll-user-to-market-deployer).
</Note>

## Endpoint

```
POST https://dev.upsidemax.xyz/exchange
```

## Request

Every request must carry an ECDSA signature and a nonce to prevent replay attacks.

```json theme={"system"}
{
  "action": {
    "type": "lockCollateral",
    "marketDeployerId": 1,
    "coinId": 1,
    "amount": "1000"
  },
  "signature": { "r": "0x...", "s": "0x...", "v": 28 },
  "nonce": 1778858900000
}
```

### Action parameters

<ParamField body="marketDeployerId" type="int32" required>
  The ID of the market deployer you want to fund. You must already be enrolled in this deployer.
</ParamField>

<ParamField body="coinId" type="int32" required>
  The coin or currency ID to transfer. Must match a coin supported by the target market deployer.
</ParamField>

<ParamField body="amount" type="string" required>
  The amount to transfer, expressed as a raw integer string (e.g. `"1000"`). Must be greater than zero. Decimals are not accepted — use the coin's smallest unit.
</ParamField>

## Response

A successful transfer returns the updated balances for both your chain-level ledger and the market deployer's cross margin pool.

```json theme={"system"}
{
  "status": "ok",
  "response": {
    "type": "lockCollateral",
    "data": {
      "coinId": 1,
      "amount": 1000,
      "ledgerAfter": 5000,
      "marketDeployerAfter": 3000
    }
  }
}
```

<ResponseField name="coinId" type="int32">
  The coin ID that was transferred, confirming which asset was moved.
</ResponseField>

<ResponseField name="amount" type="int64">
  The amount that was transferred into the market deployer's cross margin pool.
</ResponseField>

<ResponseField name="ledgerAfter" type="int64">
  Your chain-level balance for this coin after the transfer.
</ResponseField>

<ResponseField name="marketDeployerAfter" type="int64">
  Your cross margin balance within the target market deployer after the transfer.
</ResponseField>

## Errors

If the request cannot be fulfilled, the exchange still returns **HTTP 200** with `status: "ok"` — the rejection is reported inside `response.data`, where a server-assigned integer `errorCode` and a human-readable `errorMessage` are populated while the numeric amount and balance fields are set to `0`. Common causes include:

* **Insufficient chain-level balance** — the requested `amount` exceeds your available chain-level funds for the given coin.
* **Not enrolled in the market deployer** — you must enroll before locking collateral into an MD.
* **Amount ≤ 0** — the `amount` field must be a positive integer string.

```json theme={"system"}
{
  "status": "ok",
  "response": {
    "type": "lockCollateral",
    "data": {
      "coinId": 0,
      "amount": 0,
      "ledgerAfter": 0,
      "marketDeployerAfter": 0,
      "errorCode": 1,
      "errorMessage": "insufficient chain-level balance"
    }
  }
}
```

<Tip>
  To move funds in the opposite direction — from a market deployer back to your chain-level balance — use [`unlockCollateral`](/exchange/unlock-collateral).
</Tip>
