Creating a toy cryptocurrency - Part 1steemCreated with Sketch.

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

Sort:  

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.

I'm gonna show this to both my boys and look forward to the rest of this series. Also, resteeming.

Thanks for the resteem :)
Next part will be up later today or tomorrow

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

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! :)

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.

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?

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.

Coin Marketplace

STEEM 0.19
TRX 0.14
JST 0.029
BTC 64781.14
ETH 3119.00
USDT 1.00
SBD 2.53