Giter VIP home page Giter VIP logo

gochain's Introduction

gochain

gochain is a proof-of-work blockchain written in go.

Features

  • Proof-Of-Work
  • Persistence
  • CLI
  • Transactions
  • Addresses
  • Merkle Tree
  • Network

How to run the gochain network

First, set NODE_ID to 3000 (export NODE_ID=3000) in the first terminal window. Create a wallet and a new blockchain on the NODE 3000 terminal:

$ go run .createblockchain -address <address3000>

After that, the blockchain will contain only the genesis block. We need to save the block and use it in other nodes.

$ cp blockchain_3000.db blockchain_genesis.db 

Next, open a new terminal window of your second Node and set node ID to 3001. This will be a wallet node. Generate some addresses with go run .createwallet.

Back to the first window send some coins to the wallet addresses:

$ go run . send -from <address3000> -to <address3001> -amount 10 -mine

-mine flag means that the block will be immediately mined by the same node.

Start the node:

$ go run . startnode

The node must be running until the end of the scenario.

Start the blockchain of NODE 3001 with the genesis block saved above:

$ cp blockchain_genesis.db blockchain_3001.db

Run the node:

$ go run . startnode

It'll download all the blocks from the 3000 node. To check that everything's ok, stop the node and check the balances:

$ go run . getbalance -address <address3001>
Balance of '<address3001>': 10

Also, you can check the balance of the NODE 3000 address, because the node 3001 now has its blockchain:

$ go run . getbalance -address <address3000>
Balance of '<address3000>': 10

Open a new terminal window and set its ID to 3002, and generate a wallet. This will be a miner node. Initialize the blockchain:

$ cp blockchain_genesis.db blockchain_3002.db

And start the node:

$ go run . startnode -miner <address3002>

Send some coins from NODE 3001:

$ go run . send -from <address3001> -to <address3002> -amount 1
$ go run . send -from <address3001> -to <address3000> -amount 1

Quickly! Switch to the miner node 3002 and see it mining a new block! Also, check the output of the central node.

Switch to the node 3001 and start it:

$ go run . startnode

It'll download the newly mined block!

Stop it and check balances:

$ go run . getbalance -address <address3001>
Balance of 'WALLET_1': 8

Research and ToDos

  • Target Adjusting Algorithm
  • Sharding
  • Test other consensus methods
  • Block Explorer (Web)

Ressources

Contact

gochain's People

Contributors

alichraghi avatar ampferl avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.