This is a simple Django REST Framework (DRF) application that implements a cryptocurrency faucet. It allows users to request a small amount (0.0001) of ETH to be sent to a specified wallet address. The application includes rate-limiting to prevent abuse and provides statistics on transactions (successful and failed) made through the faucet.
- Request ETH to be sent to a wallet address
- Rate-limited to one request per minute per IP address
- Fetch statistics on successful and failed transactions in the past 24 hours
- Error handling for failed transactions
Make sure you have the following installed on your machine:
- Python 3.11
- poetry
- Docker and docker-compose (optional)
git clone https://github.com/vsaverin/faucet-api.git
cd faucet-apipoetry shellpoetry installCreate a .env file in ./deploy and define the following environment variables:
SECRET_KEY=your-secret-key
DEBUG=True
NODE_URL="https node url"
SOURCE_WALLET="wallet to send eth from"
PRIVATE_KEY="and its private key"
pythone manage.py migratepython3 manage.py createsuperuserpython3 manage.py runserverdocker-compose -f ./deploy/docker-compose.yml up --builddocker-compose -f ./deploy/docker-compose.yml run web python manage.py migratedocker-compose -f ./deploy/docker-compose.yml run web python manage.py createsuperuserNow application is available at http://localhost:8000/
Swagger API Documentation is available at http://localhost:8000/api/schema/swagger-ui/
Send 0.0001 ETH to the specified wallet address. Rate-limited to one request per minute per IP address.
- URL:
/faucet - Method: POST
- Request Body:
{ "wallet_address": "0xYourWalletAddress" } - Response Example (200 OK):
{ "tx_id": "0xTransactionHash" } - Response Example (429 Rate Limited):
{ "error": "Rate limit exceeded. Please wait 1 minute." }
Get the statistics for the faucet over the past 24 hours. Returns the count of successful and failed transactions.
- URL:
/faucet/stats - Method: GET
- Response Example (200 OK):
{ "successful_transactions": 10, "failed_transactions": 2 }
python3 manage.py test