Devs-Not-Wizards / Blockchain_in_GO

The Aim of The Project is to provide a Visual Simualtion of Blockchain World for those who are new to this Technology

Home Page:https://blockchaingo.herokuapp.com/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Blockchain Demo in GOLANG

The Aim of The Project is to provide a Visual Simualtion of Blockchain World for those who are new to this Technology

alt text alt text alt text alt text alt text alt text alt text

Blockchain In GOLANG

Live Demo

Checkout the live demo here

  • The Webapp may take 20 -30 sec to Load
  • Prefer Desktop to access the website

https://blockchaingo.herokuapp.com/

alt text

alt text

Running Locally

Make sure you have Go version 1.12 or newer.

$ git clone https://github.com/atharvau/Blockchain_in_GO
$ cd Blockchain_in_GO
$ go get -u github.com/gin-gonic/gin
$ go build Main.go 

Your app should now be running on localhost:2222.

Introduction

Blockchain in GoLang is a Golang Project which consists simualtion of two blockchains

  • Simple Blockchain
  • Crypto Blockchain

It gives visual feel of the blockchain data structure to easly understand the concepts. Features of the blockchain are

Blockchain Consensus Algorithm Stored Data
Simple Proof-of-Work String Data
Crypto Proof-of-Work Transaction Data

An awesome project.

Technical Details

Technology

  1. BackEnd : GOLANG-Gin
  2. FrontEnd : HTML CSS Jquery
  3. Deployement :Heroku

Directory Structure

project
│   README.md
│   main.go   
│   Procfile
│   app.json
│   heroku.yml             
└───folder1
   a.html  
   index.html
   crypto.html
   index.css

The main.go is the Main file which has implementation of Blockchain and a server to serve It. The Template Folder Consists of All Front End Html Css And JS files required in Front End The Remaining files in root directory are autogenrated deployement files required for hosting on Heroku

Code Structure

The main.go can be categorized into 1. blockchain implementaion 2.Server Code The Server Code consits typical GET Request and Responses for handling incoming requests from FrontEnd The Blockchain Implementation consists 2 Chains Structure

  1. Simple
  • Structure
type Block struct {
	PrevHash  string
	CurrHash  string
	Data      string
	Nonce     uint64
	Timestamp int64
	Index     uint64
	Validate  bool
}

  • Methods

func AddBlock(PrevHash string, Data string, blockchain []Block) []Block
func SetBlock(blockchain []Block, pos uint64, Data string) []Block 
func ReMine(blockchain []Block)
func ValidateChain(blockchain []Block) []Block
func ProofOfWork
func GetMD5Hash(text string) string


  1. Crypto
  • Structure
type CryptoBlock struct {
	PrevHash  string
	CurrHash  string
	Nonce     uint64
	Timestamp int64
	Index     uint64
	Validate  bool
	Data      TransInfo
}
type TransInfo struct {
	Sender  string
	Reciver string
	Amount  uint64
	Miner   string
}
type Wallet struct {
	Name    string
	Amount  uint64
	Address string
}


  • Methods
func CryptoAddBlock(Data TransInfo, Prevhash string, blockchain []CryptoBlock) []CryptoBlock 
func ProofOfWork2(str string) CryptoBlock 
func CryptoValidateChain(blockchain []CryptoBlock) []CryptoBlock 
func CryptoReMine(blockchain []CryptoBlock) 
func CryptoSetBlock(blockchain []CryptoBlock, pos uint64, Data TransInfo) []CryptoBlock 
func CryptoCalculate(blockchain []CryptoBlock) []Wallet

How To Use : Simple Blockchain

Add New Block

New Block Can be added by inputing a string and click add new data

alt text

Change Difficulty

Difficulty is a measure of how difficult it is to find a hash below a given target

alt text

Reset Blockchain

The Blockchain can be cleared easily cleared by clicking

alt text

Corrupting Blockchain

You can Change the contents of blockchain by inputing data and clicking Change Data Button It Corrupts the blockchain and display corrupted Chain in Red Color

alt text

How To Use : Crypto Blockchain

Wallets

The Crypto chain is provided with 3 default Wallets

Name Account Default CryptoCoin
Steve 0x111111 51
Mark 0x222222 51
Bill 0x333333 51

The Mining Reward is 1 CryptoCoin

Create New Transaction

  1. Select The Sender
  2. Select The Reciver
  3. Select The Miner
  4. Select the Amount to Transfer
  5. Select the Transfer button and wait till it mines new Block

alt text

Contributing

  • We're are open to enhancements & bug-fixes.
  • Feel free to add issues and submit patches.

About

The Aim of The Project is to provide a Visual Simualtion of Blockchain World for those who are new to this Technology

https://blockchaingo.herokuapp.com/


Languages

Language:HTML 56.7%Language:JavaScript 29.5%Language:Go 12.4%Language:CSS 1.5%