📖 What You’ll Learn
This guide teaches you how to integrate DeFindex API into your application using:- Freighter Wallet for secure wallet connection and transaction signing
- DeFindex API for creating yield-generating vault deposits and withdrawals
- Vault concepts like dfTokens (vault shares) and investment strategies
🎯 Prerequisites
Before starting, make sure you have:- Basic knowledge of HTML, CSS, and JavaScript
- Freighter Wallet extension installed
- An API key from DeFindex — follow the Getting Your API Key guide to register and create one
- A web browser with developer tools
- 5-10 minutes of focused time
🏗️ Project Structure Overview
Our vault deposit application consists of 6 main parts:🔧 Core Functions Explained
Function 1: Connect to Wallet 🔗
- Checks if Freighter wallet is available
- Requests permission to access the wallet
- Stores the wallet address for later use
- Updates the UI to show connection status
- User doesn’t have Freighter installed → Show installation instructions
- User denies permission → Ask them to try again
Function 2: Get Vault Info and Build Deposit Transaction 💰
- Validates wallet connection first
- Fetches vault information (name, assets, strategies)
- Builds a deposit transaction for the specified amount
- Prepares the transaction for signing (stores in app state)
- Updates the UI to enable the next step
- Wallet not connected → Connect wallet first
- API key rejected → The key was revoked, most often because a newer one was generated. Copy the current key from the console (see Getting Your API Key)
- Insufficient balance → Make sure wallet has enough XLM
- Vault not found → Check vault address and network
Function 3: Sign the Transaction ✍️
- Validates wallet connection and transaction availability
- Calls Freighter to sign the transaction
- Stores the signed transaction in app state
- Updates UI to enable final step
- User rejects signing → Ask them to try again
- Freighter not connected → Check wallet connection
- Wrong network → Ensure Freighter is on testnet
Function 4: Send Transaction to Network 🚀
- Validates we have a signed transaction ready
- Submits the transaction to the Stellar network through the DeFindex API
- Shows success message with transaction hash and explorer link
- Resets state for potential next transaction
🔄 Complete Workflow Summary
4-Step Process:🛠️ Key Concepts for Beginners
What is XDR?
XDR (External Data Representation) is how Stellar transactions are encoded:- Unsigned XDR: Transaction ready to be signed
- Signed XDR: Transaction with digital signature, ready to submit
What is a Vault?
A vault is a smart contract that:- Holds multiple users’ assets
- Automatically invests them in yield-generating strategies
- Issues dfTokens (vault shares) representing ownership
What are dfTokens?
dfTokens are like receipts for your vault deposit:- Represent your proportional share of the vault
- Increase in value as the vault earns yield
- Can be redeemed for underlying assets + profits
What are Strategies?
Strategies are investment protocols that:- Generate yield on deposited assets
- Examples: Blend Capital lending, liquidity providing
- Vaults can use multiple strategies to maximize returns
What is Signing?
Signing a transaction means:- Proving you own the wallet
- Authorizing the vault deposit
- Making it ready for the network
🚨 Security Best Practices
✅ DO:
- Use testnet for learning and testing
- Keep your API keys secure
- Verify transaction details before signing
- Start with small amounts
❌ DON’T:
- Put API keys in public code repositories
- Sign transactions you don’t understand
- Use mainnet while learning
- Hardcode private keys (never!)
🔧 Common Troubleshooting
Problem: “Freighter not found”
Solution: Install Freighter wallet extensionProblem: “403 Forbidden” error
Solution: Check your API key is correct and not expiredProblem: “Insufficient balance”
Solution: Make sure you have enough XLM in your wallet for the depositProblem: Transaction fails
Solution: Check you have enough XLM for fees and minimum deposit requirements🎓 Next Steps
Once you understand this basic example:- Customize the UI with better styling
- Add error handling for better user experience
- Support multiple vaults with different asset combinations
- Add APY tracking to show vault performance
- Try withdrawal functionality to redeem your dfTokens
- Learn about strategies and how they generate yield
📚 Additional Resources
- DeFindex API Docs: https://api.defindex.io/docs
- DeFindex Discord: https://discord.gg/aV5jHwmsaj
- Freighter Docs: https://freighter.app/docs
- Stellar Docs: https://developers.stellar.org
- Stellar Expert: https://stellar.expert (blockchain explorer)
- DeFindex: https://defindex.io
💡 Pro Tips
- Use browser dev tools to debug API calls
- Check the console for error messages
- Read API responses to understand what’s happening