IOTA Faucet
The IOTA Faucet service distributes testnet tokens to developers for testing and development purposes.Overview
The faucet provides:- HTTP API for requesting test tokens
- Rate limiting to prevent abuse
- Batch processing for efficient token distribution
- Write-Ahead Log (WAL) for reliability
- Prometheus metrics for monitoring
Architecture
The faucet consists of:- SimpleFaucet: Core faucet logic managing gas coin pool
- HTTP Server: Axum-based REST API
- Batch Transfer Task: Background worker for batch requests
- Write-Ahead Log: Persistent transaction log for reliability
Configuration
The faucet is configured via command-line arguments:Command-line Options
Network Configuration
--port <PORT>: Server port (default:5003)--host-ip <IP>: Server host IP (default:127.0.0.1)
Token Distribution
--amount <AMOUNT>: Amount per coin in nanoIOTA (default:1000000000= 1 IOTA)--num-coins <NUM>: Number of coins per request (default:1)
Performance & Limits
--request-buffer-size <SIZE>: Request buffer size (default:10)--max-request-per-second <NUM>: Max requests per second (default:10)--max-request-queue-length <NUM>: Max queue length (default:10000)--batch-request-size <NUM>: Batch size for processing (default:500)
Rate Limiting
--enable-rate-limiting: Enable rate limiting (default:false)--max-requests-per-window <NUM>: Max requests per window (default:12)--rate-window-secs <SECS>: Rate limit window in seconds (default:43200= 12 hours)
Reliability
--write-ahead-log <PATH>: Path to WAL file (required)--wal-retry-interval <SECS>: WAL retry interval (default:300seconds)--ttl-expiration <SECS>: Task cache TTL (default:300seconds)
Wallet Configuration
--wallet-client-timeout-secs <SECS>: Wallet client timeout (default:60)
Batch Mode
--batch-enabled: Enable batch processing (default:false)
Environment Variables
MAX_CONCURRENCY: Override default concurrency limit (default:30)
Running the Faucet
Prerequisites
-
IOTA Wallet Configuration: Create wallet with funded address
- Located at
~/.iota/iota_config/client.yamlby default - Must have sufficient IOTA tokens for distribution
- Located at
-
Write-Ahead Log Directory: Create directory for WAL
Basic Setup
Start the faucet with default configuration:Production Configuration
For production use with rate limiting:With Custom Token Amounts
API Endpoints
Health Check
OK if the faucet is running.
Example:
Request Gas (Legacy)
Batch Request Gas (v1)
Check Request Status
Rate Limiting
When enabled, rate limiting prevents abuse:Configuration
- Window Duration: Time window for counting requests (e.g., 12 hours)
- Max Requests: Maximum requests per address in the window
- Tracked Addresses: Up to 100,000 addresses tracked simultaneously
Behavior
- Tracks requests per recipient address
- Removes expired entries from tracking
- Returns
503 Service Unavailablewhen limit exceeded - Old requests automatically age out after window expires
Example Error Response
Batch Processing
Batch mode improves efficiency by grouping multiple requests:Benefits
- Reduced transaction overhead
- Lower gas costs
- Higher throughput
Configuration
How It Works
- Requests are queued in memory
- Background task gathers up to
batch-request-sizerequests - Single transaction transfers tokens to multiple recipients
- Status tracked via task ID
Write-Ahead Log (WAL)
The WAL ensures reliability:Purpose
- Records pending transactions before execution
- Enables retry after faucet restart
- Prevents token loss on failure
Behavior
- Transaction written to WAL before sending
- WAL entry removed on success
- Failed transactions remain in WAL
- WAL retried periodically (default: every 300 seconds)
Manual WAL Retry
The faucet automatically retries WAL entries, but you can also:- Stop the faucet
- Fix any issues (network, wallet, etc.)
- Restart the faucet - WAL entries are retried on startup
Monitoring
Prometheus metrics exposed on port9184:
Key Metrics
faucet_total_requests: Total requests receivedfaucet_total_successful: Successful token transfersfaucet_total_failed: Failed transfersfaucet_available_coins: Available gas coins in poolfaucet_discarded_coins: Coins removed from poolfaucet_current_executions: In-flight transactions
Access Metrics
Error Handling
Common Errors
No Gas Coins AvailableSecurity Considerations
- Testnet Only: Never run faucet on mainnet
- Rate Limiting: Always enable for public faucets
- CORS: Configure CORS appropriately for your use case
- Monitoring: Monitor metrics for abuse patterns
- Wallet Security: Protect wallet configuration and keys
Best Practices
- Enable Rate Limiting: Prevent abuse on public faucets
- Use Batch Mode: Improve efficiency for high traffic
- Monitor Metrics: Track usage and performance
- Regular WAL Cleanup: Monitor WAL size
- Sufficient Funds: Maintain adequate balance in faucet wallet
- Backup WAL: Backup WAL file periodically
Troubleshooting
Faucet Won’t Start
- Verify wallet configuration exists
- Check wallet has funded address
- Ensure WAL directory is writable
No Tokens Distributed
- Check wallet balance
- Verify network connectivity to fullnode
- Review logs for errors
- Check WAL for stuck transactions
High Error Rate
- Monitor metrics at
:9184/metrics - Check fullnode connectivity
- Review gas coin pool size
- Check for insufficient balance