> For the complete documentation index, see [llms.txt](https://docs.kpk.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.kpk.io/funds/integration/cancel-a-request.md).

# Cancel a request

A subscription or redemption request can be **cancelled** by its investor or receiver, provided it is still **pending** (not yet approved or denied) **and** its cancellation TTL has elapsed. This lets users recover tokens from stale requests.

```solidity
function cancelSubscription(uint256 id) external; // returns escrowed assets to the investor
function cancelRedemption(uint256 id) external;   // returns escrowed shares to the investor
```

The TTL after which a request becomes cancellable is the `cancelableFrom` timestamp in the request's creation event (`timestamp + subscriptionRequestTtl` / `+ redemptionRequestTtl`). Calling before then reverts with `RequestNotPastTtl`; calling on a non-pending request reverts with `RequestNotPending`.

{% tabs %}
{% tab title="viem" %}

```typescript
import { createWalletClient, http, parseAbi } from "viem";
import { privateKeyToAccount } from "viem/accounts";
import { mainnet } from "viem/chains";

const SHARES = "0x...";
const abi = parseAbi([
  "function cancelSubscription(uint256 id)",
  "function cancelRedemption(uint256 id)",
]);

const account = privateKeyToAccount("0x...");
const wallet = createWalletClient({ account, chain: mainnet, transport: http() });

await wallet.writeContract({ address: SHARES, abi, functionName: "cancelSubscription", args: [42n] });
```

{% endtab %}

{% tab title="ethers.js" %}

```typescript
import { ethers } from "ethers";

const SHARES = "0x...";
const abi = ["function cancelSubscription(uint256 id)", "function cancelRedemption(uint256 id)"];

const provider = new ethers.JsonRpcProvider("https://eth.llamarpc.com");
const signer = new ethers.Wallet("0x...", provider);
const shares = new ethers.Contract(SHARES, abi, signer);

await (await shares.cancelSubscription(42n)).wait();
```

{% endtab %}

{% tab title="Python" %}

```python
from web3 import Web3

SHARES = "0x..."
abi = [
    {"name": "cancelSubscription", "type": "function", "stateMutability": "nonpayable",
     "inputs": [{"name": "id", "type": "uint256"}], "outputs": []},
    {"name": "cancelRedemption", "type": "function", "stateMutability": "nonpayable",
     "inputs": [{"name": "id", "type": "uint256"}], "outputs": []},
]

w3 = Web3(Web3.HTTPProvider("https://eth.llamarpc.com"))
acct = w3.eth.account.from_key("0x...")
shares = w3.eth.contract(address=SHARES, abi=abi)

tx = shares.functions.cancelSubscription(42).build_transaction({"from": acct.address})
# ... sign & send tx ...
```

{% endtab %}
{% endtabs %}

{% hint style="info" %}

## Events

Cancelling emits a `SubscriptionCancellation` or `RedemptionCancellation` event with the request id and the canceller's address.
{% endhint %}

<figure><picture><source srcset="/files/KAA7kVGGFD9VNtHiNTEX" media="(prefers-color-scheme: dark)"><img src="/files/nKUilhXyoyaBQvBrnDdh" alt=""></picture><figcaption></figcaption></figure>


---

# 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.kpk.io/funds/integration/cancel-a-request.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.
