-
Notifications
You must be signed in to change notification settings - Fork 314
Add DeFi examples for contract deployment and interaction #1822
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
friedger
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 = ` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How to never commit keys in real world?
| callReadOnlyFunction, | ||
| makeContractCall, | ||
| broadcastTransaction, | ||
| uintCV, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using Cl is more recommended nowadays because it requires less imports
| const CONTRACT_ADDRESS = 'SP2PEBKJ2W1ZDDF2QQ6Y4FXKZEDPT9J9R2NKD9WJB'; | ||
| const CONTRACT_NAME = 'voting'; | ||
|
|
||
| const network = new StacksMainnet(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Only name is required
| postConditionMode: PostConditionMode.Deny, | ||
| // Add post-condition to protect user | ||
| postConditions: [ | ||
| makeStandardFungiblePostCondition( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have better builders for post conditions nows.
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: