Skip to content

GoLang backend for blockchain-based coin and in-game chip management. Features user sync, wallet operations, and transaction handling. An educational reference implementation for Go REST API development, particularly for BNB coin integration.

Notifications You must be signed in to change notification settings

wizinfantry/coin-api-server-go

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Coin API Server (GoLang)

English | 한국어

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.

Table of Contents

Project Overview

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.

Key Features

  • 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

Prerequisites

  • Go: Go 1.24+ version
  • Git: For source code management
  • Docker: For container-based deployment
  • MySQL: Database server (must be externally accessible)

Database Configuration

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"

Local Development Setup

  1. Clone Source Code: Clone the project repository.

    git clone <repository_url>
    # Navigate to the cloned repository directory (e.g., cd coin-api-server-go)
  2. Download Dependencies: Download Go module dependencies.

    go mod tidy
  3. Set Environment Variables: Set the environment variables from the Database Configuration section above.

  4. Run Application: Run the application directly.

    go run ./cmd/main.go

    The application will run on the port set by the APP_PORT environment variable (default: 11809).

Deployment with Docker

  1. Build Docker Image: Build the Docker image from the project root directory.

    docker build -t your-dockerhub-username/coin-api-server:latest .
  2. Push Docker Image (Optional): Push the image to a container registry like Docker Hub.

    docker push your-dockerhub-username/coin-api-server:latest
  3. 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 -e options must be replaced with your actual database information.
  4. Test Access: Test access via http://<linux_host_ip>:11809/jetton-product/select (POST request).

Deployment with Kubernetes

For detailed Kubernetes deployment, refer to the DOC/kubernetes_deployment_guide.md file. The main steps are:

  1. Dockerfile Verification: Use the project's Dockerfile to build and push the Docker image to a registry.
  2. k8s-secret.yaml Creation: 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
  3. k8s-deployment.yaml Creation: Create a file defining Deployment and Service. Service type can be NodePort or LoadBalancer.
    # 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
  4. Deploy to Kubernetes Cluster: Deploy using kubectl apply -f k8s-secret.yaml then kubectl apply -f k8s-deployment.yaml.

API Endpoint Examples

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.

About

GoLang backend for blockchain-based coin and in-game chip management. Features user sync, wallet operations, and transaction handling. An educational reference implementation for Go REST API development, particularly for BNB coin integration.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published