Skip to content

Multiple Node Blockchain Simulation with Mining and Wallet Module

Notifications You must be signed in to change notification settings

cnrdmrci/blockchain-app

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

37 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Usage

$ go run main.go
Usage:
  createwallet -----------------------------------> Create a new wallet
  listaddresses ----------------------------------> List wallet addressses
  createblockchain -address ADDRESS --------------> Create a blockchain and sends genesis reward to address
  updateblockchain -------------------------------> Update blockchain via other nodes
  printblockchain --------------------------------> Print the blocks in the blockchain
  printlastblock ---------------------------------> Print last block  
  removelastblock --------------------------------> Remove last block from the blockchain  
  getbalance -address ADDRESS --------------------> Get the balance for an address
  send -from FROM -to TO -amount AMOUNT -mine ----> Send amount of coins. Then -mine flag is set, mine off of this node
  reindexutxo ------------------------------------> Rebuilds the UTXO set
  startnode -miner ADDRESS -----------------------> Start a node with TxID specified in NODE_ID env. var. -miner enables mining

Create Wallet

Node 1

$ export NODE_ID=3000
$ go run main.go createwallet
New address is: 15uQXdzyY8Bki98UQgeXcLtXaDhW4szBjp

Node 2

$ export NODE_ID=4000
$ go run main.go createwallet
New address is: 14sLJH78gy27wSEaWDTHNrhUxLa3yXYVzS

Node 3

$ export NODE_ID=5000
$ go run main.go createwallet
New address is: 1NEnVj4RVVjjZjRqoXBBqoCV5BXneMo97S

Initialize Blockchain

Node 1

$ go run main.go createblockchain -address 14sLJH78gy27wSEaWDTHNrhUxLa3yXYVzS
Nonce found: 563481
Block Hash : 000000421470170d61f247b3b9e587debc37387b936fac018a474950a4ab8ad2
Genesis block created.

Print Blockchain

Node 1

$ go run main.go printblockchain
printblockchain

Get Wallet Balance and Check Reward

Node 1

$ go run main.go getbalance -address 14sLJH78gy27wSEaWDTHNrhUxLa3yXYVzS
Balance of 14sLJH78gy27wSEaWDTHNrhUxLa3yXYVzS: 20 

Start Full Node and Miner Node

Node 1

$ go run main.go startnode
fullnode

Node 3

$ go run main.go startnode -miner 1NEnVj4RVVjjZjRqoXBBqoCV5BXneMo97S
miner

Send Funds

Node 2

$ go run main.go updateblockchain
$ go run main.go send -from 14sLJH78gy27wSEaWDTHNrhUxLa3yXYVzS -to 15uQXdzyY8Bki98UQgeXcLtXaDhW4szBjp -amount 5
send

Node 1 (Full Node)

Screenshot 2024-07-25 at 22 26 46

Node 2 (Miner Node)

Screenshot 2024-07-25 at 22 27 51

Get Final Balances

Node 2

$ go run main.go updateblockchain
$ go run main.go getbalance -address 14sLJH78gy27wSEaWDTHNrhUxLa3yXYVzS
$ go run main.go getbalance -address 1NEnVj4RVVjjZjRqoXBBqoCV5BXneMo97S
$ go run main.go getbalance -address 15uQXdzyY8Bki98UQgeXcLtXaDhW4szBjp
Balance of 14sLJH78gy27wSEaWDTHNrhUxLa3yXYVzS: 15
Balance of 1NEnVj4RVVjjZjRqoXBBqoCV5BXneMo97S: 20 //Mining Reward
Balance of 15uQXdzyY8Bki98UQgeXcLtXaDhW4szBjp: 5

Get Final Blockchain

Node 2

$ go run main.go printblockchain
finalblockchain

About

Multiple Node Blockchain Simulation with Mining and Wallet Module

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages