Skip to main content

Integration Best Practices

Follow these best practices for a robust HashNut integration.

Security

  1. Secure API Keys: Never commit keys to version control
  2. HTTPS Only: Use HTTPS for all webhook endpoints
  3. Environment Variables: Store credentials in environment variables

Error Handling

  1. Handle All States: Handle all order states (0-4, -1, -2, -3)
  2. Retry Logic: Implement retry logic for transient errors
  3. User-Friendly Messages: Provide clear error messages
  4. Logging: Log all errors for debugging

Order Management

  1. Unique Order IDs: Use unique merchant order IDs
  2. Idempotency: Make operations idempotent
  3. State Tracking: Track order states in your database
  4. Regular Polling: Poll order status for active orders

Webhooks

  1. Idempotency: Handle duplicate webhook deliveries
  2. Quick Response: Respond within 30 seconds
  3. Error Handling: Return appropriate error codes

Performance

  1. Async Processing: Process webhooks asynchronously
  2. Batch Operations: Batch operations when possible
  3. Caching: Cache chain/token information
  4. Connection Pooling: Use connection pooling

Testing

  1. Testnet First: Test on testnet before production
  2. Webhook Testing: Use ngrok for local webhook testing
  3. Error Scenarios: Test all error scenarios
  4. Load Testing: Test under load

Next Steps


Following best practices? Check API Reference →