# Self-Submit On-Chain

For partners who manage their own private keys or custodial wallets.

## Workflow

```mermaid
sequenceDiagram
    participant Client
    participant API
    participant Chain
    participant Indexer

    Client->>API: POST /orders/calldata
    API-->>Client: calldata + toAddress
    Client->>Chain: Submit transaction
    Chain-->>Client: txHash
    Client->>API: POST /orders/tx { txHash }
    API-->>Client: Mapping record
    Indexer->>API: Parse on-chain events, backfill orderId
    Client->>API: GET /orders/{orderId}
    API-->>Client: Order status
```

## Steps

1. Call `/api/v1/orders/calldata`, `/api/v1/cash/deposits/calldata`, or `/api/v1/cash/withdrawals/calldata` to get `toAddress`, `value`, and `callData`.
2. Submit the transaction on-chain using your own wallet system.
3. After obtaining the `txHash`, call the corresponding `/tx` endpoint to record it.
4. The indexer parses on-chain events and backfills `orderId` or `operationId` by `txHash`.
5. Use query endpoints to track status.

## Transaction Recording Endpoints

| Operation   | Endpoint                           |
| ----------- | ---------------------------------- |
| Place Order | `POST /api/v1/orders/tx`           |
| Deposit     | `POST /api/v1/cash/deposits/tx`    |
| Withdraw    | `POST /api/v1/cash/withdrawals/tx` |

## Status Query Endpoints

| Operation   | Endpoint                                                         |
| ----------- | ---------------------------------------------------------------- |
| Place Order | `GET /api/v1/orders/tx/{txHash}`, `GET /api/v1/orders/{orderId}` |
| Deposit     | `GET /api/v1/cash/deposits/{operationId}`                        |
| Withdraw    | `GET /api/v1/cash/withdrawals/{operationId}`                     |

{% hint style="warning" %}
Submitting the same `txHash` from the same API Key returns the existing mapping. If the `txHash` was already recorded by another API Key, the endpoint returns an error.
{% endhint %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.anchored.finance/trading-api-docs-en/integration/self-submit.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
