# Blockchain Challenge Task 🔗

## Our Idea 💡

A tool for donations where a donator can mint an NFT according to the amount donated which is represented in multiple tiers. The owner of the contract can withdraw all donations done to the contract.

Donators can mint an NFT to donate to the contract. All currency is saved on the contract and can only be withdrawn by the owner of the contract.

## Technologies 🦾

The smart contract is written in Solidity. The frontend is built with Django which handles server-side logic and database management. Tailwind CSS provides a consistent and customizable design system with a minimal footprint.

The whole project is containerized with Docker which simplifies application deployment and management.

## Start Project 🚀

To start with this project, deploy the contract with your wallet and copy the contract address. Change the `contractAddress` in `home.html` to your own.

Build the project.
``` sh
docker compose up --build
```

## New? 🆕
If the project is started the first time, one need to apply the python migrations inside the docker container

``` sh
docker exec -it blockchainchallengetask-web-1 python3 manage.py migrate
```

## Docker Troubleshoot 🐳

Docker assists in containerizing the various components of the project, ensuring smooth and consistent operations across different environments. Here are explanations of some common Docker commands used during the project's deployment and maintenance:

- `docker rm -f $(docker ps -qa)`: Forcefully removes all running and stopped containers, helping in resetting the Docker environment.
- `docker volume ls`: Lists all the volumes created in the Docker environment, which are used to persist data generated by and used by Docker containers.
- `docker exec -it <hash> python3 manage.py migrate`: Runs the migration scripts inside a running container (identified by `<hash>`) to set up or update the database schema, a crucial step in initializing or updating the database structure within the Django application running in a container.
- `docker compose up`: Starts up all the services defined in the `docker-compose.yml` file, initializing the entire application stack including backend services, databases, and frontend applications.
- `docker compose down`: Stops and removes all the containers defined in the `docker-compose.yml` file, facilitating the graceful shutdown of the application stack and cleaning up the resources utilized by the containers.

### Delete Containers 🗑

``` sh
docker rm -f $(docker ps -qa)
```

### Delete Volumes 🗑

``` sh
docker volume rm -f $(docker volume ls -q)
```

### Execute command in Container 📟

``` sh
docker exec -it <hash> <command>
```

## Django Development 🐍

### Starting a New App 📦

In Django, an app is a self-contained unit of code that can be used in multiple projects. To create a new app within your Django project, follow these steps:

1. Navigate to the root directory of your Django project (where `manage.py` is located) in the terminal.
2. Use the following command to create a new app: `python manage.py startapp <app_name>`

3. After running the command, a new directory named `<app_name>` will be created with the basic structure of a Django app.

### Django App Structure 📂

Here is a brief explanation of the files and directories that are created when you start a new app:

- `__init__.py`: An empty file that tells Python that this directory should be treated as a package.
- `admin.py`: A file where you can define the admin interface for your app.
- `apps.py`: A file containing the configuration of your app.
- `migrations/`: A directory where Django stores migration files.
- `models.py`: A file where you define the data models of your app.
- `tests.py`: A file where you can write unit tests for your app.
- `views.py`: A file where you define the views for your app. Views determine what content is displayed on the screen when a user navigates to a particular URL.

### Integrating the App into Your Project 🔗🔄

After creating a new app, you need to integrate it into your Django project by following these steps:

1. Open the `settings.py` file of your Django project (located in the project's main directory).
2. Add the name of your app to the `INSTALLED_APPS` list in the `settings.py` file. It should look something like this:
INSTALLED_APPS = [
    ...,
    '<app_name>',
]
