create account

Creating a toy cryptocurrency - Part 1 by garethnelsonuk

View this thread on: hive.blogpeakd.comecency.com
· @garethnelsonuk ·
$5.71
Creating a toy cryptocurrency - Part 1
# Creating a toy cryptocurrency - part 1

Hi everyone and welcome to a series of posts aimed at explaining cryptocurrencies by building one. The end result is intended to be a new altcoin that isn't of much use beyond education - though you are of course welcome to build it and try and turn it into something useful. To understand this series of articles you should be familiar with programming in python as well as having some basic understanding of cryptography and networking.

In this first article i'll go over a summary of what components a blockchain-based cryptocurrency requires, for the next articles in the series i'll show how to build each component and eventually how it all fits together. So without further ado, here's the basic parts:

## A P2P communications network
One of the defining things about cryptocurrencies is they are decentralised - anyone can run the software and start using them. This requires a method of communicating between nodes without relying on central servers to keep the network going, or in other words a peer-to-peer (P2P) network.
There are many approaches to building a P2P network as well as various approaches to seeding the network (establishing first contact with other nodes). I'll discuss some of the approaches and then settle on what I personally have chosen for my own experiments.

## Proof of work for verification - miners and mining
When you go to a traditional bank and withdraw cash you are given physical coins and notes. These coins and notes are produced by a mint somewhere run by a government and they are designed to be difficult to forge. In the cryptocurrency space we use mining to produce our currency and instead of a government-run mint, miners are computers owned by anyone who is willing to invest the time and hardware.
In order to prevent forgery of our cryptocurrency we need to use a form of mathematical verification known as a proof of work - this is essentially a complex operation that is difficult to repeat and easy to verify the results of. In the proof of work article I will go over this in depth and explore different options for proof of work (as well as touching lightly on alternative systems such as proof of stake) and implement a very simplistic proof of work algorithm for our own toy currency.

## Blockchain storage
The actual transactions in a cryptocurrency are stored in blocks that are verified by miners. These blocks need to be stored on disk somewhere AND must be distributed across the P2P network. This is a deceptively simple sounding and very important task. Our cryptocurrency must ensure that only one valid blockchain exists and take care of forks and blockchain reorganisations. For the toy currency, we will implement a very simple longest chain wins system and I will explore various formats for physical storage on disk.
Remember, we need to be able to lookup data from the blockchain in order to perform transactions and to verify them, making the problem of storage a more complex one than it first appears. If you're familiar with relational database theory then you should instantly think of indexing.

## Electronic signatures
In order to spend a cryptocurrency you basically send a message out saying you're spending it and sign that message. This is what a transaction is. There are multiple ways to create electronic signatures that are useful for cryptocurrency transactions, but the basic theory is it should be possible to verify the transaction as valid without needing the private key of the sender. Miners will check the signatures before storing a transaction in a block, and all nodes when receiving funds will check the transaction signature too in order to make sure it is valid. The signature algorithm also needs to be strong against any attacks - if an attacker can alter the message while keeping a valid signature, the signature algorithm is useless.

## Private key storage and wallets
Finally we get to the bit most end users actually see - wallets and private keys. In this final article i'll look at implementing a simple wallet and generating and storing private keys. I'll also look at how to expand this with deterministic wallets and keys generated from arbitary passphrases (so-called "brain wallets"). After this article, we should have a complete cryptocurrency capable of being mined and sent between users.

## Last thoughts
If you find these articles useful please upvote them and feel free to tip me either here on steem or via bitcoin at 14vL5HUzqTLfFv9Pf9Vy7naKhJb35HQ6Mn
👍  , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , and 28 others
properties (23)
authorgarethnelsonuk
permlinkcreating-a-toy-cryptocurrency-part-1
categorycryptocurrency
json_metadata{"tags":["cryptocurrency","money","coding","tutorials"]}
created2016-09-24 00:06:00
last_update2016-09-24 00:06:00
depth0
children10
last_payout2016-10-25 10:03:21
cashout_time1969-12-31 23:59:59
total_payout_value4.836 HBD
curator_payout_value0.870 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length4,529
author_reputation9,564,384,386,809
root_title"Creating a toy cryptocurrency - Part 1"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd0
post_id1,342,912
net_rshares10,305,611,841,691
author_curate_reward""
vote details (92)
@dcomxv1 ·
The idea and the future posts have me very interested.  I found this post from your part 2 and going to follow just to see how you make out.  With your alt coin, have you a name yet?
properties (22)
authordcomxv1
permlinkre-garethnelsonuk-creating-a-toy-cryptocurrency-part-1-20161002t194145668z
categorycryptocurrency
json_metadata{"tags":["cryptocurrency"]}
created2016-10-02 19:41:45
last_update2016-10-02 19:41:45
depth1
children1
last_payout2016-10-25 10:03:21
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length182
author_reputation5,552,960,738
root_title"Creating a toy cryptocurrency - Part 1"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id1,424,694
net_rshares0
@garethnelsonuk ·
This series of mine is not intended to build a stable and reliable altcoin - if people reading want to do so then I encourage them to take the lessons learnt and build something reliable on top, but I actively discourage trying to take this code and directly use it for anything beyond education.

With that in mind, I haven't bothered to name the coin being built - but it could be cool to give it a name if you've got any suggestions.
properties (22)
authorgarethnelsonuk
permlinkre-dcomxv1-re-garethnelsonuk-creating-a-toy-cryptocurrency-part-1-20161002t195233366z
categorycryptocurrency
json_metadata{"tags":["cryptocurrency"]}
created2016-10-02 19:52:33
last_update2016-10-02 19:52:33
depth2
children0
last_payout2016-10-25 10:03:21
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length436
author_reputation9,564,384,386,809
root_title"Creating a toy cryptocurrency - Part 1"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id1,424,786
net_rshares0
@geke · (edited)
I'm gonna show this to both my boys and look forward to the rest of this series. Also, resteeming.
properties (22)
authorgeke
permlinkre-garethnelsonuk-creating-a-toy-cryptocurrency-part-1-20160924t003643905z
categorycryptocurrency
json_metadata{"tags":["cryptocurrency"]}
created2016-09-24 00:36:45
last_update2016-09-24 00:46:06
depth1
children3
last_payout2016-10-25 10:03:21
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length98
author_reputation113,100,696,967,033
root_title"Creating a toy cryptocurrency - Part 1"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id1,343,100
net_rshares0
@garethnelsonuk ·
Thanks for the resteem :)
Next part will be up later today or tomorrow
properties (22)
authorgarethnelsonuk
permlinkre-geke-re-garethnelsonuk-creating-a-toy-cryptocurrency-part-1-20160924t034950324z
categorycryptocurrency
json_metadata{"tags":["cryptocurrency"]}
created2016-09-24 03:49:51
last_update2016-09-24 03:49:51
depth2
children0
last_payout2016-10-25 10:03:21
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length70
author_reputation9,564,384,386,809
root_title"Creating a toy cryptocurrency - Part 1"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id1,343,968
net_rshares0
@garethnelsonuk ·
Due to size I had to split this  in 2, but here's part 2a:
https://steemit.com/cryptocurrency/@garethnelsonuk/creating-a-toy-cryptocurrency-part-2a-p2p-networking
properties (22)
authorgarethnelsonuk
permlinkre-geke-re-garethnelsonuk-creating-a-toy-cryptocurrency-part-1-20160924t052323075z
categorycryptocurrency
json_metadata{"tags":["cryptocurrency"],"links":["https://steemit.com/cryptocurrency/@garethnelsonuk/creating-a-toy-cryptocurrency-part-2a-p2p-networking"]}
created2016-09-24 05:23:21
last_update2016-09-24 05:23:21
depth2
children1
last_payout2016-10-25 10:03:21
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length162
author_reputation9,564,384,386,809
root_title"Creating a toy cryptocurrency - Part 1"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id1,344,410
net_rshares0
@geke ·
Awesome!
properties (22)
authorgeke
permlinkre-garethnelsonuk-re-geke-re-garethnelsonuk-creating-a-toy-cryptocurrency-part-1-20160924t120909978z
categorycryptocurrency
json_metadata{"tags":["cryptocurrency"]}
created2016-09-24 12:09:12
last_update2016-09-24 12:09:12
depth3
children0
last_payout2016-10-25 10:03:21
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length8
author_reputation113,100,696,967,033
root_title"Creating a toy cryptocurrency - Part 1"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id1,346,270
net_rshares0
@jacobcards ·
Good format/guide on staring a crypto. If crypto is ever introduce into high schools this would be a great introduction. Im going to follow you to stay up on your posts please do the same for me and see some of the cryptos I've been recently paying attention to.
properties (22)
authorjacobcards
permlinkre-garethnelsonuk-creating-a-toy-cryptocurrency-part-1-20160924t001424647z
categorycryptocurrency
json_metadata{"tags":["cryptocurrency"]}
created2016-09-24 00:14:27
last_update2016-09-24 00:14:27
depth1
children0
last_payout2016-10-25 10:03:21
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length262
author_reputation48,954,175,480,649
root_title"Creating a toy cryptocurrency - Part 1"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id1,342,973
net_rshares0
@theprophet0 ·
Really looking forward to this, my main goal is to create a cryptocurrency and I swear to you, this will def help me accomplish my goal! :)
properties (22)
authortheprophet0
permlinkre-garethnelsonuk-creating-a-toy-cryptocurrency-part-1-20160926t205227843z
categorycryptocurrency
json_metadata{"tags":["cryptocurrency"]}
created2016-09-26 20:52:18
last_update2016-09-26 20:52:18
depth1
children1
last_payout2016-10-25 10:03:21
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length139
author_reputation42,005,134,378,165
root_title"Creating a toy cryptocurrency - Part 1"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id1,369,299
net_rshares0
@garethnelsonuk ·
Glad to hear - the next part will be coming soon, though I should warn you to do a lot more of your own research - this series of mine really is about building a TOY and not a real useful cryptocurrency - it's intended to help people understand how cryptocurrencies work through building one.
👍  
properties (23)
authorgarethnelsonuk
permlinkre-theprophet0-re-garethnelsonuk-creating-a-toy-cryptocurrency-part-1-20160927t042856022z
categorycryptocurrency
json_metadata{"tags":["cryptocurrency"]}
created2016-09-27 04:28:54
last_update2016-09-27 04:28:54
depth2
children0
last_payout2016-10-25 10:03:21
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length292
author_reputation9,564,384,386,809
root_title"Creating a toy cryptocurrency - Part 1"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id1,372,360
net_rshares15,863,253,845
author_curate_reward""
vote details (1)
@uwe69 ·
Upvoted. Please vote in the lottery of herbert müller. You can then also win Steem Power.
https://steemit.com/deutsch/@herbertmueller/4-week-steemit-lottery-3-vote-to-win-steem-power-vote-um-steem-power-zu-gewinnen
properties (22)
authoruwe69
permlinkre-garethnelsonuk-creating-a-toy-cryptocurrency-part-1-20160924t083837683z
categorycryptocurrency
json_metadata{"tags":["cryptocurrency"],"links":["https://steemit.com/deutsch/@herbertmueller/4-week-steemit-lottery-3-vote-to-win-steem-power-vote-um-steem-power-zu-gewinnen"]}
created2016-09-24 08:38:36
last_update2016-09-24 08:38:36
depth1
children0
last_payout2016-10-25 10:03:21
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length214
author_reputation35,524,530,484,330
root_title"Creating a toy cryptocurrency - Part 1"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id1,345,321
net_rshares0