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-senderandcontract-callervalues 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-ftandwith-nftgrant asset outflows.with-stakingcaps how much STX can be locked through the active PoX contract, andwith-poxpermits position-altering PoX calls (unstake,unstake-sbtc,update-bond-registration,announce-l1-early-exit). Contracts written in Clarity 4 or 5 usewith-stackinginstead ofwith-staking.
Last updated
Was this helpful?