First of all, I assume that you know what Ethereum and Blockchain are, and what Smart Contract stands for. In other words, you are not an absolute beginner.
To put it brief, this tutorial is for someone who knows how to write programs (C++ to Java Script, anything will do) and wants to begin writing Smart Contracts using Solidity.
Solidity, by the way, is a programming language, and knowing its basics is a plus. It is not mandatory though, as I am going to explain language features I use, and they are similar enough to features of other programming languages.
So, if I expect you to know programming and to be familiar with Solidity, why bother reading this book? What is it in there that you do not know already? Very simple. See, knowing a language does not necessarily mean that you are able to write a program on it. Do you have developer's tools installed? Do you know WHICH tools you need? Do you know how to test your program without spending ether (which means testing it in some kind of a sand box, not on the "real" network)?
Of course, there are tutorials around. But if you take an average tutorial from the net, you will see that "you will need Geth and for your convenience we'll use Truffle, and by the way, are you familiar with Remix?" And now you are lost.
To make things worse, Ethereum folks do not bother with dates. Not always, but as a genegal rule: you may read a nice tutorial, just to follow the "download" link at the end of the text, to a "Sorry, this tool is no longer supported" page.
So I put together a tutorial that takes you from zero ground and guides you all the way till you have your smart contract a) working, b) error-checked and c) with nice Web UI, so that your customers can enjoy the user experience, rather than learning command-line tools.
If you look at the Tutorial's contents, you will see the steps, so I'll just explain them, briefly.
This chapter provides you with simple (probably, simplest possible) steps to set up a private block chain using Geth (a command line tool that will run in the background) and Mist (a Wallet app you will use to "talk" to the block chain most if the time).
Private network runs on your computer, so you do not have to pay for transaction, also it is very fast.
Mist comes with its own Geth, so we are not going to install it. Instead, we start it from where Mist installed it. However, a default folder Mist's geth puts the block chain files is one of the worse imaginable choices (if you are under Windows) - it places it on C: disk, deep in "Users..." folder. While you would probably like to keep it some place safe: either on removable disk or in an encrypted disk. In this chapter we will discuss how to do it.
As expected, your first smart contract is called "Hello. World!" You will write it on Solidity, check it for errors and deploy to a private network.
A remake of a well-known "King of Ether" contract, it is a simple auction allowing people to pay for the right to take the "throne". Each payment should be larger than the previous one, as it should be in any auction. When you pay, the previous Duke gets a refund, however, he/she gets YOUR money; in other words, a refund is larger then the original payment. It is a good way to earn some extra ethers, however (as in any pyramid scheme, for that mater) there is a risk that the payment required grows so large that there will never be the next Duke.
Using the "Duke" contract, we are going to walk through some simple pitfalls one can experience while doing the block chain programming. We are going to break our contract, as a hacker would do; then we'll fix the problem. It should be mentioned, that this is only one example of how code vulnerabilities can be explored; you will find more of those in the tutorial, as I find in more convenient to explain a problem on the spot, rather than moving them all in a separate chapter.
A new, improved "Duke of Ether" contract: we are going to look at it from the point of viev of potential profitability.
Using smart contracts the way we did it so far, via Geth and Ether, is ok for a programmer. However, the user would expect a UI of some kind; in other words, a contract should have look and feel of a Web site, with all its decorations and other nice features.
This requirement is handled by allowing a contract to be called from HTML, via some data exchange protocol. We are going to use web3.js library: it allows your Web browser to "talk" to Geth, exchanging the data. As the result, we have a nearly ideal situation: Geth handles block chain data exchange, while a browser does what it is good at: showing the User Interface.
A slightly more advanced UI, with additional features. It should be noted, that modern HTML5 is very powerful, which allows people to create code that is impossible to understand. I am trying to keep complexity to a reasonable minimum, showing only what is required: working with smart contract's functions and handling contract's events. However, being a human, I couldn't stop, so you will also find some charts that were, probably, not absolutely required.
Some additional philosophy wrapped around a simple question: how do we profit from the contract? A smart contract is considered to be an LLC, an entity capable of performing certain work (in exchange for clients' money) and paying some of that money to its owners. So in addition to a direct "I charge you a small percent" approach the "Duke of Ether" uses, we will introduce a slightly different approach: a contract (aka "company" that shares its profits with share sholders in exchange for advertizing its services.
Note that it is not a "token", we are going to discuss tokens and ICO in a separate chapter. During an ICO (stands for Initial Coin Offering) a person pays for a certain amount of "tokens". The process is nothing but a fund rising, and there is no guarantee that there will be any profit: tokens are traded at a market price and can go down.
The shares we discuss are different: there is a guarantee of a profit, and the more active share holders are, informing their friends about the service, the more profit they receive. In other words, ICO is a crowd funding that (in its simple form) is not connected to a profit of a contract. It may depend on the profit of the company that issued tokens, but the process is not DIRECT. While in case of share holding, profit of the contract is being distributed among share holders by the smart contract itself, so there is no room for cheating.
A contract implementing share holding. A share holder receives a profit that is proportional to contract's profit. A share's price depends on the contract's profitability, so you can buy it, wait for some profit to add to the price and sell it for more.
An even more advancer Web UI example. On this Web page I am using contract's events (explained in Tutorial) to present data in the form of charts and tables. All done in Java Script in a reasonably simple way.
If you look at the code of contracts that are already in the block chain, you can see that they often use same parent classes: SafeMath, ERC20, Oraclize... I will BRIEFLY cover most important of those standard building blocks.
By this time we are going to have some contracts created. I am going to place them to the "real" block chain, just for the sake of an experiment. I am going to choose useful contracts.
A page of the "Duke" contract discussed above. For those who haven't read the tutorial yet: in order for this page to work, you need to have Geth running in the background, there is a small appendix in Setting up Private Block Chain chapter explaining how to connect to a real network, instead of the private one.
This is not a tutorial, but the real contract: feel free to play the "Game of Thrones"!
A page of the "ShareHolder" contract that is attached to the "Duke": whatever profit "Duke" makes, is distributed among share holders.
This is not a tutorial, but the real contract: read the rules and invest if you want!
A collection of links to my other sites. Please visit and do not forget to like them in the social networks: there are buttons on the bottom of each page.
I have couple of e.mail classes that are sent automatically upon subscription.