This guide provides comprehensive instructions for deploying the Kaspa integration in production environments for wallets, bridges, DEXs, and other applications.
- NEVER use
dfx_test_keyin production - this is only for local development - Use production threshold ECDSA keys with proper permissions
- Implement key rotation policies
- Use hardware security modules (HSMs) when possible
- Limit derivation path exposure
- Always use HTTPS for API calls
- Implement rate limiting for HTTP requests
- Validate all external API responses
- Use IP whitelisting for sensitive operations
- Monitor for suspicious activity
- All inputs are validated using the
Validationmodule - Cryptographic operations use vetted libraries
- Error messages don't leak sensitive information
- Debug prints are disabled in production builds
- IC subnet with sufficient compute and storage
- Production threshold ECDSA key configured
- Monitoring and alerting setup
- Backup and disaster recovery plan
- Load testing completed
- Security audit completed
- Penetration testing performed
- Key management procedures documented
- Incident response plan created
- Access controls implemented
- Transaction throughput tested
- Memory usage optimized
- Cycle consumption measured
- API rate limits configured
- Caching strategies implemented
- Regulatory requirements reviewed
- Privacy policy updated
- Terms of service updated
- Audit logs configured
- Compliance monitoring setup
errors.mo- Comprehensive error handlingvalidation.mo- Input validation and sanitizationaddress.mo- Enhanced address operationswallet.mo- Production wallet functionality
βββββββββββββββββββ βββββββββββββββββββ βββββββββββββββββββ
β Frontend β β Backend β β IC Canister β
β Application βββββΆβ API Gateway βββββΆβ Kaspa Wallet β
βββββββββββββββββββ βββββββββββββββββββ βββββββββββββββββββ
β
βββββββββββββββββββ
β Kaspa Network β
β (via API) β
βββββββββββββββββββ
# Install dependencies
npm install -g ic-mops
mops install
# Configure production key
dfx identity use production # Create this identity firstCreate production configuration:
let production_config = {
key_name = "production_kaspa_key"; // Your production key
api_host = "api.kaspa.org";
network = "mainnet";
max_fee = 1_000_000; // 0.01 KAS
default_fee_rate = 1000; // Adjust based on network conditions
};# Deploy to IC mainnet
dfx deploy --network ic --with-cycles 10000000000000
# Verify deployment
dfx canister --network ic call your_canister_name get_kaspa_address '(null)'Run comprehensive tests:
# Run tests
mops testpublic type WalletConfig = {
key_name: Text; // Production ECDSA key name
api_host: Text; // Kaspa API endpoint
network: Text; // "mainnet" or "testnet"
max_fee: Nat64; // Maximum allowed fee
default_fee_rate: Nat64; // Default fee rate (sompi/byte)
};// Adjust these constants based on your requirements
public let DUST_THRESHOLD : Nat64 = 1_000; // Minimum output
public let MIN_FEE : Nat64 = 1_000; // Minimum fee
public let MAX_FEE : Nat64 = 100_000_000; // Maximum fee (1 KAS)-
Transaction Metrics
- Transaction success rate
- Average transaction time
- Fee distribution
- UTXO utilization
-
System Metrics
- Cycle consumption
- Memory usage
- API response times
- Error rates
-
Security Metrics
- Failed authentication attempts
- Invalid address attempts
- Unusual transaction patterns
- API rate limit hits
// Add logging for production monitoring
public func logTransaction(
from: Text,
to: Text,
amount: Nat64,
fee: Nat64,
success: Bool
) {
// Log to your monitoring system
Debug.print("TX: " # from # " -> " # to # " : " # debug_show(amount) # " fee:" # debug_show(fee) # " success:" # debug_show(success));
};// Always validate inputs
let validation_result = Validation.validateAddress(address);
switch (validation_result) {
case (#ok(addr_info)) { /* Process valid address */ };
case (#err(error)) {
// Log security event
logSecurityEvent("Invalid address attempt: " # address);
return #err(error);
};
};// Use structured error handling
switch (wallet.sendTransaction(from, to, amount, fee, path)) {
case (#ok(result)) { /* Handle success */ };
case (#err(#InsufficientFunds(e))) { /* Handle insufficient funds */ };
case (#err(#NetworkError(e))) { /* Handle network issues */ };
case (#err(error)) { /* Handle other errors */ };
};// Implement per-caller rate limiting
private stable var rate_limits: [(Principal, Nat64)] = [];
private func checkRateLimit(caller: Principal) : Bool {
// Implement your rate limiting logic
true
};Implement circuit breakers for critical operations:
private stable var emergency_mode = false;
public func enableEmergencyMode() : async () {
// Only callable by authorized principals
emergency_mode := true;
};
private func checkEmergencyMode() : Result.Result<(), Errors.KaspaError> {
if (emergency_mode) {
return #err(Errors.internalError("System in emergency mode"));
};
#ok(())
};-
Immediate Response
- Enable emergency mode
- Stop new transactions
- Assess scope of issue
-
Investigation
- Review transaction logs
- Check system metrics
- Analyze error patterns
-
Recovery
- Fix underlying issue
- Test thoroughly
- Gradually resume operations
- Monitor Kaspa network upgrades
- Update API endpoints if needed
- Review and update fee estimates
- Perform security updates
- Check cycle balance regularly
- Monitor API rate limits
- Review error logs
- Test key availability
- Review error messages using
Errors.errorToText() - Check network status at https://kaspa.org
- Monitor transaction status via block explorers
- Contact your security team for key-related issues
Consider implementing transaction batching for high-volume applications:
public func batchSendTransactions(
transactions: [TransactionRequest]
) : async [Result.Result<TransactionResult, Errors.KaspaError>] {
// Implement batching logic
[]
};Implement intelligent UTXO selection and consolidation strategies:
private func optimizeUTXOSet(utxos: [Types.UTXO]) : [Types.UTXO] {
// Implement UTXO optimization
utxos
};Cache frequently accessed data:
private stable var address_cache: [(Text, AddressV2.AddressInfo)] = [];This guide provides a foundation for production deployment. Customize based on your specific requirements and security policies.