Skip to content

Commit 12f4389

Browse files
authored
Merge pull request #948 from hirosystems/sft-pc-example
Added an SFT PC example to PC guide
2 parents 3584376 + d978843 commit 12f4389

File tree

1 file changed

+41
-99
lines changed

1 file changed

+41
-99
lines changed

content/docs/stacks/stacks.js/guides/post-conditions.mdx

+41-99
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ In this guide, you will learn how to:
1616
1. [Construct post-conditions](#constructing-post-conditions).
1717
2. [Use post-conditions](#using-post-conditions).
1818
3. [Set the post-condition mode](#setting-the-post-condition-mode).
19-
4. [Use the legacy methods/enums](#using-the-legacy-methods-enums).
19+
4. [Usage examples](#usage-examples).
2020

2121
---
2222

@@ -86,123 +86,65 @@ const tx = await makeContractCall({
8686

8787
Essentially, the `postConditionMode` is what tells the Stacks node whether to require (`Deny`) or ignore (`Allow`) the post-conditions when evaluating the transaction.
8888

89-
## Legacy methods/enums
89+
## Usage examples
9090

91-
Legacy methods and enums can be used interchangeably with the builder methods.
91+
### Amount uSTX sent
9292

93-
<Callout title="Note">
94-
If you prefer the legacy methods over the `Pc` builder approach, you can import them from the `@stacks/transactions` package.
95-
</Callout>
93+
Construct a post-condition for a certain amount of uSTX to be sent.
9694

9795
```ts
98-
import { createSTXPostCondition, FungibleConditionCode } from '@stacks/transactions';
96+
import { Pc } from '@stacks/transactions';
9997

100-
const postCondition = createSTXPostCondition(
101-
"STB44HYPYAT2BB2QE513NSP81HTMYWBJP02HPGK6",
102-
FungibleConditionCode.Equal,
103-
1000
104-
);
98+
const postCondition = Pc.principal('STB44HYPYAT2BB2QE513NSP81HTMYWBJP02HPGK6')
99+
.willSendEq(1000)
100+
.ustx();
105101
```
106102

107-
Some other examples can be found below:
103+
### Amount FT sent
108104

109-
- [`createSTXPostCondition`](https://stacks.js.org/functions/_stacks_transactions.createSTXPostCondition)
110-
- [`createFungiblePostCondition`](https://stacks.js.org/functions/_stacks_transactions.createFungiblePostCondition)
111-
- [`createNonFungiblePostCondition`](https://stacks.js.org/functions/_stacks_transactions.createNonFungiblePostCondition)
112-
- [`FungibleConditionCode`](https://stacks.js.org/enums/_stacks_transactions.FungibleConditionCode)
113-
- [`NonFungibleConditionCode`](https://stacks.js.org/enums/_stacks_transactions.NonFungibleConditionCode)
105+
Construct a post-condition for a certain amount of a specific FT to be sent.
114106

115-
<Callout title="Note">
116-
Use the `Pc` helpers to construct post-conditions in a clear and concise manner.
117-
</Callout>
107+
```ts
108+
import { Pc } from '@stacks/transactions';
118109

119-
---
110+
const postCondition = Pc.principal('STB44HYPYAT2BB2QE513NSP81HTMYWBJP02HPGK6.token-ft')
111+
.willSendGte(500)
112+
.ft('STB44HYPYAT2BB2QE513NSP81HTMYWBJP02HPGK6.token-ft', 'token');
113+
```
120114

121-
## Amount uSTX sent
115+
### Amount NFT sent / not sent
122116

123-
Construct a post-condition for a certain amount of uSTX to be sent.
117+
Construct a post-condition for sending / not-sending a specific NFT.
124118

125-
<Tabs id="eq-ustx" items={["Pc","Legacy"]}>
126-
<Tab value={"Pc"}>
127-
```ts
128-
import { Pc } from '@stacks/transactions';
129-
130-
const postCondition = Pc.principal('STB44HYPYAT2BB2QE513NSP81HTMYWBJP02HPGK6')
131-
.willSendEq(1000)
132-
.ustx();
133-
```
134-
</Tab>
135-
<Tab value={"Legacy"}>
136-
```ts
137-
import { createSTXPostCondition, FungibleConditionCode } from '@stacks/transactions';
138-
139-
const postCondition = createSTXPostCondition(
140-
"STB44HYPYAT2BB2QE513NSP81HTMYWBJP02HPGK6",
141-
FungibleConditionCode.Equal,
142-
1000
143-
);
144-
```
145-
</Tab>
146-
</Tabs>
147-
148-
## Amount FT sent
119+
```ts
120+
import { Pc } from '@stacks/transactions';
149121

150-
Construct a post-condition for a certain amount of a specific FT to be sent.
122+
const postCondition = Pc.principal('STB44HYPYAT2BB2QE513NSP81HTMYWBJP02HPGK6')
123+
.willNotSendAsset()
124+
.nft('STB44HYPYAT2BB2QE513NSP81HTMYWBJP02HPGK6.token-nft::token', Cl.uint(12));
125+
```
151126

152-
<Tabs id="gte-ft" items={["Pc","Legacy"]}>
153-
<Tab value={"Pc"}>
154-
```ts
155-
import { Pc } from '@stacks/transactions';
127+
### Amount SFT sent / not sent
156128

157-
const postCondition = Pc.principal('STB44HYPYAT2BB2QE513NSP81HTMYWBJP02HPGK6.token-ft')
158-
.willSendGte(500)
159-
.ft('STB44HYPYAT2BB2QE513NSP81HTMYWBJP02HPGK6.token-ft', 'token');
160-
```
161-
</Tab>
162-
<Tab value={"Legacy"}>
163-
```ts
164-
import { createSTXPostCondition, FungibleConditionCode } from '@stacks/transactions';
165-
166-
const postCondition = createSTXPostCondition(
167-
"STB44HYPYAT2BB2QE513NSP81HTMYWBJP02HPGK6.token-ft",
168-
FungibleConditionCode.GreaterEqual,
169-
500,
170-
"STB44HYPYAT2BB2QE513NSP81HTMYWBJP02HPGK6.token-ft::token"
171-
);
172-
```
173-
</Tab>
174-
</Tabs>
175-
176-
## Amount NFT sent / not sent
129+
Construct a post-condition for sending / not-sending a specific SFT (Semi-fungible token).
177130

178-
Construct a post-condition for sending / not-sending a specific NFT.
131+
```ts
132+
import { Cl, Pc } from '@stacks/transactions';
179133

180-
<Tabs id="post-condition-examples" items={["Pc","Legacy"]}>
181-
<Tab value={"Pc"}>
182-
```ts
183-
import { Pc } from '@stacks/transactions';
134+
const postConditionForNFT = Pc.principal('STB44HYPYAT2BB2QE513NSP81HTMYWBJP02HPGK6')
135+
.willSendAsset()
136+
.nft(
137+
"ST1PQHQKV0RJXZFY1DGX8MNSNYVE3VGZJSRTPGZGM.semi-fungible-token::semi-fungible-token-id",
138+
Cl.tuple({ "token-id": Cl.uint(1), owner: Cl.principal('STB44HYPYAT2BB2QE513NSP81HTMYWBJP02HPGK6') })
139+
);
184140

185-
const postCondition = Pc.principal('STB44HYPYAT2BB2QE513NSP81HTMYWBJP02HPGK6')
186-
.willNotSendAsset()
187-
.nft('STB44HYPYAT2BB2QE513NSP81HTMYWBJP02HPGK6.token-nft::token', Cl.uint(12));
141+
const postConditionForFT = Pc.principal('STB44HYPYAT2BB2QE513NSP81HTMYWBJP02HPGK6')
142+
.willSendEq(500)
143+
.ft("ST1PQHQKV0RJXZFY1DGX8MNSNYVE3VGZJSRTPGZGM.semi-fungible-token", "semi-fungible-token");
188144
```
189-
</Tab>
190-
<Tab value={"Legacy"}>
191-
```ts
192-
import { createNonFungiblePostCondition, NonFungibleConditionCode } from '@stacks/transactions';
193-
194-
const postCondition = createNonFungiblePostCondition(
195-
"STB44HYPYAT2BB2QE513NSP81HTMYWBJP02HPGK6",
196-
NonFungibleConditionCode.DoesNotSend,
197-
"STB44HYPYAT2BB2QE513NSP81HTMYWBJP02HPGK6.token-nft::token",
198-
Cl.uint(12)
199-
);
200-
```
201-
</Tab>
202-
</Tabs>
203-
204-
<Callout title="Note" type="warn">
205-
Post-conditions can only ensure the transfer of assets and cannot guarantee the end-state after a transaction. To learn more, read the [post-conditions](/stacks/stacks.js/concepts/post-conditions) guide.
145+
146+
<Callout title="Note">
147+
The previous builders (`makeStandardSTXPostCondition`, `makeStandardFungiblePostCondition`, etc) were removed in `v7.0.0`.
206148
</Callout>
207149

208150
---
@@ -218,6 +160,6 @@ Post-conditions can only ensure the transfer of assets and cannot guarantee the
218160
<Card
219161
href="/stacks/stacks.js/packages/transactions"
220162
title="API References"
221-
description="Dive into the API references for Stacks.js."
163+
description="Dive deeper into the API references for the Stacks.js transactions package."
222164
/>
223165
</Cards>

0 commit comments

Comments
 (0)