Skip to content

This repository features a blockchain implementation in Go, utilizing the UTXO (Unspent Transaction Output) model. The project currently supports basic transactions and wallet functionality, laying the groundwork for a decentralized cryptocurrency system.

Notifications You must be signed in to change notification settings

ayushn2/blockchainx

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Go Blockchain with Proof of Work and Command-Line Interface

This project is a simple blockchain implementation written in Go. It includes functionality for creating blocks, adding transactions, implementing a Proof-of-Work (PoW) consensus mechanism, and interacting with the blockchain via a Command-Line Interface (CLI).

Features

Blockchain Core Features

  • Blockchain Structure:
    A chain of blocks linked together through cryptographic hashes.

  • Transactions:
    Transactions are stored in each block, showcasing the core idea of a blockchain as a ledger.

  • Proof of Work (PoW):
    A computational challenge that miners must solve to create a valid block.

  • Block Details:
    Each block contains:

    • Index: The block's position in the chain.
    • Timestamp: When the block was created.
    • Transactions: Data stored in the block.
    • Nonce: A value adjusted to meet the PoW requirements.
    • Previous Hash: The hash of the previous block in the chain.
    • Current Hash: The hash representing the block's contents.

CLI Features

The cli.go file provides a command-line interface to interact with the blockchain.

Commands:

  • Get Balance
    getbalance -address ADDRESS
    

Fetch the balance for the given address.

  • Create Blockchain
    createblockchain -address ADDRESS
    

Initializes a new blockchain and rewards the address with the genesis block.

  • Print Blockchain
    printchain
    

Prints all blocks in the blockchain.

  • Send Coins
    send -from FROM -to TO -amount AMOUNT
    

Creates a transaction and mines a new block.

  • Create Wallet
    createwallet
    

Generates a new wallet and address.

  • List Addresses
    listaddresses
    

Lists all addresses stored in the wallet.

Getting Started

Prerequisites

  • Go programming language installed (version 1.19 or later recommended).

Installation

  1. Clone the repository:
    git clone https://github.com/ayushn2/blockchainx.git  
    cd blockchainx
    
  2. Build the project:
    go build
    

Running the CLI

  • Start the CLI:
    go run main.go COMMAND [OPTIONS]
    

Replace COMMAND with one of the CLI commands mentioned above.

Example Commands

  1. Create a Blockchain:
    go run main.go createblockchain -address your-address
    
  2. Print the Blockchain:
    go run main.go printchain
    
  3. Send Coins:
    go run main.go send -from sender-address -to receiver-address -amount 10
    
  4. Get Balance:
    go run main.go getbalance -address your-address
    
  5. Create a Wallet:
    go run main.go createwallet
    
  6. List Addresses:
    go run main.go listaddresses  
    

To Do

  • Implement a peer-to-peer network.
  • Enhance transaction validation.
  • Add a smart contract-like feature for custom logic.

Contributing

Contributions are welcome! Feel free to submit issues or pull requests.

About

This repository features a blockchain implementation in Go, utilizing the UTXO (Unspent Transaction Output) model. The project currently supports basic transactions and wallet functionality, laying the groundwork for a decentralized cryptocurrency system.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published