Are you an LLM? Read llms.txt for a summary of the docs, or llms-full.txt for the full context.
Skip to content

Post-Conditions

Fluent builder for Stacks post-conditions. Protects users by asserting expected asset transfers.

STX

import { Pc } from "@secondlayer/stacks/postconditions";
 
// Sender will send exactly 1 STX
Pc.principal("SP2J6...").willSendEq(1_000_000).ustx();
 
// Sender will send at most 5 STX
Pc.principal("SP2J6...").willSendLte(5_000_000).ustx();

Fungible Tokens

// Sender will send exactly 100 tokens
Pc.principal("SP2J6...")
  .willSendEq(100)
  .ft("SP2J6....my-token", "my-token");

NFTs

import { Cl } from "@secondlayer/stacks/clarity";
 
// Sender will send NFT
Pc.principal("SP2J6...")
  .willSendAsset()
  .nft("SP2J6....my-nft::my-nft", Cl.uint(1));
 
// Sender will NOT send NFT
Pc.principal("SP2J6...")
  .willNotSendAsset()
  .nft("SP2J6....my-nft::my-nft", Cl.uint(1));
 
// Epoch 3.4: NFT may or may not be sent
Pc.principal("SP2J6...")
  .willMaybeSendAsset()
  .nft("SP2J6....my-nft::my-nft", Cl.uint(1));

Staking / PoX (SIP-045)

pox-5 locks STX natively — use a staking post-condition, not .ustx().

Pc.principal(staker).willSendEq(amountUstx).ustxToLock();
Pc.principal(staker).willPerformPox();
Pc.origin().willNotPerformPox();

unstake / claimRewards send an amount the contract computes at execution. Use postConditionMode: "allow" rather than guessing a bound.

Hex PCs (Leather, stacks.js) round-trip: Pc.fromHex(hex) / postConditionToHex(pc).

Comparators

MethodClarity Equivalent
willSendEq(n)=
willSendGt(n)>
willSendGte(n)>=
willSendLt(n)<
willSendLte(n)<=