Developer Docs
Developer Guide: SDK Integration
A comprehensive guide for developers to integrate StableFlow’s cross-chain transfers into your applications.
Table of Contents
Getting Started
Installation
npm install stableflow-ai-sdkPrerequisites
Node.js: Version 16 or higher
TypeScript (recommended): For full type safety
API Configuration
Basic Setup
Configuration Options
OpenAPI.BASE
string
API endpoint URL
Yes
OpenAPI.TOKEN
string
JWT authentication token
Yes
OpenAPI.WITH_CREDENTIALS
boolean
Include credentials in requests
No
OpenAPI.HEADERS
object
Additional request headers
No
Core Functions
1. getTokens()
getTokens()Retrieves the list of all supported tokens across different blockchains.
Signature
Returns
Array of TokenResponse objects containing:
Example Usage
Use Cases
Building token selection UI
Validating supported tokens
Getting current token prices
Discovering available networks
2. getQuote()
getQuote()Requests a quote for cross-chain token swap, including fees, estimated time, and deposit address.
Signature
Request Parameters
Response
Example Usage
Important Notes
dry: true: Testing mode, no real deposit addressdry: false: Production mode, returns real deposit addressAmount Format: Always use smallest token unit (e.g., 1 USDT = 1000000 for 6 decimals)
Deadline: Must be a future timestamp in ISO 8601 format
Address Validation: Ensure addresses match the respective network format
3. submitDepositTx()
submitDepositTx()Notifies StableFlow that you've sent tokens to the deposit address.
Signature
Request Parameters
Response
Example Usage
When to Call
After sending tokens to
depositAddressAfter transaction is confirmed on blockchain
Before checking execution status
4. getExecutionStatus()
getExecutionStatus()Checks the current status of a cross-chain swap.
Signature
Parameters
depositAddress
string
Deposit address from quote
Response
Example Usage
Polling Example
Working Examples
The SDK includes a complete web application example demonstrating real-world usage.
Web Demo Application
Location: examples/web-demo/
Features
â Real wallet connection (MetaMask)
â Network switching
â Token balance checking
â Quote generation
â Transaction execution
â Status tracking
Running the Example
Key Files to Study
app.ts- Main application logicWallet connection:
connectWallet()Network switching:
switchNetwork()Getting quotes:
handleGetQuote()Executing swaps:
executeBridge()
Network Configuration
ERC20 Token Transfer
Learning Path
Start with: Understanding the flow in
app.tsStudy: Network configuration and asset IDs
Review: Error handling patterns
Examine: UI/UX best practices
Customize: Adapt for your use case
Best Practices
1. Error Handling
Always wrap SDK calls in try-catch blocks:
2. Token Amount Conversion
Always convert human-readable amounts to smallest units:
3. Deadline Management
Set reasonable deadlines:
4. Network Validation
Validate network compatibility:
5. Status Polling
Implement exponential backoff:
Common Use Cases
Use Case 1: Simple USDT Bridge
Bridge USDT from Ethereum to Arbitrum:
Use Case 2: Dynamic Token Selection
Let users choose any supported token pair:
Use Case 3: Fee Calculator
Calculate bridge fees before execution:
Troubleshooting
Common Issues
1. "Invalid token" Error
Cause: Using incorrect assetId format
Solution: Always get asset IDs from getTokens():
2. "Deadline is not valid" Error
Cause: Deadline is in the past or incorrect format
Solution: Use ISO 8601 format with future timestamp:
3. Authentication Errors
Cause: Missing or invalid JWT token
Solution:
After receiving your token, set it before any API calls:
4. Network Mismatch
Cause: Wallet on wrong network when sending transaction
Solution: Check and switch network before transaction:
5. Transaction Stuck
Cause: Transaction not confirmed on blockchain
Solution: Wait for confirmation before submitting:
Additional Resources
SDK Repository
GitHub: stableflow-ai/stableflow-ai-sdk
Examples:
examples/directoryIssues: Report bugs via GitHub Issues
StableFlow Platform
Website: https://app.stableflow.ai/
API Access: Apply for JWT token
Documentation: Latest API specs
Community
Discord: Join our community
Twitter: @StableFlowAI
Summary
Quick Reference
getTokens()
List supported tokens
JWT Token
getQuote()
Get swap quote
JWT Token, QuoteRequest
submitDepositTx()
Notify deposit
JWT Token, txHash, depositAddress
getExecutionStatus()
Check swap status
JWT Token, depositAddress
Integration Checklist
Happy Building!
For questions or support, visit our GitHub repository or join our Discord community.
Last updated