@@ -16,7 +16,7 @@ In this guide, you will learn how to:
16
16
1 . [ Construct post-conditions] ( #constructing-post-conditions ) .
17
17
2 . [ Use post-conditions] ( #using-post-conditions ) .
18
18
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 ) .
20
20
21
21
---
22
22
@@ -86,123 +86,65 @@ const tx = await makeContractCall({
86
86
87
87
Essentially, the ` postConditionMode ` is what tells the Stacks node whether to require (` Deny ` ) or ignore (` Allow ` ) the post-conditions when evaluating the transaction.
88
88
89
- ## Legacy methods/enums
89
+ ## Usage examples
90
90
91
- Legacy methods and enums can be used interchangeably with the builder methods.
91
+ ### Amount uSTX sent
92
92
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.
96
94
97
95
``` ts
98
- import { createSTXPostCondition , FungibleConditionCode } from ' @stacks/transactions' ;
96
+ import { Pc } from ' @stacks/transactions' ;
99
97
100
- const postCondition = createSTXPostCondition (
101
- " STB44HYPYAT2BB2QE513NSP81HTMYWBJP02HPGK6" ,
102
- FungibleConditionCode .Equal ,
103
- 1000
104
- );
98
+ const postCondition = Pc .principal (' STB44HYPYAT2BB2QE513NSP81HTMYWBJP02HPGK6' )
99
+ .willSendEq (1000 )
100
+ .ustx ();
105
101
```
106
102
107
- Some other examples can be found below:
103
+ ### Amount FT sent
108
104
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.
114
106
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' ;
118
109
119
- ---
110
+ const postCondition = Pc .principal (' STB44HYPYAT2BB2QE513NSP81HTMYWBJP02HPGK6.token-ft' )
111
+ .willSendGte (500 )
112
+ .ft (' STB44HYPYAT2BB2QE513NSP81HTMYWBJP02HPGK6.token-ft' , ' token' );
113
+ ```
120
114
121
- ## Amount uSTX sent
115
+ ### Amount NFT sent / not sent
122
116
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 .
124
118
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' ;
149
121
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
+ ```
151
126
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
156
128
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).
177
130
178
- Construct a post-condition for sending / not-sending a specific NFT.
131
+ ``` ts
132
+ import { Cl , Pc } from ' @stacks/transactions' ;
179
133
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
+ );
184
140
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 " );
188
144
```
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 ` .
206
148
</Callout >
207
149
208
150
---
@@ -218,6 +160,6 @@ Post-conditions can only ensure the transfer of assets and cannot guarantee the
218
160
<Card
219
161
href = " /stacks/stacks.js/packages/transactions"
220
162
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 ."
222
164
/>
223
165
</Cards >
0 commit comments