Skip to content

Get Started with BlockShell

Daxeel Soni edited this page Jan 28, 2018 · 5 revisions

๐Ÿ Introduction

Blockshell works on blockchain concepts and it creates a tiny blockchain in your local system. So, you will actually learn the concepts like blocks, mining, hashing, proof of work and lot more.

So, with blockshell you will be creating blocks with simple commands and rest of the tasks will be handled by Blockshell. In this wiki I will try to explain how Blockshell works behind every commands and how it is executing blockchain.

Let's get start!

๐Ÿ†• Initialize New Blockchain

First we will initialize the new blockchain with following command in blockshell CLI.

[BLOCKSHELL] $ blockshell init --difficulty 3

Above command initializes new blockchain and creates chain.txt in your working directory where our blockchain data will be stored. You can compare this chain.txt file as real world blockchain's ledger.

--difficulty number indicates the difficulty level for blockchain's proof of work. More the number, more time will be taken to mine new block in our blockchain.

In our blockchain we have Initial Zeros Proof of Work algorithm. So, when we want to mine new block, our PoW will look for the hash that has the initial 3 characters are zeros(0) as right now our blockchain's difficulty level is set to 3 at the time of initialization.

Eg. hash

0002fdd96ffec46277a753fa983773599c816dcf100c956afae0a4853fd1ce32

โ›๏ธ Mine First Block

Let's store some data and Mine very first block of our blockchain by doing PoW.

[BlockShell] $ dotx hello blockchain

Blockshell comes with build-in command dotx which is used to create a new transaction and this will mine new block with given data (eg. hello blockchain)

Output

[Status] Mining block (1) with PoW ...
[ Info ] Time Elapsed : 0.0164740085602 seconds.
[ Info ] Mined Hash : 000eea381e45c9f6c1c330cf991b5b1e7d15f739da3894b703e412881b2c2edd

Mining this block will depend on the difficulty level of the blockchain. Right now difficulty is of 3 and thats why our block mined in less than a second. After mining action, we received hash of that block with 3 initials as zero as difficulty is 3.

๐Ÿ“ฆ Genesis Blocks

First block in blockchain is known as Genesis block and which is created manually at the time of blockchain development. In our case, creation of this genesis block is handled by Blockshell. When we initialized the blockchain, it also created genesis block. Lets check this out.

๐Ÿ•ธ๏ธ Explore Blockchain

Now, we have 2 blocks in our blockchain. First is genesis block and other we created in previous step and that contains data hello blockchain

List all blocks in blockchain with following command

[BlockShell] $ allblocks

This lists hashes of all the blocks. Output

338a2d1ac1b8135283ae19a304b2b426b69b9caba7ef462f246fc577a0297230
000eea381e45c9f6c1c330cf991b5b1e7d15f739da3894b703e412881b2c2edd

โ„น๏ธ View Block Data

Let's check what's inside each block. For this Blockshell has getblock command.

Here, 338a2d1ac1b8135283ae19a304b2b426b69b9caba7ef462f246fc577a0297230 is genesis block. Let's look inside our genesis block

[BlockShell] $ getblock 338a2d1ac1b8135283ae19a304b2b426b69b9caba7ef462f246fc577a0297230

Output

{
	'nonce': 0,
	'index': 0,
	'hash': '338a2d1ac1b8135283ae19a304b2b426b69b9caba7ef462f246fc577a0297230',
	'previousHash': '',
	'timestamp': '2018-01-27 20:13:44.835930',
	'data': 'Genesis Block'
}

Similarly, let's check what's inside our own created block.

[BlockShell] $ getblock 000eea381e45c9f6c1c330cf991b5b1e7d15f739da3894b703e412881b2c2edd

Output

{
	'nonce': 1959,
	'index': 1,
	'hash': '000eea381e45c9f6c1c330cf991b5b1e7d15f739da3894b703e412881b2c2edd',
	'previousHash': '338a2d1ac1b8135283ae19a304b2b426b69b9caba7ef462f246fc577a0297230',
	'timestamp': '2018-01-27 20:15:01.515716',
	'data': 'hello blockchain'
}

๐ŸŒ Launch Blockshell Web

Blockshell comes with built-in Blockchain web explorer. You can search blocks and data in your blockchain from your web browser.

Open new terminal, go to cloned Blockshell directory and run web.py python script.

python web.py

Go to localhost 127.0.0.1:5000 in browser and give it a shot!