> For the complete documentation index, see [llms.txt](https://docs.anchored.finance/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.anchored.finance/trading-api/guides/self-submit-on-chain.md).

# Self-Submit On-Chain

For integrators who sign and broadcast transactions with their own wallet or custodian.

## 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 `/calldata` for the operation:
   * Orders: `POST /api/v1/orders/calldata`
   * Deposits: `POST /api/v1/cash/deposits/calldata`
   * Withdrawals: `POST /api/v1/cash/withdrawals/calldata`
2. Submit `toAddress`, `value`, and `callData` on-chain.
3. Call the matching `/tx` endpoint with `txHash`.
4. Indexer backfills `orderId` or `operationId`.
5. Poll status endpoints until settled.

## Record tx 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 queries

| Operation | Endpoints                                                        |
| --------- | ---------------------------------------------------------------- |
| 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}`                     |

> Same `txHash` from the same API key is idempotent. A `txHash` already recorded by another API key returns an error.

## Deposit prerequisite

Complete ERC-20 `approve` before deposit calldata execution. See [cash/deposits.md](/trading-api/cash-operations/deposits.md) and [demo-code.md](/trading-api/guides/demo-code.md).


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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, and the optional `goal` query parameter:

```
GET https://docs.anchored.finance/trading-api/guides/self-submit-on-chain.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
