Skip to content

A blockchain implementation to understand and learn more about blockchain development

Notifications You must be signed in to change notification settings

prnvbn/go-blockchain

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

70 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Go Blockchain: A Learning Adventure

A command-line interface for a simple blockchain module in Go.

A commandline interface for a simple blockchain module in Go. This project is an academic pursuit of mine to learn more about blockchain and implement one on myself. The charts folder has some great diagrams that can be used to understand certain concepts of blockchain.

This module uses SHA256 hashing and so obviously should not be used for sensitive data (SHA256 can be cracked with relative ease). The module uses BadgerDB to store the blockchain and ensure persistance.

Transactions

As of now, 1 block can only have 1 transaction because the mining of the block is synchronous with the sending of a transaction. Each block has an input and an output. The input stores an unhashed public key and a signature of the entire transaction and the output stores a hashed public key. So to access the unspent tokens in the output, the hash of the public key in the input has to match the hashed public key in the output. You can see the flowchart of an example transaction here

CLI

There is a simple commandline application showing the module can be used. You can run it using go run main.go (flags). See Usage to learn about the flags.

Usage

  1. printchain Prints all the blocks in the chain
  2. getbalance -address ADDRESS gets the balance for a given address
  3. createblockchain -address ADDRESS creates a blockchain
  4. send -from FROM -to TO -amount -AMOUNT makes a transaction
  5. createwallet - Creates a new Wallet
  6. listaddresses - Lists the addresses in our wallet file

Demo

I am assuming you have go properly installed on your machine.

With wallets

Creating 2 wallets Screenshot from 2021-06-13 16-39-21

Mining the genesis block (Output is -1 for for the coinbase transaction) Screenshot from 2021-06-13 16-39-41

Making a transaction Screenshot from 2021-06-13 16-55-13

Without wallets

First, we created the blockchain by proving the genesis block and subsequently having a coinbase transaction mining it. After this step, the balance at address "Pranav" is 100 (value of the coinbase transaction). Then we make a transaction from address "Pranav" to address "Manya". This first created an address "Manya" and then completed the transaction. We can see that it was succesful and that the blockchain is still valid after it.

image

If you find any issues, typos, errors or have any feature requests, feel free to create an issue or a pull request :)

Features

  • Persistance
  • Transactions
  • Consensus Algorithm
  • Wallet Module
  • Integrate wallet Module and the blockchain
  • Digital Signatures
  • Merkle Tree
  • Dynamic Difficulty
  • Improve the CLI Package

Being added with wallets. image

About

A blockchain implementation to understand and learn more about blockchain development

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages