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.
- 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.
- 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.
- RESTful API endpoints for blockchain operations, including:
- Creating a blockchain
- Retrieving wallet balances
- Sending transactions
- Printing the blockchain
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
- Go 1.20 or higher
- A modern web browser
-
Clone the repository:
git clone https://github.com/<your-username>/blockchain_demo.git cd blockchain_demo
-
Install dependencies:
go mod tidy
-
Set up environment variables:
- Create a
.envfile in the root directory. - Add the following variables:
PORT=8080 DATABASE_PATH=./Database
- Create a
-
Run the application:
go run cmd/api/main.go
-
Open the web interface:
- Navigate to
http://localhost:8080in your browser.
- Navigate to
- Create Blockchain: Initialize a new blockchain.
- Get Balance: Retrieve the balance of a specific wallet address.
- Print Chain: View the entire blockchain, including blocks and transactions.
- Send Transaction: Transfer funds between wallets.
- Create Wallet: Generate a new wallet with a unique address.
- List Addresses: Display all wallet addresses.
| 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. |
