Note: This project is a reference/example implementation of a Coin API server developed in Go. For deployment in a real production environment, additional security, performance optimization, and operational considerations are required.
This project is for educational purposes only and will not function without a database. We hope it serves as a useful reference for users looking to build REST APIs with Go or interested in utilizing BNB coins.
This API server is developed in Go language and provides backend services for managing blockchain-based coins and in-game chip systems. It is built using the Gin framework and utilizes MySQL database.
- Project Overview
- Key Features
- Prerequisites
- Database Configuration
- Local Development Setup
- Deployment with Docker
- Deployment with Kubernetes
- API Endpoint Examples
This API server provides backend services for managing blockchain-based coins and in-game chip systems. It is developed using the Go language and the Gin framework, and utilizes a MySQL database.
- User synchronization and management
- Jetton Coin balance, deposits, withdrawals, and transaction history management
- Wallet registration, updates, information retrieval, balance inquiry, and transfers
- Gas balance, fees, deposits, and deposit history management
- Chip purchase, conversion to Jetton Coin, and conversion history inquiry
- Jetton/Chip product inquiry
- Go: Go 1.24+ version
- Git: For source code management
- Docker: For container-based deployment
- MySQL: Database server (must be externally accessible)
Important: This project provides source code for reference only, and the actual database is not open. The database connection information below is an example configuration for the application to function, and you must set up your own database according to your environment.
The application reads database connection information from environment variables. The following environment variables must be set:
| Environment Variable | Description |
|---|---|
DB_USER |
MySQL username |
DB_PASSWORD |
MySQL password |
DB_HOST |
MySQL server IP address or hostname |
DB_PORT |
MySQL server port (default: 3306) |
DB_NAME |
Database name to use |
Example (.env file or environment variable setup):
export DB_USER="root"
export DB_PASSWORD="your_db_password"
export DB_HOST="your-db-host-ip"
export DB_PORT="3306"
export DB_NAME="your_database_name"
export APP_PORT="11809"-
Clone Source Code: Clone the project repository.
git clone <repository_url> # Navigate to the cloned repository directory (e.g., cd coin-api-server-go)
-
Download Dependencies: Download Go module dependencies.
go mod tidy
-
Set Environment Variables: Set the environment variables from the Database Configuration section above.
-
Run Application: Run the application directly.
go run ./cmd/main.go
The application will run on the port set by the
APP_PORTenvironment variable (default:11809).
-
Build Docker Image: Build the Docker image from the project root directory.
docker build -t your-dockerhub-username/coin-api-server:latest . -
Push Docker Image (Optional): Push the image to a container registry like Docker Hub.
docker push your-dockerhub-username/coin-api-server:latest
-
Run Docker Container: Run the container with environment variables.
docker run -d \ --name coin-api-app \ -p 11809:11809 \ -e DB_USER="your_db_user" \ -e DB_PASSWORD="your_db_password" \ -e DB_HOST="your-db-host-ip" \ -e DB_PORT="your_db_port" \ -e DB_NAME="your_database_name" \ -e APP_PORT="11809" \ your-dockerhub-username/coin-api-server:latest
- The values for
-eoptions must be replaced with your actual database information.
- The values for
-
Test Access: Test access via
http://<linux_host_ip>:11809/jetton-product/select(POST request).
For detailed Kubernetes deployment, refer to the DOC/kubernetes_deployment_guide.md file. The main steps are:
DockerfileVerification: Use the project'sDockerfileto build and push the Docker image to a registry.k8s-secret.yamlCreation: Create a Secret file for database credentials and fill in Base64 encoded values.# k8s-secret.yaml example apiVersion: v1 kind: Secret metadata: name: coin-api-db-secret type: Opaque data: DB_USER: "cm9vdA==" # Base64 encoded DB username DB_PASSWORD: "eW91cl9kYl9wYXNzd29yZA==" # Base64 encoded DB password
k8s-deployment.yamlCreation: Create a file defining Deployment and Service. Service type can beNodePortorLoadBalancer.# k8s-deployment.yaml example (NodePort type) apiVersion: apps/v1 kind: Deployment metadata: name: coin-api-server-deployment labels: app: coin-api-server spec: replicas: 2 selector: matchLabels: app: coin-api-server template: metadata: labels: app: coin-api-server spec: containers: - name: coin-api-server image: your-dockerhub-username/coin-api-server:latest ports: - containerPort: 11809 env: - name: DB_USER valueFrom: secretKeyRef: name: coin-api-db-secret key: DB_USER - name: DB_PASSWORD valueFrom: secretKeyRef: name: coin-api-db-secret key: DB_PASSWORD - name: DB_HOST value: "your-db-host-ip" - name: DB_PORT value: "3306" - name: DB_NAME value: "your_database_name" - name: APP_PORT value: "11809" --- apiVersion: v1 kind: Service metadata: name: coin-api-server-service labels: app: coin-api-server spec: selector: app: coin-api-server ports: - protocol: TCP port: 11809 targetPort: 11809 nodePort: 31809 # 30000-32767 range type: NodePort
- Deploy to Kubernetes Cluster: Deploy using
kubectl apply -f k8s-secret.yamlthenkubectl apply -f k8s-deployment.yaml.
All APIs use POST requests.
/users/sync/jetton-coin/balance/jetton-coin/deposit/jetton-coin/withdraw/jetton-coin/deposit-history/jetton-coin/withdraw-history/wallet/register/wallet/update/wallet/check/wallet/info/wallet/balance/wallet/jetton-balance/wallet/send/wallet/jetton-send/gas/balance/gas/fees/gas/deposit/gas/deposit-history/chips/purchase-with-jetton-coin/chips/convert-to-jetton-coin/chips/convert-history/jetton-product/select/chip-product/select
Note: This README.md file provides basic information about the project. Additional configuration or documentation may be required depending on the actual deployment environment and requirements.