Add DeFi examples for contract deployment and interaction - #1822
Open
serayd61 wants to merge 2 commits into
Open
Add DeFi examples for contract deployment and interaction#1822serayd61 wants to merge 2 commits into
serayd61 wants to merge 2 commits into
Conversation
friedger
suggested changes
Dec 30, 2025
friedger
left a comment
Contributor
There was a problem hiding this comment.
Looks like AI generated code based on historical stuff not being progressive.
Make it a real world example. Like https://github.com/friedger/clarity-ccip-026 or something similar.
| } from '@stacks/transactions'; | ||
| import { StacksMainnet, StacksTestnet } from '@stacks/network'; | ||
|
|
||
| // Contract source code (simple counter example) |
Contributor
There was a problem hiding this comment.
Simple counter is not defi and not real world example as mentioned in the readme.
| import { StacksMainnet, StacksTestnet } from '@stacks/network'; | ||
|
|
||
| // Contract source code (simple counter example) | ||
| const contractSource = ` |
Contributor
There was a problem hiding this comment.
In real world the contract is either generated or read from file.
| async function deployContract() { | ||
| // Configuration | ||
| const network = new StacksTestnet(); // Use StacksMainnet() for mainnet | ||
| const senderKey = 'YOUR_PRIVATE_KEY_HERE'; // Never commit real keys! |
Contributor
There was a problem hiding this comment.
How to never commit keys in real world?
| callReadOnlyFunction, | ||
| makeContractCall, | ||
| broadcastTransaction, | ||
| uintCV, |
Contributor
There was a problem hiding this comment.
Using Cl is more recommended nowadays because it requires less imports
| const CONTRACT_ADDRESS = 'SP2PEBKJ2W1ZDDF2QQ6Y4FXKZEDPT9J9R2NKD9WJB'; | ||
| const CONTRACT_NAME = 'voting'; | ||
|
|
||
| const network = new StacksMainnet(); |
| postConditionMode: PostConditionMode.Deny, | ||
| // Add post-condition to protect user | ||
| postConditions: [ | ||
| makeStandardFungiblePostCondition( |
Contributor
There was a problem hiding this comment.
We have better builders for post conditions nows.
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Added practical DeFi examples to help developers get started with stacks.js:
Motivation
The current documentation is great but could benefit from real-world examples.
These examples use actual deployed contracts on mainnet to show practical usage.
Changes
examples/defi/directoryTesting
All examples have been tested against mainnet contracts:
Related
These examples complement my open-source DeFi projects: