> 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.

> **Use a reliable RPC node.** `estimateGas`, `eth_call`, and `waitForTransactionReceipt` hit your RPC provider, not the Anchored API. Free/public endpoints (including viem's default `http()` transport and free-tier providers) may rate-limit or reject `eth_call` and gas estimation, failing *before* the API is involved. Pass your own node URL to `http("<url>")`.
>
> **Add a gas buffer.** Default `estimateGas` can under-estimate router calls on some chains (e.g. Monad) and the tx reverts out-of-gas. Multiply the estimate (e.g. `× 1.5–2`) before submitting.

## 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).
