This project implements the GraphQL API for transferring BTP tokens between wallets. The API enables the transfer of tokens from one wallet to another, providing error handling in case of insufficient balance or race conditions.
- Golang 1.24.2
- GraphQL
- Docker Compose
- PostgreSQL
- GORM
- tested with testify
-
Download Docker Compose following instructions: https://docs.docker.com/compose/install/
-
Clone the repository:
git clone https://github.com/damianlebiedz/token-transfer-api.git
cd token-transfer-api
- Create a
.envfile in the project's directory with the following variables:
# Production database configuration
POSTGRES_USER=your_user
POSTGRES_PASSWORD=your_password
# Test database configuration
TEST_POSTGRES_USER=your_test_user
TEST_POSTGRES_PASSWORD=your_test_password
Important
.env file is required to run the application. Never commit your .env file to a public repository!
- Build and run the application using docker-compose:
docker-compose up --build app
Important
If you are using Docker Desktop make sure it is turned on - otherwise docker-compose will not work.
- Access the GraphQL playground at: http://localhost:8080/playground This is where you can test the GraphQL queries and mutations.
Example mutation:
mutation {
transfer(from: "0x0000000000000000000000000000000000000000", to: "0x0000000000000000000000000000000000000001", amount: 100) {
balance
}
}
This mutation creates a second wallet and transfers a balance of 100 tokens from the initial wallet (0x000...0000) to the new one (0x000...0001). It returns the updated balance of the sender wallet after the transfer.
Note
To close the connection press Ctrl+C.
- Build and run tests using docker-compose:
docker-compose up --build test
Note
You can configure your own tests in transfer_test.go file.
Damian Lebiedź | https://damianlebiedz.github.io/contact.html