Skip to content

ZSZYoung/A-basic-blockchain-implementation-using-Go-Web-

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Blockchain Demo

A simple and interactive blockchain demo built with Go and HTMX. This project demonstrates the core functionalities of a blockchain, including creating blocks, managing wallets, sending transactions, and viewing the blockchain data. The web interface is designed to make blockchain interactions intuitive and user-friendly.


Features

Blockchain Core

  • Block Creation: Implements proof-of-work and block validation.
  • Transaction Management: Supports creating and verifying transactions.
  • Wallets: Generate wallets with unique addresses and manage balances.
  • Persistence: Stores blockchain data and wallets using a file-based database.

Web Interface

  • Interactive UI: Built with HTMX and Bootstrap for a responsive and dynamic experience.
  • Blockchain Visualization: View the blockchain structure, including blocks, transactions, and hashes.
  • Wallet Management: Create wallets and list all wallet addresses.
  • Transaction Execution: Send transactions between wallets and view the updated balances.

API

  • RESTful API endpoints for blockchain operations, including:
    • Creating a blockchain
    • Retrieving wallet balances
    • Sending transactions
    • Printing the blockchain

Project Structure

blockchain_demo/
├── cmd/
│   ├── api/                # Backend API entry point
│   │   └── main.go
│   ├── web/                # Web interface
│       ├── index.html
│       ├── assets/
│       │   └── js/htmx.min.js
│       ├── css/styles.css
│       └── js/scripts.js
├── Database/               # Persistent storage for blocks and wallets
│   ├── blocks/
│   └── wallets/
├── internal/
│   ├── blockchain_Logic/   # Core blockchain logic
│   │   ├── blockchain/
│   │   ├── cli/
│   │   ├── utils/
│   │   └── wallet/
│   └── server/             # API routes and server logic
├── .env                    # Environment variables
├── go.mod                  # Go module dependencies
├── README.md               # Project documentation
└── Makefile                # Build and run commands

Getting Started

Prerequisites

  • Go 1.20 or higher
  • A modern web browser

Installation

  1. Clone the repository:

    git clone https://github.com/<your-username>/blockchain_demo.git
    cd blockchain_demo
  2. Install dependencies:

    go mod tidy
  3. Set up environment variables:

    • Create a .env file in the root directory.
    • Add the following variables:
      PORT=8080
      DATABASE_PATH=./Database
      
  4. Run the application:

    go run cmd/api/main.go
  5. Open the web interface:

    • Navigate to http://localhost:8080 in your browser.

Web Interface Overview

Sections

  1. Create Blockchain: Initialize a new blockchain.
  2. Get Balance: Retrieve the balance of a specific wallet address.
  3. Print Chain: View the entire blockchain, including blocks and transactions.
  4. Send Transaction: Transfer funds between wallets.
  5. Create Wallet: Generate a new wallet with a unique address.
  6. List Addresses: Display all wallet addresses.

Screenshots

webshow


API Endpoints

Method Endpoint Description
POST /create-blockchain Initialize a new blockchain.
GET /get-balance/:address Get wallet balance.
POST /send-transaction Send a transaction.
GET /print-chain Print the blockchain.
POST /create-wallet Create a new wallet.
GET /list-addresses List all wallet addresses.

Acknowledgments

  • HTMX for dynamic web interactions.
  • Bootstrap for responsive design.
  • The Go community for their amazing tools and libraries.

About

The web version for a simple bitcoin-like blockchain implementation

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published