> For the complete documentation index, see [llms.txt](https://docs.kyberswap.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.kyberswap.com/developer-guide/limit-order-api/how-to-guides/cancel-an-order-hard-cancel.md).

# Cancel an Order — Hard Cancel

Immediately cancel a limit order on-chain by submitting a transaction to the   Limit Order contract. Requires a gas fee.

## Cancel an Order — Hard Cancel

Hard Cancel writes the cancellation directly to the blockchain, making it effective immediately regardless of any in-flight Operator signatures. Use this when you need certainty that an order is cancelled right now.

You can cancel multiple orders in a single transaction to pay gas only once. Alternatively, increment the contract nonce to cancel **all** of your open orders at once.

{% hint style="info" %}
For cancellation without gas, use Gasless Cancel. Expect up to a 5-minute wait.
{% endhint %}

{% hint style="success" %}
**Full demo:** [github.com/KyberNetwork/ks-limit-order-API-demo](https://github.com/KyberNetwork/ks-limit-order-API-demo)
{% endhint %}

### Flow

```
GET /orders  →  POST /encode/cancel-batch-orders  →  send transaction
```

To cancel all orders instead: `POST /encode/increase-nonce → send transaction`

### Step 1 — Get Active Orders

```typescript
const { data } = await axios.get(
    "https://limit-order.kyberswap.com/read-ks/api/v1/orders",
    { params: { chainId: 137, maker: signerAddress, status: "active" } }
);

const targetOrderId = data.data[0].id;
```

### Step 2 — Encode the Cancel Calldata

Pass one or more `orderIds` to cancel in a single transaction:

```typescript
const requestBody = {
    orderIds: [targetOrderId]   // add multiple IDs to batch cancel
};

const { data: encoded } = await axios.post(
    "https://limit-order.kyberswap.com/read-ks/api/v1/encode/cancel-batch-orders",
    requestBody
);
```

#### Alternative: Cancel All Orders

To invalidate all open orders by incrementing the Maker's nonce:

```typescript
const { data: encoded } = await axios.post(
    "https://limit-order.kyberswap.com/read-ks/api/v1/encode/increase-nonce",
    { chainId: 137 }
);
```

### Step 3 — Execute On-chain

```typescript
const tx = await signer.sendTransaction({
    to:    limitOrderContract,
    from:  signerAddress,
    data:  encoded.data.encodedData,
    maxFeePerGas: 100000000000,
    maxPriorityFeePerGas: 100000000000
});

const receipt = await tx.wait();
console.log("Hard cancel tx hash:", receipt.hash);
```

See Contracts & Addresses for the `limitOrderContract` address per chain.

### Related

* [Cancel an Order — Gasless](/developer-guide/limit-order-api/how-to-guides/cancel-an-order-gasless.md)
* [POST /read-ks/api/v1/encode/cancel-batch-orders](/developer-guide/limit-order-api/api-reference/maker-api.md#post-read-ks-api-v1-encode-cancel-batch-orders)
* [POST /read-ks/api/v1/encode/increase-nonce](/developer-guide/limit-order-api/api-reference/maker-api.md#encode-increase-nonce)


---

# 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 by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.kyberswap.com/developer-guide/limit-order-api/how-to-guides/cancel-an-order-hard-cancel.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
