For the complete documentation index, see llms.txt. This page is also available as Markdown.

Contract post-conditions

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.

Last updated

Was this helpful?