- Install Go in you machine.
- Install Code Editor VS CODE or IDE GO LAND
- Get Some Understanding of How Blockchain Works
- Below are some youtube video link will give you some context
- If you are new to Go language follow the Cheat Sheet. You will get some understanding of Go syntax.
$ git clone https://github.com/NearPrime/blockchain.git
$ cd blockchain
$ go mod init blockchain
$ go get golang.org/x/crypto/ripemd160
$ go get github.com/boltdb/bolt
$ go get github.com/stretchr/testify/assert
$ go build
Cheers!! You have done with your local setup. You are ready to play with your blockchain.
- Set NODE_ID to 3000
export NODE_ID=3000
in the first terminal window. - Open two more terminal and set the
NODE_ID
to 3001 & 3002. - Create a wallet and a new blockchain for
NODE 3000
blockchain createwallet
it will create a wallet and give you the wallet address.blockchain createblockchain -address CENTRAL_NODE
CENTRAL_NODE is address of wallet you just created.- After that, the blockchain will contain single genesis block. We need to save the block and use it in other nodes
cp blockchain_3000.db blockchain_genesis.db
- Go to the terminal
NODE 3001
. This will be a wallet node. Generate some addresses withblockchain createwallet
. Let's call them asWALLET_1
,WALLET_2
,WALLET_3
for shake of understanding. - On terminal
NODE 3000
. Let's send some coins to the wallet addresses. We have to have-mine
flag because initially there are no miner nodes in the network.$ blockchain send -from CENTRAL_NODE -to WALLET_1 -amount 10 -mine
$ blockchain send -from CENTRAL_NODE -to WALLET_2 -amount 10 -mine
- Start the node
blockchain startnode
. This node must be running until the end of the scenario.
- On terminal
NODE 3001
. Start the node’s blockchain with the genesis block saved abovecp blockchain_genesis.db blockchain_3001.db
.- Run the Node
blockchain startnode
It’ll download all the blocks from the central node. To check that everything’s ok, stop the node and check the balances. blockchain getbalance -address WALLET_1
it will returnBalance of 'WALLET_1': 10
blockchain getbalance -address WALLET_2
it will returnBalance of 'WALLET_2': 10
blockchain getbalance -address CENTRAL_NODE
you can check the balance of the CENTRAL_NODE address, because the node 3001 now has its blockchain.
- Run the Node
- On terminal
NODE 3002
. Generate a Walletblockchain createwallet
. This will be a miner node.- Initialize the blockchain:
cp blockchain_genesis.db blockchain_3002.db
- Start the node:
blockchain startnode -miner MINER_WALLET
- Initialize the blockchain:
- On terminal
NODE 3001
. Send some coins.blockchain send -from WALLET_1 -to WALLET_3 -amount 1
blockchain send -from WALLET_2 -to WALLET_4 -amount 1
- Quickly! Switch to the miner node
NODE 3002
and see it mining a new block! Also, check the output of the central node. - On terminal
NODE 3001
. Switch to the wallet node.- Start the wallet node:
blockchain startnode
. It’ll download the newly mined block. - Now stop the node and check the balances using
blockchain getbalance -address WALLET_1
- Start the wallet node:
blockchain listaddresses
You can get all the addresses.blockchain printchain
It will return the complete chain.
blockchain getbalance -address {WALLET_ADDRESS}
It will return the current balance of wallet.blockchain createblockchain -address {CENTRAL_NODE}
CENTRAL_NODE is wallet address. It will create blockchain.blockchain createwallet
it will create a wallet and returns the wallet address.blockchain listaddresses
it will list all wallet address available on blockchain.blockchain printchain
It will return the blockchain.blockchain send -from {WALLET_ADD_1} -to {WALLET_ADD_2} -amount {amount}
It will used to send the coins from one wallet to another.blockchain startnode
It will start the node. and download all the newly mined block.
- I've followed the below tutorial and the Blockchain Implementation is done as described in the following articles, It's good to follow if you want to get a good understanding of Code Base:*