Skip to content

Latest commit

 

History

History
120 lines (80 loc) · 2.38 KB

Readme.md

File metadata and controls

120 lines (80 loc) · 2.38 KB

Simple Blockchain

This repository contains the golang code of a simple blockchain implementation.

This blockchain consists of three parts:

  • A simple wallet that you can get address, scan utxos, sign transaction.
  • A simple blockchain can sync block from other known nodes, mining new block, send transaction and broadcast to other node.
  • A simple restful server you can query blocks and utxos from blockchain.

There are many part are not like real blockchain because it's just simple implementation, still insecure and incomplete. you can learn the basic operation of the blockchain through this project.

How to run

Build

go build ./cmd/cli

Create Wallet

./cli wallet create -walletname "alice"
./cli wallet create -walletname "bob"

Start two node

./cli server start -nodeport 3000 -apiport 8080 -walletname "alice" -ismining=true
./cli server start -nodeport 3001 -apiport 8081 -walletname "bob" -ismining=true

Mining empty block to get block reward

./cli server miningblock --apiport 8080

Send Transaction to other address

./cli server sendtransaction --apiport 8080 --to "172wJyiJZxXWyBW7CYSVddsR5e7ZMxtja9" -amount 100000

threr are still have other blockchain command, you can find out by type ./cli server.

Example

Create wallet

./cli wallet create -walletname "alice"

Start blockchain server

./cli server start -nodeport 3000 -apiport 8080 -walletname "alice" -ismining=true

Get blocks

./cli server getblocks -apiport 8080

Get block hashes

./cli server getblockhashes -apiport 8080

Get block height

./cli server getblockheight -apiport 8080

Get block utxos

./cli server getutxos -apiport 8080

Get wallet address

./cli server getwalletaddress -apiport 8080

Get wallet utxos

./cli server getwalletutxos -apiport 8080

Get wallet balance

./cli server getwalletbalance -apiport 8080

Send transaction

./cli server sendtransaction --apiport 8080 --to "172wJyiJZxXWyBW7CYSVddsR5e7ZMxtja9" -amount 100000

Mining block

./cli server miningblock -apiport 8080