> For the complete documentation index, see [llms.txt](https://docs.stacks.co/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.stacks.co/cookbook/clarity/cryptography-and-security/contract-post-conditions.md).

# Contract post-conditions

Source: [SP2PABAF9FTAJYNFZH93XENAJ8FVY99RRM50D2JG9.xbtc-sbtc-swap-v2](https://explorer.hiro.so/txid/SP2PABAF9FTAJYNFZH93XENAJ8FVY99RRM50D2JG9.xbtc-sbtc-swap-v2)

<pre class="language-clarity" data-title=".xbtc-sbtc-swap-v2" data-expandable="true"><code class="lang-clarity">;; --snip--

(define-private (transfer-sbtc-to
    (amount uint)
    (sbtc-recipient principal)
  )
<strong>  (as-contract?
</strong>    ((with-ft 'SM3VDXK3WZZSA84XXFKAFAF15NNZX32CTSG82JFQ4.sbtc-token "sbtc-token"
      amount
    ))
    (try! (contract-call? 'SM3VDXK3WZZSA84XXFKAFAF15NNZX32CTSG82JFQ4.sbtc-token
      transfer amount current-contract sbtc-recipient none
    ))
  )
)

;; --snip--
</code></pre>

### Description

The `as-contract?` function resolves the expression caller to the principal of the current contract. Most importantly it allows a contract to protect its own assets during the execution of the expression with a set of specified allowances.

### Use Cases

* A contract invoking a body expression that potentially may have unwanted and unexpected asset transfers.
* Protecting a contract invoking another external contract's function.

### Key Concepts

* **Contract caller context -** Switches the current context's `tx-sender` and `contract-caller` values to the contract's principal and executes the body expressions within that context, then checks the asset outflows from the contract against the granted allowances, in declaration order.
* **Clarity post-conditions** - Accepts a set of allowances that limit what the body can do with the contract's assets. `with-stx`, `with-ft` and `with-nft` grant asset outflows. `with-staking` caps how much STX can be locked through the active PoX contract, and `with-pox` permits position-altering PoX calls (`unstake`, `unstake-sbtc`, `update-bond-registration`, `announce-l1-early-exit`). Contracts written in Clarity 4 or 5 use `with-stacking` instead of `with-staking`.


---

# 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.stacks.co/cookbook/clarity/cryptography-and-security/contract-post-conditions.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.
