Best Practices
Guidelines for building robust applications with the SatsTerminal Borrow SDK.Initialization
Always Call Setup First
Validate Configuration
Use Environment-Specific Configuration
Error Handling
Always Handle Errors
Use Typed Error Handling
Handle Workflow Errors Separately
Session Management
Check Session Before Operations
Clear Session on Disconnect
Workflow Tracking
Always Provide All Callbacks
Persist Workflow IDs
Resume Pending Workflows
Quotes
Validate Quote Selection
Configure Quote Selector
Transactions
Validate Inputs
Check Collateral Before Withdrawal
Performance
Cache Positions
Batch Operations
Use Appropriate Poll Interval
Security
Never Log Sensitive Data
Validate BTC Addresses
Use Secure Storage
Testing
Mock the SDK
Test Error Scenarios
Logging
Structured Logging
Log Important Events
Unit Handling
Use Units for Type-Safe Conversions
Normalize Unknown Units
When handling values from API responses where units may be ambiguous:Use ResponseNormalizer for API Responses
Format Consistently for Display
Summary
- Initialize properly - Always call
setup()before operations - Handle all errors - Use typed error handling
- Manage sessions - Check validity, refresh proactively
- Track workflows - Persist IDs, handle all callbacks
- Validate inputs - Check parameters before API calls
- Cache when possible - Reduce unnecessary API calls
- Secure sensitive data - Don’t log secrets, validate addresses
- Test thoroughly - Mock SDK, test error paths
- Log structured data - Track important events