-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #943 from hirosystems/develop
v2.5.3
- Loading branch information
Showing
11 changed files
with
232 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
# Build a STX post-condition | ||
|
||
A helper function that creates a post-condition for STX token transfers using the `Pc` builder class, ensuring exact amounts are transferred as expected. | ||
|
||
## Use cases | ||
|
||
- Securing STX token transfers with transfer amount validation | ||
|
||
## Example usage | ||
|
||
```typescript -cn | ||
import { | ||
AnchorMode, | ||
broadcastTransaction, | ||
makeSTXTokenTransfer, | ||
Pc, | ||
PostConditionMode, | ||
} from "@stacks/transactions"; | ||
|
||
// !hover post-conditions | ||
const pc = Pc.principal("ST1PQHQKV0RJXZFY1DGX8MNSNYVE3VGZJSRTPGZGM") | ||
// !hover post-conditions | ||
.willSendEq(10000000) | ||
// !hover post-conditions | ||
.ustx(); | ||
|
||
const txOptions = { | ||
recipient: "ST1SJ3DTE5DN7X54YDH5D64R3BCB6A2AG2ZQ8YPD5", | ||
amount: 10000000, | ||
senderKey: "753b7cc01a1a2e86221266a154af739463fce51219d97e4f856cd7200c3bd2a601", | ||
network: STACKS_TESTNET, | ||
// !hover post-conditions | ||
postConditions: [pc], | ||
postConditionMode: PostConditionMode.Deny, | ||
anchorMode: AnchorMode.Any, | ||
}; | ||
|
||
const transaction = await makeSTXTokenTransfer(txOptions); | ||
const broadcastResponse = await broadcastTransaction({ | ||
transaction, | ||
}); | ||
``` | ||
|
||
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. | ||
|
||
## Resources | ||
|
||
- [Stacks.js / Transactions](/stacks/stacks.js/packages/transactions) | ||
- [Post-conditions](/stacks/stacks.js/guides/post-conditions) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# Build a fungible token post-condition | ||
|
||
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. | ||
|
||
## Use cases | ||
|
||
- Securing token swaps with transfer amount validation | ||
|
||
## Resources | ||
|
||
- [Stacks.js / Transactions](/stacks/stacks.js/packages/transactions) | ||
- [Post-conditions](/stacks/stacks.js/guides/post-conditions) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# Build an NFT post-condition | ||
|
||
A helper function that creates a post-condition for NFT transfers using the `Pc` builder class, ensuring specific NFTs are handled as expected. | ||
|
||
## Use cases | ||
|
||
- Securing NFT transfers with ownership validation | ||
|
||
## Resources | ||
|
||
- [Stacks.js / Transactions](/stacks/stacks.js/packages/transactions) | ||
- [Post-conditions](/stacks/stacks.js/guides/post-conditions) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
# Create a sponsored transaction | ||
|
||
A script to create sponsored transactions where one party (the sponsor) pays the transaction fees for another party's transaction. | ||
|
||
## Use cases | ||
|
||
- Building onboarding flows where a service pays user fees | ||
- Creating DAO operations where treasury pays member fees | ||
|
||
## Example usage | ||
|
||
```typescript -cn | ||
import { | ||
broadcastTransaction, | ||
deserializeTransaction, | ||
sponsorTransaction, | ||
} from "@stacks/transactions"; | ||
// !hover serialized-tx | ||
import { serializedTx } from "./create-a-sponsored-tx"; | ||
|
||
const deserializedTx = deserializeTransaction(serializedTx); | ||
const sponsorOptions = { | ||
// !hover tx-options | ||
transaction: deserializedTx, | ||
// !hover tx-options | ||
sponsorPrivateKey: "<sponsor-private-key>", | ||
// !hover tx-options | ||
fee: 1000n; | ||
// !hover tx-options | ||
sponsorNonce: 0, | ||
// !hover tx-options | ||
network: STACKS_TESTNET, | ||
}; | ||
// !hover sponsor-tx | ||
const sponsoredTx = await sponsorTransaction(sponsorOptions); | ||
|
||
const broadcastResponse = await broadcastTransaction({ | ||
transaction: sponsoredTx, | ||
}); | ||
const txId = broadcastResponse.txid; | ||
``` | ||
|
||
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. | ||
|
||
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. | ||
|
||
## Resources | ||
|
||
- [Stacks.js / Transactions](/stacks/stacks.js/packages/transactions) | ||
- [Transaction Broadcasting](/stacks/stacks.js/guides/broadcast-transactions) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# Deploy a contract | ||
|
||
A script that deploys a Clarity smart contract to the Stacks blockchain using Stacks.js. | ||
|
||
## Example usage | ||
|
||
```typescript | ||
import { STACKS_TESTNET } from "@stacks/network"; | ||
import { makeContractDeploy, broadcastTransaction } from "@stacks/transactions"; | ||
import { readFileSync } from 'fs'; | ||
|
||
const txOptions = { | ||
contractName: "super-cool-contract", | ||
codeBody: readFileSync("./contract.clar", "utf8"), | ||
senderKey: "<your-private-key>", | ||
network: STACKS_TESTNET, | ||
}; | ||
|
||
const transaction = await makeContractDeploy(txOptions); | ||
const broadcastResponse = await broadcastTransaction({transaction}); | ||
const txId = broadcastResponse.txid; | ||
``` | ||
|
||
This example reads the contract code from a file and uses it to deploy a contract to the Stacks blockchain. | ||
|
||
## Resources | ||
|
||
- [Stacks.js / Transactions](/stacks/stacks.js/packages/transactions) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# Generate a secret key | ||
|
||
A script that generates BIP39 mnemonic phrases for use as wallet secret keys. | ||
|
||
## Use cases | ||
|
||
- Creating new wallets | ||
- Generating backup phrases | ||
- Testing wallet functionality | ||
|
||
## Resources | ||
|
||
- [Stacks.js](/stacks/stacks.js) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# Generate a wallet from a seed phrase or private key | ||
|
||
A script that creates a Stacks wallet from a seed phrase or private key, with support for multiple accounts. | ||
|
||
## Use cases | ||
|
||
- Creating new wallets from existing seed phrases | ||
- Restoring wallets from backups | ||
- Managing multiple accounts within a single wallet | ||
|
||
## Example usage | ||
|
||
```typescript | ||
import { generateWallet, generateNewAccount } from '@stacks/wallet-sdk'; | ||
|
||
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" | ||
const privateKey = "753b7cc01a1a2e86221266a154af739463fce51219d97e4f856cd7200c3bd2a601" | ||
|
||
let wallet = generateWallet({ | ||
// !diff - | ||
secretKey: mnemonic, | ||
// !diff + | ||
secretKey: privateKey, | ||
password: "secret", | ||
}); | ||
|
||
// !hover generate-new-account | ||
wallet = generateNewAccount(wallet); | ||
|
||
const { account1, account2 } = wallet; | ||
``` | ||
|
||
This example demonstrates: | ||
|
||
1. You can use either a seed phrase or private key to create a wallet. | ||
2. The <HoverLink href="hover:generate-new-account" className="text-[var(--ch-9)]">generateNewAccount</HoverLink> function adds a new account to the wallet. | ||
|
||
## Resources | ||
|
||
- [Stacks.js](/stacks/stacks.js) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# Get account details from a wallet | ||
|
||
A script that extracts important account details like the STX address and private key from a wallet. | ||
|
||
## Use cases | ||
|
||
- Retrieving wallet addresses for constructing transactions | ||
- Getting private keys for signing operations | ||
- Managing multiple wallet accounts | ||
|
||
## Resources | ||
|
||
- [Stacks.js](/stacks/stacks.js) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# Transfer STX tokens | ||
|
||
A script that creates and broadcasts an STX token transfer with <HoverLink href="hover:post-conditions">post-conditions</HoverLink> for secure transfers. | ||
|
||
## Use cases | ||
|
||
- Sending STX tokens between addresses | ||
- Building payment functionality | ||
|
||
## Resources | ||
|
||
- [Stacks.js / Transactions](/stacks/stacks.js/packages/transactions) | ||
- [Post-conditions](/stacks/stacks.js/guides/post-conditions) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters