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

# Cancelling an Order

> Handling an unfulfilled order – cancellations on the destination chain, response payload, and important considerations.

It can be the case that the given order remains unfulfilled for a prolonged period of time. The reason for this may be that the order became
unprofitable, and no one is willing to fulfill it. In this case, the order must be cancelled to unlock the input amount of funds.

[Limit orders](/dln-details/integration-guidelines/order-creation/creating-order/quoting-strategies#limit-order-not-recommended) have a high potential
of remaining unfulfilled for prolonged periods of time, until the market conditions are met. One example of such an order is a [0.01 SOL for 20.000
POL limit order](https://app.debridge.finance/order?orderId=0x5aa527db4bb244bb30b05d443db3370e42d29c4a1364601deb54e632f7c70c51) which was created for
demonstration purposes of this article.

The only way to cancel the order is to initiate the cancellation procedure on the chain it was intended to be fulfilled on (the `dstChainId` parameter
from `create-tx` call payload). During the cancellation process, the order enters a `OrderCancelled`
[state](/dln-details/integration-guidelines/order-creation/order-tracking-api/order-states#order-states), which prevents fulfillment. A cross-chain
message is sent through the deBridge cross-chain messaging infrastructure to the DLN contract on the source chain to unlock the given funds. **The
funds locked on the source chain are returned in full including affiliate and protocol fees**.

The cancellation procedure can only be initiated by the `dstChainOrderAuthorityAddress` in a separate transaction on the destination chain. Such
transaction can be requested by calling the `/v1.0/dln/order/:id/cancel-tx` endpoint:

```
https://dln.debridge.finance/v1.0/dln/order/0x5aa527db4bb244bb30b05d443db3370e42d29c4a1364601deb54e632f7c70c51/cancel-tx
```

This gives the response from which the transaction data can be extracted to be signed and broadcasted to the destination chain, described by the
following TypeScript type:

```typescript theme={null}
export type CancelTxResponsePayload = {
  cancelBeneficiary: string; // Source chain input funds recipient after cancellation
  chainId: number; // Chain to submit on 
  data: string; // TX data
  from: string; // Allowed tx sender address
  to: string; // TX `to`
  value: string; // TX `value`
}
```

Detailed runnable script on how to cancel an order is available in [the accompanying examples
repository](https://github.com/debridge-finance/api-integrator-example/blob/master/src/scripts/orders/cancellation/cancel-order.ts).

Several considerations:

* the transaction can be submitted only to the chain where the order has been intended to be fulfilled on, designated with `chainId` field in the response
* the transaction call would be accepted only if made by the `dstChainOrderAuthorityAddress` specified during the given order creation, designated
  with `from` field in the response
* the funds locked on the source chain upon order creation are returned to the `srcChainOrderAuthorityAddress` specified during the given order
  creation, designated with the `cancelBeneficiary` response field
* the `value` for the transaction is always positive, needed to cover:
  * the deBridge cross-chain messaging protocol fee (measured in the blockchain native currency where the message is being sent from) to make a
    cancellation message accepted. Consider looking at [the list of supported chains and fees](/dmp-details/dmp/fees-supported-chains) and [details on
    retrieving the deBridge protocol fee](dln-details/integration-guidelines/smart-contracts/placing-orders);
  * a small amount to cover the gas on the source chain, which gives an incentive to keepers for the successful claim of the cross-chain message on
    the source chain. In other words, this is a prepayment for potential gas expenses, that will be transferred by the protocol.

## Further reading

* [Automatic Cancellations](/dln-details/affiliates/auto-cancellations)
