Skip to content

Commit fc81b5e

Browse files
authored
Merge pull request #943 from hirosystems/develop
v2.5.3
2 parents 14b2ead + 02f90ad commit fc81b5e

11 files changed

+232
-4
lines changed

app/cookbook/components/snippet-result.tsx

+1-4
Original file line numberDiff line numberDiff line change
@@ -232,10 +232,7 @@ export function SnippetResult({
232232
</Button> */}
233233
{type === "clarity" && (
234234
<Button variant="link" className="gap-2 self-end" size="sm" asChild>
235-
<Link
236-
href={`https://play.hiro.so/?epoch=3.0&snippet=KGRlZmluZS1yZWFkLW9ubHkgKGdldC10ZW51cmUtaGVpZ2h0IChibG9jayB1aW50KSkKICAob2sKICAgIChhdC1ibG9jawogICAgICAodW53cmFwIQogICAgICAgIChnZXQtc3RhY2tzLWJsb2NrLWluZm8_IGlkLWhlYWRlci1oYXNoIGJsb2NrKQogICAgICAgIChlcnIgdTQwNCkogICAgICApCiAgICAgIHRlbnVyZS1oZWlnaHQKICAgICkKICApCik=`}
237-
target="_blank"
238-
>
235+
<Link href={recipe?.external_url || ""} target="_blank">
239236
Open in Clarity Playground <ArrowUpRight className="w-4 h-4" />
240237
</Link>
241238
</Button>

content/_recipes/build-a-stx-pc.mdx

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# Build a STX post-condition
2+
3+
A helper function that creates a post-condition for STX token transfers using the `Pc` builder class, ensuring exact amounts are transferred as expected.
4+
5+
## Use cases
6+
7+
- Securing STX token transfers with transfer amount validation
8+
9+
## Example usage
10+
11+
```typescript -cn
12+
import {
13+
AnchorMode,
14+
broadcastTransaction,
15+
makeSTXTokenTransfer,
16+
Pc,
17+
PostConditionMode,
18+
} from "@stacks/transactions";
19+
20+
// !hover post-conditions
21+
const pc = Pc.principal("ST1PQHQKV0RJXZFY1DGX8MNSNYVE3VGZJSRTPGZGM")
22+
// !hover post-conditions
23+
.willSendEq(10000000)
24+
// !hover post-conditions
25+
.ustx();
26+
27+
const txOptions = {
28+
recipient: "ST1SJ3DTE5DN7X54YDH5D64R3BCB6A2AG2ZQ8YPD5",
29+
amount: 10000000,
30+
senderKey: "753b7cc01a1a2e86221266a154af739463fce51219d97e4f856cd7200c3bd2a601",
31+
network: STACKS_TESTNET,
32+
// !hover post-conditions
33+
postConditions: [pc],
34+
postConditionMode: PostConditionMode.Deny,
35+
anchorMode: AnchorMode.Any,
36+
};
37+
38+
const transaction = await makeSTXTokenTransfer(txOptions);
39+
const broadcastResponse = await broadcastTransaction({
40+
transaction,
41+
});
42+
```
43+
44+
This example passes in our <HoverLink href="hover:post-condition" className="text-[var(--ch-11)]">post-conditions</HoverLink> as part of the transaction options, ensuring that exactly 10 STX will be transferred from the `ST1PQHQKV0RJXZFY1DGX8MNSNYVE3VGZJSRTPGZGM` principal.
45+
46+
## Resources
47+
48+
- [Stacks.js / Transactions](/stacks/stacks.js/packages/transactions)
49+
- [Post-conditions](/stacks/stacks.js/guides/post-conditions)

content/_recipes/build-an-ft-pc.mdx

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Build a fungible token post-condition
2+
3+
A helper function that creates a post-condition for SIP-010 fungible token transfers using the `Pc` builder class, ensuring exact amounts of specific tokens are transferred as expected.
4+
5+
## Use cases
6+
7+
- Securing token swaps with transfer amount validation
8+
9+
## Resources
10+
11+
- [Stacks.js / Transactions](/stacks/stacks.js/packages/transactions)
12+
- [Post-conditions](/stacks/stacks.js/guides/post-conditions)

content/_recipes/build-an-nft-pc.mdx

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Build an NFT post-condition
2+
3+
A helper function that creates a post-condition for NFT transfers using the `Pc` builder class, ensuring specific NFTs are handled as expected.
4+
5+
## Use cases
6+
7+
- Securing NFT transfers with ownership validation
8+
9+
## Resources
10+
11+
- [Stacks.js / Transactions](/stacks/stacks.js/packages/transactions)
12+
- [Post-conditions](/stacks/stacks.js/guides/post-conditions)
+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# Create a sponsored transaction
2+
3+
A script to create sponsored transactions where one party (the sponsor) pays the transaction fees for another party's transaction.
4+
5+
## Use cases
6+
7+
- Building onboarding flows where a service pays user fees
8+
- Creating DAO operations where treasury pays member fees
9+
10+
## Example usage
11+
12+
```typescript -cn
13+
import {
14+
broadcastTransaction,
15+
deserializeTransaction,
16+
sponsorTransaction,
17+
} from "@stacks/transactions";
18+
// !hover serialized-tx
19+
import { serializedTx } from "./create-a-sponsored-tx";
20+
21+
const deserializedTx = deserializeTransaction(serializedTx);
22+
const sponsorOptions = {
23+
// !hover tx-options
24+
transaction: deserializedTx,
25+
// !hover tx-options
26+
sponsorPrivateKey: "<sponsor-private-key>",
27+
// !hover tx-options
28+
fee: 1000n;
29+
// !hover tx-options
30+
sponsorNonce: 0,
31+
// !hover tx-options
32+
network: STACKS_TESTNET,
33+
};
34+
// !hover sponsor-tx
35+
const sponsoredTx = await sponsorTransaction(sponsorOptions);
36+
37+
const broadcastResponse = await broadcastTransaction({
38+
transaction: sponsoredTx,
39+
});
40+
const txId = broadcastResponse.txid;
41+
```
42+
43+
This example takes the <HoverLink href="hover:serialized-tx">pre-built transaction</HoverLink> and adds the sponsorship details to it. The <HoverLink href="hover:tx-options">sponsorship options</HoverLink> include the transaction itself, the sponsor's credentials, their next valid nonce, and network details.
44+
45+
Once configured, the <HoverLink href="hover:sponsor-tx" className="text-[var(--ch-9)]">sponsorTransaction</HoverLink> function creates the sponsored version, which can then be broadcast to the network.
46+
47+
## Resources
48+
49+
- [Stacks.js / Transactions](/stacks/stacks.js/packages/transactions)
50+
- [Transaction Broadcasting](/stacks/stacks.js/guides/broadcast-transactions)
+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Deploy a contract
2+
3+
A script that deploys a Clarity smart contract to the Stacks blockchain using Stacks.js.
4+
5+
## Example usage
6+
7+
```typescript
8+
import { STACKS_TESTNET } from "@stacks/network";
9+
import { makeContractDeploy, broadcastTransaction } from "@stacks/transactions";
10+
import { readFileSync } from 'fs';
11+
12+
const txOptions = {
13+
contractName: "super-cool-contract",
14+
codeBody: readFileSync("./contract.clar", "utf8"),
15+
senderKey: "<your-private-key>",
16+
network: STACKS_TESTNET,
17+
};
18+
19+
const transaction = await makeContractDeploy(txOptions);
20+
const broadcastResponse = await broadcastTransaction({transaction});
21+
const txId = broadcastResponse.txid;
22+
```
23+
24+
This example reads the contract code from a file and uses it to deploy a contract to the Stacks blockchain.
25+
26+
## Resources
27+
28+
- [Stacks.js / Transactions](/stacks/stacks.js/packages/transactions)
+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Generate a secret key
2+
3+
A script that generates BIP39 mnemonic phrases for use as wallet secret keys.
4+
5+
## Use cases
6+
7+
- Creating new wallets
8+
- Generating backup phrases
9+
- Testing wallet functionality
10+
11+
## Resources
12+
13+
- [Stacks.js](/stacks/stacks.js)
+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# Generate a wallet from a seed phrase or private key
2+
3+
A script that creates a Stacks wallet from a seed phrase or private key, with support for multiple accounts.
4+
5+
## Use cases
6+
7+
- Creating new wallets from existing seed phrases
8+
- Restoring wallets from backups
9+
- Managing multiple accounts within a single wallet
10+
11+
## Example usage
12+
13+
```typescript
14+
import { generateWallet, generateNewAccount } from '@stacks/wallet-sdk';
15+
16+
const mnemonic = "twice kind fence tip hidden tilt action fragile skin nothing glory cousin green tomorrow spring wrist shed math olympic multiply hip blue scout claw"
17+
const privateKey = "753b7cc01a1a2e86221266a154af739463fce51219d97e4f856cd7200c3bd2a601"
18+
19+
let wallet = generateWallet({
20+
// !diff -
21+
secretKey: mnemonic,
22+
// !diff +
23+
secretKey: privateKey,
24+
password: "secret",
25+
});
26+
27+
// !hover generate-new-account
28+
wallet = generateNewAccount(wallet);
29+
30+
const { account1, account2 } = wallet;
31+
```
32+
33+
This example demonstrates:
34+
35+
1. You can use either a seed phrase or private key to create a wallet.
36+
2. The <HoverLink href="hover:generate-new-account" className="text-[var(--ch-9)]">generateNewAccount</HoverLink> function adds a new account to the wallet.
37+
38+
## Resources
39+
40+
- [Stacks.js](/stacks/stacks.js)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Get account details from a wallet
2+
3+
A script that extracts important account details like the STX address and private key from a wallet.
4+
5+
## Use cases
6+
7+
- Retrieving wallet addresses for constructing transactions
8+
- Getting private keys for signing operations
9+
- Managing multiple wallet accounts
10+
11+
## Resources
12+
13+
- [Stacks.js](/stacks/stacks.js)

content/_recipes/transfer-stx.mdx

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Transfer STX tokens
2+
3+
A script that creates and broadcasts an STX token transfer with <HoverLink href="hover:post-conditions">post-conditions</HoverLink> for secure transfers.
4+
5+
## Use cases
6+
7+
- Sending STX tokens between addresses
8+
- Building payment functionality
9+
10+
## Resources
11+
12+
- [Stacks.js / Transactions](/stacks/stacks.js/packages/transactions)
13+
- [Post-conditions](/stacks/stacks.js/guides/post-conditions)

types/recipes.ts

+1
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ export interface RecipeMetadata {
5151
categories: RecipeCategory[];
5252
tags: SubTagsForCategory[RecipeCategory][];
5353
dependencies?: Record<string, string>;
54+
external_url?: string;
5455
}
5556

5657
// Code blocks extracted from markdown content

0 commit comments

Comments
 (0)