BTC Wallet is a sample API that "simulates" a platform that allow users to register, create own BTC wallets and transfer BTC to other wallets inside it. Platform makes 1.5% profit from the transactions between users.
- Python: 3.8
- Django: 2.2
- Django Rest Framework: 3.11
- PostgreSQL: 12.2
-
Clone the project:
$ git clone https://github.com/dnievas04/btcwalletapi.git
-
Run docker-compose commands to build and start containers:
$ docker-compose up -d --build
-
Test if API is running at http://localhost:8000/api/v1/users/
Some settings are required to configure the API. Use the .env file in the project root to change default values, os just define the required OS environment variables.
Hardcoded Token to authenticate the administrator. Required for statistics
Hardcoded wallet address used by the platform to perform transactions between platform and users. For example to grant bitcoins when users create a wallet
Username and password for the user platform who owns the platform wallet.
Refers to the minimum bitcoins amount allowed to transfer between different users
Transaction costs of the transferred amount (profit of the platform) if transferred to a wallet of another user. Hardcoded at 1.5%
Tests can be run as follow:
$ docker-compose exec web python manage.py test
The API uses the TokenAuthentication scheme provided by DRF. This is a simple token-based HTTP Authentication scheme.
To obtain a valid token, you must first create a user. The endpoint to create users is /api/v1/users
and accepts POST requests. The endpoint returns the token that is required to authenticate all other requests for this user.
The following examples uses HTTPie to consume the API endpoints via the terminal.
$ http post http://localhost:8000/api/v1/users/ username=test password=123
The response body:
{
"token": "9c6ded39ecdb4568f562e5bd2bc31195cdf3e147"
}
In order to access the protected views (the API endpoints that require authentication), you should include the token in the header of all requests. For example create BTC wallet for the authenticated user:
$ http post http://localhost:8000/api/v1/wallets/ "Authorization: Token 9c6ded39ecdb4568f562e5bd2bc31195cdf3e147"
Check the docs for all available endpoints.