Integration Best Practices
Follow these best practices for a robust HashNut integration.
Security
- Secure API Keys: Never commit keys to version control
- HTTPS Only: Use HTTPS for all webhook endpoints
- Environment Variables: Store credentials in environment variables
Error Handling
- Handle All States: Handle all order states (0-4, -1, -2, -3)
- Retry Logic: Implement retry logic for transient errors
- User-Friendly Messages: Provide clear error messages
- Logging: Log all errors for debugging
Order Management
- Unique Order IDs: Use unique merchant order IDs
- Idempotency: Make operations idempotent
- State Tracking: Track order states in your database
- Regular Polling: Poll order status for active orders
Webhooks
- Idempotency: Handle duplicate webhook deliveries
- Quick Response: Respond within 30 seconds
- Error Handling: Return appropriate error codes
Performance
- Async Processing: Process webhooks asynchronously
- Batch Operations: Batch operations when possible
- Caching: Cache chain/token information
- Connection Pooling: Use connection pooling
Testing
- Testnet First: Test on testnet before production
- Webhook Testing: Use ngrok for local webhook testing
- Error Scenarios: Test all error scenarios
- Load Testing: Test under load
Next Steps
- API Reference: Complete API documentation
- Troubleshooting: Common issues
Following best practices? Check API Reference →