The entire history of humanity is a continuous struggle to break free from chains and create new, even stronger ones. (Anonymous)
By analyzing numerous blockchain projects (Bitshares, Hyperledger, Exonum, Ethereum, Bitcoin, etc.), I realize that they are all built on the same principles from a technical standpoint. Blockchains can be likened to houses, which, despite their diverse structures, decorations, and purposes, share a foundation, walls, roofs, windows, and doors that are interconnected in specific ways. If one understands the basic principles of building design and knows the properties of the materials used, it becomes possible to determine the intended purpose of a particular house. Currently, with blockchain, there is a situation where everyone has heard of it, but few understand its architecture and operating principles. This leads to confusion about why and how it makes sense to use blockchain technologies.
In this article, we will explore the common properties and principles applicable to all blockchains. Next, we will examine the tasks that can be solved using blockchain, and to reinforce the material, we will build a small but real blockchain on our own virtual plot!
So, let's recall the problems that blockchain originally aimed to solve.
I am sure many will mention a distributed, decentralized, public, and immutable database. But why was all this necessary?
I prefer to start studying any technology with reading the standards, as all articles and books on the subject are based on them. However, as of now, there are no blockchain standards; only for their development have been created within ISO. Currently, each public blockchain project has its own White Paper, which essentially serves as a technical specification. The first well-known blockchain project is the Bitcoin network. Let's go to the official website of the network and how it all began.
The task of blockchain
So, the task that blockchain solved in the pioneering Bitcoin network is the trustworthy transfer of ownership of digital assets in an untrusted environment without intermediaries. For instance, in the Bitcoin network, the digital asset is the bitcoin currency. All technical solutions of Bitcoin and other blockchains are aimed at addressing this task.
Problems that blockchain solves
Suppose a certain financial organization claims it has built a network worldwide that allows money transfers to anyone. Would you believe it? If this organization is Visa or MasterCard, you probably would, but if it's, say, AnonymousWorldMoney, probably not. Why is that? Because we well know how distributed systems are constructed by private companies, for what purposes, and what they can lead to. Let's take a closer look at the issues such systems face and how they can be resolved using blockchain technology.
Let's assume that the hypothetical AnonymousWorldMoney has servers with databases, and it's good if there are several in different data centers. When the sender transfers money, a transaction is recorded, replicated across all servers, and the money reaches the recipient.

In an ideal world, such a scheme works perfectly; however, in our world, the following issues arise:
- The problem of identifying participants on one side and the need for anonymity in transactions on the other. That is, you need to transfer money to a specific recipient in a way that no one other than the transaction participants knows about it. Banks have account numbers and credit card numbers linked to a specific individual or legal entity, and banking secrecy protects information about transactions. But who guarantees that the hypothetical AnonymousWorldMoney does not use personal data and transaction information for its own purposes?
- How can you be sure that the recipient received exactly the amount that was sent to them? For instance, the sender transferred $100, but the recipient got $10. The sender visits the AnonymousWorldMoney office with their receipt, but the clerk shows their version, which states that the sender only transferred $10.
- The problem of a distrustful environment, such as fraud known as double-spending. An unscrupulous participant can spend their balance multiple times before the payment is replicated across all servers. of course, has not been canceled, and consistency will ultimately be achieved, but someone will not receive the money for the services or goods provided. Therefore, if there is no complete trust in the payment organization or transaction participants, one must build a network based not on trust, but on cryptography.
- The Conditional AnonymousWorldMoney has a finite number of servers that may become unavailable either inadvertently or maliciously.
- AnonymousWorldMoney will take its tangible commission.
- Management capability. During the operation of Bitcoin, it became clear that people want not only to transfer coins to each other but also to verify various conditions for transaction processing, program operation scenarios, and automatically perform actions based on conditions, etc.
How blockchain addresses these issues
- The identification of participants is carried out using a pair of keys: private and public, and the digital signature algorithm uniquely identifies the sender and recipient while keeping their identities anonymous.
- Transactions are gathered into blocks, and the hash of the block is calculated and recorded in the next block. This sequence of recording hashes in blocks gave its name to the technology blockchain and makes it impossible to alter or delete blocks or individual transactions within blocks unnoticed. Thus, once a transaction is in the blockchain, we can be confident that its data will remain unchanged.
- Double-spending fraud is prevented by achieving consensus in the network on which data to consider valid and which to discard. In the Bitcoin network, consensus is achieved through Proof-of-Work (PoW).
- The reliability of the network's operation is ensured by the fact that the blockchain is public, where each participant can run their node, obtain a full copy of the blockchain, and moreover, independently start verifying transactions for correctness. It is worth noting that modern blockchains allow for the creation of not only public (open) but also private (closed) blockchains, as well as using hybrid schemes.
- One cannot completely eliminate commissions in the blockchain, as it is necessary to pay the people maintaining the network, but in the blockchain, the necessity of the commission is proven so convincingly that there are no doubts about its necessity.
- Modern blockchains have the capability to implement business logic, referred to in the blockchain as Smart Contracts. The logic of smart contracts is implemented in various high-level programming languages.
Let's take a closer look at these solutions.
Blockchain architecture
Components of the blockchain
Each participant can run their own node with a complete copy of the blockchain (full node). The full nodes that can record transactions in the blockchain are called consensus nodes (witness) or miners (miner). Full nodes that only verify the correctness of transactions are called audit nodes (audit). Light clients (light clients) do not store full copies of the blockchain, but interact with the network using full nodes.
Most users for conducting transactions use light clients or web wallets. All nodes are interconnected. With this set of elements, the network architecture becomes more resilient:

Transaction Lifecycle
Let's look at the transaction lifecycle and break it down into parts:

Blockchain Technologies
Let’s focus more on the technical solutions and their connections with each other.
Identification
Every blockchain transaction must be signed with a digital signature. Therefore, to carry out a transaction, each participant must have a pair of keys: private/public. Sometimes this pair of keys is referred to as a wallet, as the keys are uniquely linked to the participant's digital address and balance. In reality, keys and addresses are simply strings of numbers in different numeral systems. Examples of keys and wallet addresses:
Private key: 0a78194a8a893b8baac7c09b6a4a4b4b161b2f80a126cbb79bde231a4567420f
Public key: 0579b478952214d7cddac32ac9dc522c821a4489bc10aac3a81b9d1cd7a92e57ba
Address: 0x3814JnJpGnt5tB2GD1qfKP709W3KbRdfb27VTo create a digital signature in blockchains, an algorithm based on elliptic curves is used: Elliptic Curve Digital Signature Algorithm (ECDSA). For this, a private key (256-bit number) is typically taken randomly. The number of key combinations is 2 to the power of 256, so we can say that it is practically impossible for private key values to collide.
Next, the public key is obtained from the private key by multiplying its value by the coordinates of a point on the elliptic curve, resulting in the coordinates of a new point on the same curve. This operation ensures the generation of a key pair suitable for digital signatures of transactions. Finally, the wallet address is uniquely computed from the public key.
There are many articles detailing the cryptography used in blockchain, for example:
The private key must be kept strictly confidential and stored securely. The public key is known to everyone. If the private key is lost, access to the asset (coins) cannot be restored and the money will be lost forever. Therefore, the task of securely storing private keys is extremely relevant, as it is not a bank where you can always come with your passport to recover your account. There is a whole industry dedicated to the production of so-called cold cryptocurrency wallets that resemble flash drives:

or you can use more secure methods, for example, engraving the private key value on tokens:

Transactions
More details about the transaction structure can be found in the article . It is important for us to understand that each transaction has at least the following data:
From: 0x48C89c341C5960Ca2Bf3732D6D8a0F4f89Cc4368 - digital address of the sender
To: 0x367adb7894334678b90аfe7882a5b06f7fbc783a - digital address of the recipient
Value: 0.0001 - transaction amount
Transaction Hash: 0x617ede331e8a99f46a363b32b239542bb4006e4fa9a2727a6636ffe3eb095cef - transaction hashThen the transaction is signed with the private key and sent out (see details on how the protocol works ) to all nodes in the blockchain, which check the transactions for validity. The algorithm for verifying transactions is non-trivial and includes .
Transaction Blocks
After verifying the validity of the transactions, the nodes form blocks from them. In addition to transactions, the block records the hash of the previous block, a number (Nonce counter), and the hash of the current block is computed using the SHA-256 algorithm. The hash must meet certain complexity conditions. For example, in the Bitcoin network, the hash difficulty is automatically adjusted every 2 weeks based on the network power so that a block is generated approximately every 10 minutes. The difficulty is determined by the following condition: the found hash must be less than a predetermined number. If this condition is not fulfilled, then 1 is added to Nonce, and the process of hash computation is repeated. The Nonce field is used for hash finding, as it is the only data in the block that can be changed; the rest must remain unchanged. A valid hash must have a certain number of leading zeros, for example, one of the actual hashes:
000000000000000000000bf03212e7dd1176f52f816fa395fc9b93c44bc11f91The successful finding of a hash serves as proof of work (Proof-of-Work, PoW) for Bitcoin or Ethereum networks. The process of finding hashes is called mining, analogous to gold prospecting. The name accurately reflects the essence of the process, as it involves simply trying different options, and if someone finds a suitable hash, it is indeed a stroke of luck. It's like finding a real gold nugget in tons of worthless rock. The current block reward is 12.5 BTC, and if you multiply that by Bitcoin's current rate of $3900, it amounts to over a kilogram of pure gold. There’s something to fight for!
After a hash is successfully found, both the block and the found hash are recorded in the blockchain as the next block. For more details on the structure of blocks, you can refer to the article , and below I will present a simplified diagram:

The blockchain starts with a block that does not yet have a hash of the previous block. There is only one such block in the blockchain, known as the Genesis block. Other blocks share the same structure and only differ in the number of transactions. You can view real transactions and blocks currently being created in Bitcoin or Ethereum in the .
The size of blocks in Bitcoin is limited to 1 MB, and with a minimal transaction size of about 200 bytes, a block can contain around 6000 transactions at most. This also explains Bitcoin's performance, which many mock: a block is generated approximately every 10 minutes * 60 seconds = 600 seconds, resulting in a formal performance of about 10 TPS. However, this isn't actual performance but rather a deliberately implemented operational algorithm. In Ethereum, to compete, they simply reduced the block generation time to 15 seconds, and performance formally skyrocketed. Therefore, in blockchains using PoW as a consensus mechanism, it is pointless to compare performance, as it directly depends on the difficulty of computing the hash, which can be set to any level.
Forks
What happens if, for example, several nodes find hashes that meet the difficulty requirements but are different in value (in other words, they reach different consensus) and write blocks to the blockchain? Let’s see how the blockchain protects against this situation. In this case, a so-called fork occurs, and the blockchain has two versions of the chain:

What happens next? Next, part of the network starts working on block N+2 from one chain, while another part works from the other:

One of these blocks will be found earlier and sent to the blockchain, and according to the rules, the blockchain must switch to the longer chain and cancel all transactions from the alternative block:

In this case, there may arise a situation where a participant's transaction was only in one of the forked blocks, which was then canceled. Therefore, to be sure that the necessary transaction has been recorded in the blockchain, there is a general recommendation — before trusting a transaction, it’s advisable to wait for a few more blocks to be added to the blockchain. Recommendations on how many blocks to wait vary for different blockchains. For example, for the Bitcoin network, the minimum is 2 blocks, while the maximum is 6.
The same picture with block forks will be observed during a so-called 51% attack — when a group of miners tries to grow an alternative chain of blocks to achieve the cancellation of the chain with their fraudulent transactions. Although currently, instead of fraud, it’s more profitable to spend their resources on honest mining.
Consensus
To write a block to the blockchain, the network must reach consensus. Let’s recall the task of achieving consensus in computer communication networks. The problem is formulated as the Byzantine Generals Problem BFT (). Leaving aside the colorful description of the issues faced by the Byzantine army, the question can be framed as follows: how can the nodes of the network come to a common result if some nodes of the network may intentionally distort it? Existing algorithms for solving the BFT problem show that the network can function correctly if the number of fraudsters is less than 1/3. Why wasn't BFT consensus applied in the Bitcoin network? Why was it necessary to use PoW? There are several reasons:
- BFT works well with a small fixed set of nodes, but in a public blockchain, the number of nodes is unpredictable and, moreover, nodes can be arbitrarily turned on and off.
- It is essential to motivate people to launch blockchain nodes. For this, people must receive rewards. In BFT, there is formally nothing to receive rewards for, while in PoW, it is intuitively clear what the reward is for: the electricity consumed by the processor while finding the hash of the block.
Besides PoW, there are several other consensus mechanisms used in modern blockchains, for example:
- PoS (Proof-of-Stake) — in the blockchain
- DPoS (Delegated Proof-of-Stake) — in the blockchain
- BFT modifications: SBFT (Simplified BFT) and PBFT (Practical BFT), for example, in the blockchain
Let's pause to discuss the PoS consensus, as PoS and its variants have gained the most popularity in private blockchains. Why specifically in private ones? On one hand, PoS characteristics are better compared to PoW, as achieving consensus requires fewer computational resources, which increases the speed of data recording in the blockchain. On the other hand, PoS has greater potential for fraud, so to neutralize this, all participants in the blockchain must be known.
PoS consensus is based on selecting a node that can record a block with transactions in the blockchain depending on the amount of funds in the account, or rather, not in the account but in collateral. That is, the more funds you have in collateral, the more likely the network will choose your node to record the block. The collateral will not be returned if the block turns out to be invalid. This is how fraud prevention is implemented. There are the following variations of PoS:
- Delegated PoS (DPoS) consensus divides participants into 'voting' and 'validating'. Coin holders (voting participants) delegate their right to verify and record transactions in the blockchain to other participants. Thus, validators perform all computational tasks and earn rewards for it, and the presence of voting participants ensures the integrity of the validators, as they can be replaced at any moment.
- LPoS (Leased Proof-of-Stake) consensus allows you to lease your funds to other nodes, giving them a better chance to verify blocks. Thus, you can earn commissions on transactions without participating in the actual transaction verification and block mining.
There are several other consensus mechanisms that have not yet gained widespread adoption; I will simply list them for information, and you can find an overview of the consensus algorithms, for example, in the article: .
- PoET (Proof-of-Elapsed Time)
- PoC (Proof-of-Capacity)
- PoB (Proof-of-Burn)
- PoWeight (Proof-of-Weight)
- PoA (Proof-of-Activity) — PoW + PoS
- PoI (Proof-of-Importance)
Reliability and Deployment Models of Blockchains
Public Blockchain
Durability Public or another name Permissionless Blockchain is achieved by allowing everyone to connect and view information or even add their own node, with trust built on PoW consensus.
Private Blockchain
Private or Private Permissioned Blockchain. In these blockchains, only a specific group of participants (organizations or individuals) has access to the information. Such blockchains are created by organizations to increase overall benefit or efficiency. Their reliability is ensured by the common goals of participants and consensus algorithms PoS and BFT.
Blockchain Consortium
There are Consortium or Public Permissioned Blockchain. These blockchains can be accessed by anyone for viewing, but participants can only add information or connect their node with the consent of other participants. Such blockchains are built by organizations to enhance trust from clients or consumers of products or society at large. Here, reliability is also achieved through the presence of trust between participants and the same consensus algorithms PoS and BFT.
Smart Contracts
In blockchains implemented after Bitcoin, the ability to execute smart contracts has been added to varying degrees. Essentially, a smart contract is a transaction that includes program code for execution. Smart contracts on the Ethereum network run in the EVM (Ethereum Virtual Machine). To initiate the execution of a smart contract, it must be explicitly triggered by another transaction, or preconditions for execution must be met. The results of executing a smart contract are also recorded on the blockchain. Obtaining data from outside the blockchain is possible but extremely limited.
What business logic can be implemented using a smart contract? In fact, there isn't much, for example, checking conditions based on blockchain data, changing ownership of digital assets according to these conditions, recording data in permanent storage within the blockchain. The logic is implemented in a special high-level language called Solidity.
A classic example of functionality realized using smart contracts is the issuance of tokens for conducting an ICO. For instance, I created a smart contract to issue a modest 500,000,000 AlexToken. According to holds
the source code of the smart contract in the Solidity language
pragma solidity ^0.4.23;
library SafeMath {
/**
* @dev Multiplies two numbers, throws on overflow.
**/
function mul(uint256 a, uint256 b) internal pure returns (uint256 c) {
if (a == 0) {
return 0;
}
c = a * b;
assert(c / a == b);
return c;
}
/**
* @dev Integer division of two numbers, truncating the quotient.
**/
function div(uint256 a, uint256 b) internal pure returns (uint256) {
// assert(b > 0); // Solidity automatically throws when dividing by 0
/**
* @title SafeMath
* @dev Math operations with safety checks that throw on error
*/
// uint256 c = a / b;
// assert(a == b * c + a % b); // There is no case in which this doesn't hold
return a / b;
}
/**
* @dev Subtracts two numbers, throws on overflow (i.e. if subtrahend is greater than minuend).
**/
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
assert(b <= a);
return a - b;
}
/**
* @dev Adds two numbers, throws on overflow.
**/
function add(uint256 a, uint256 b) internal pure returns (uint256 c) {
c = a + b;
assert(c >= a);
return c;
}
}
/**
* @title Ownable
* @dev The Ownable contract has an owner address, and provides basic authorization control
* functions, this simplifies the implementation of "user permissions".
**/
contract Ownable {
address public owner;
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
/**
* @dev The Ownable constructor sets the original `owner` of the contract to the sender account.
**/
constructor() public {
owner = msg.sender;
}
/**
* @dev Throws if called by any account other than the owner.
**/
modifier onlyOwner() {
require(msg.sender == owner);
_;
}
/**
* @dev Allows the current owner to transfer control of the contract to a newOwner.
* @param newOwner The address to transfer ownership to.
**/
function transferOwnership(address newOwner) public onlyOwner {
require(newOwner != address(0));
emit OwnershipTransferred(owner, newOwner);
owner = newOwner;
}
}
/**
* @title ERC20Basic interface
* @dev Basic ERC20 interface
**/
contract ERC20Basic {
function totalSupply() public view returns (uint256);
function balanceOf(address who) public view returns (uint256);
function transfer(address to, uint256 value) public returns (bool);
event Transfer(address indexed from, address indexed to, uint256 value);
}
/**
* @title ERC20 interface
* @dev see https://github.com/ethereum/EIPs/issues/20
**/
contract ERC20 is ERC20Basic {
function allowance(address owner, address spender) public view returns (uint256);
function transferFrom(address from, address to, uint256 value) public returns (bool);
function approve(address spender, uint256 value) public returns (bool);
event Approval(address indexed owner, address indexed spender, uint256 value);
}
/**
* @title Basic token
* @dev Basic version of StandardToken, with no allowances.
**/
contract BasicToken is ERC20Basic {
using SafeMath for uint256;
mapping(address => uint256) balances;
uint256 totalSupply_;
/**
* @dev total number of tokens in existence
**/
function totalSupply() public view returns (uint256) {
return totalSupply_;
}
/**
* @dev transfer token for a specified address
* @param _to The address to transfer to.
* @param _value The amount to be transferred.
**/
function transfer(address _to, uint256 _value) public returns (bool) {
require(_to != address(0));
require(_value <= balances[msg.sender]);
balances[msg.sender] = balances[msg.sender].sub(_value);
balances[_to] = balances[_to].add(_value);
emit Transfer(msg.sender, _to, _value);
return true;
}
/**
* @dev Gets the balance of the specified address.
* @param _owner The address to query the the balance of.
* @return An uint256 representing the amount owned by the passed address.
**/
function balanceOf(address _owner) public view returns (uint256) {
return balances[_owner];
}
}
contract StandardToken is ERC20, BasicToken {
mapping (address => mapping (address => uint256)) internal allowed;
/**
* @dev Transfer tokens from one address to another
* @param _from address The address which you want to send tokens from
* @param _to address The address which you want to transfer to
* @param _value uint256 the amount of tokens to be transferred
**/
function transferFrom(address _from, address _to, uint256 _value) public returns (bool) {
require(_to != address(0));
require(_value <= balances[_from]);
require(_value <= allowed[_from][msg.sender]);
balances[_from] = balances[_from].sub(_value);
balances[_to] = balances[_to].add(_value);
allowed[_from][msg.sender] = allowed[_from][msg.sender].sub(_value);
emit Transfer(_from, _to, _value);
return true;
}
/**
* @dev Approve the passed address to spend the specified amount of tokens on behalf of msg.sender.
*
* Beware that changing an allowance with this method brings the risk that someone may use both the old
* and the new allowance by unfortunate transaction ordering. One possible solution to mitigate this
* race condition is to first reduce the spender's allowance to 0 and set the desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
* @param _spender The address which will spend the funds.
* @param _value The amount of tokens to be spent.
**/
function approve(address _spender, uint256 _value) public returns (bool) {
allowed[msg.sender][_spender] = _value;
emit Approval(msg.sender, _spender, _value);
return true;
}
/**
* @dev Function to check the amount of tokens that an owner allowed to a spender.
* @param _owner address The address which owns the funds.
* @param _spender address The address which will spend the funds.
* @return A uint256 specifying the amount of tokens still available for the spender.
**/
function allowance(address _owner, address _spender) public view returns (uint256) {
return allowed[_owner][_spender];
}
/**
* @dev Increase the amount of tokens that an owner allowed to a spender.
*
* approve should be called when allowed[_spender] == 0. To increment
* allowed value is better to use this function to avoid 2 calls (and wait until
* the first transaction is mined)
* From MonolithDAO Token.sol
* @param _spender The address which will spend the funds.
* @param _addedValue The amount of tokens to increase the allowance by.
**/
function increaseApproval(address _spender, uint _addedValue) public returns (bool) {
allowed[msg.sender][_spender] = allowed[msg.sender][_spender].add(_addedValue);
emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]);
return true;
}
/**
* @dev Decrease the amount of tokens that an owner allowed to a spender.
*
* approve should be called when allowed[_spender] == 0. To decrement
* allowed value is better to use this function to avoid 2 calls (and wait until
* the first transaction is mined)
* From MonolithDAO Token.sol
* @param _spender The address which will spend the funds.
* @param _subtractedValue The amount of tokens to decrease the allowance by.
**/
function decreaseApproval(address _spender, uint _subtractedValue) public returns (bool) {
uint oldValue = allowed[msg.sender][_spender];
if (_subtractedValue > oldValue) {
allowed[msg.sender][_spender] = 0;
} else {
allowed[msg.sender][_spender] = oldValue.sub(_subtractedValue);
}
emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]);
return true;
}
}
/**
* @title Configurable
* @dev Configurable varriables of the contract
**/
contract Configurable {
uint256 public constant cap = 1000000000*10**18;
uint256 public constant basePrice = 100*10**18; // tokens per 1 ether
uint256 public tokensSold = 0;
uint256 public constant tokenReserve = 500000000*10**18;
uint256 public remainingTokens = 0;
}
/**
* @title CrowdsaleToken
* @dev Contract to preform crowd sale with token
**/
contract CrowdsaleToken is StandardToken, Configurable, Ownable {
/**
* @dev enum of current crowd sale state
**/
enum Stages {
none,
icoStart,
icoEnd
}
Stages currentStage;
/**
* @dev constructor of CrowdsaleToken
**/
constructor() public {
currentStage = Stages.none;
balances[owner] = balances[owner].add(tokenReserve);
totalSupply_ = totalSupply_.add(tokenReserve);
remainingTokens = cap;
emit Transfer(address(this), owner, tokenReserve);
}
/**
* @dev fallback function to send ether to for Crowd sale
**/
function () public payable {
require(currentStage == Stages.icoStart);
require(msg.value > 0);
require(remainingTokens > 0);
uint256 weiAmount = msg.value; // Calculate tokens to sell
uint256 tokens = weiAmount.mul(basePrice).div(1 ether);
uint256 returnWei = 0;
if(tokensSold.add(tokens) > cap){
uint256 newTokens = cap.sub(tokensSold);
uint256 newWei = newTokens.div(basePrice).mul(1 ether);
returnWei = weiAmount.sub(newWei);
weiAmount = newWei;
tokens = newTokens;
}
tokensSold = tokensSold.add(tokens); // Increment raised amount
remainingTokens = cap.sub(tokensSold);
if(returnWei > 0){
msg.sender.transfer(returnWei);
emit Transfer(address(this), msg.sender, returnWei);
}
balances[msg.sender] = balances[msg.sender].add(tokens);
emit Transfer(address(this), msg.sender, tokens);
totalSupply_ = totalSupply_.add(tokens);
owner.transfer(weiAmount);// Send money to owner
}
/**
* @dev startIco starts the public ICO
**/
function startIco() public onlyOwner {
require(currentStage != Stages.icoEnd);
currentStage = Stages.icoStart;
}
/**
* @dev endIco closes down the ICO
**/
function endIco() internal {
currentStage = Stages.icoEnd;
// Transfer any remaining tokens
if(remainingTokens > 0)
balances[owner] = balances[owner].add(remainingTokens);
// transfer any remaining ETH balance in the contract to the owner
owner.transfer(address(this).balance);
}
/**
* @dev finalizeIco closes down the ICO and sets needed varriables
**/
function finalizeIco() public onlyOwner {
require(currentStage != Stages.icoEnd);
endIco();
}
}
/**
* @title LavevelToken
* @dev Contract to create the Lavevel Token
**/
contract AlexToken is CrowdsaleToken {
string public constant name = "AlexToken";
string public constant symbol = "ALT";
uint32 public constant decimals = 18;
}and the binary representation as seen by the network
60806040526000600355600060045533600560006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055506000600560146101000a81548160ff021916908360028111156200006f57fe5b0217905550620001036b019d971e4fe8401e74000000600080600560009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020546200024a6401000000000262000b1d179091906401000000009004565b600080600560009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002081905550620001986b019d971e4fe8401e740000006001546200024a6401000000000262000b1d179091906401000000009004565b6001819055506b033b2e3c9fd0803ce8000000600481905550600560009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163073ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef6b019d971e4fe8401e740000006040518082815260200191505060405180910390a362000267565b600081830190508281101515156200025e57fe5b80905092915050565b611cb880620002776000396000f300608060405260043610610112576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff16806306fdde03146104c7578063095ea7b31461055757806318160ddd146105bc57806323b872dd146105e7578063313ce5671461066c578063355274ea146106a3578063518ab2a8146106ce57806366188463146106f957806370a082311461075e57806389311e6f146107b55780638da5cb5b146107cc578063903a3ef61461082357806395d89b411461083a578063a9059cbb146108ca578063bf5839031461092f578063c7876ea41461095a578063cbcb317114610985578063d73dd623146109b0578063dd62ed3e14610a15578063f2fde38b14610a8c575b60008060008060006001600281111561012757fe5b600560149054906101000a900460ff16600281111561014257fe5b14151561014e57600080fd5b60003411151561015d57600080fd5b600060045411151561016e57600080fd5b3494506101a7670de0b6b3a764000061019968056bc75e2d6310000088610acf90919063ffffffff16565b610b0790919063ffffffff16565b9350600092506b033b2e3c9fd0803ce80000006101cf85600354610b1d90919063ffffffff16565b111561024c576101f66003546b033b2e3c9fd0803ce8000000610b3990919063ffffffff16565b915061022e670de0b6b3a764000061022068056bc75e2d6310000085610b0790919063ffffffff16565b610acf90919063ffffffff16565b90506102438186610b3990919063ffffffff16565b92508094508193505b61026184600354610b1d90919063ffffffff16565b6003819055506102886003546b033b2e3c9fd0803ce8000000610b3990919063ffffffff16565b6004819055506000831115610344573373ffffffffffffffffffffffffffffffffffffffff166108fc849081150290604051600060405180830381858888f193505050501580156102dd573d6000803e3d6000fd5b503373ffffffffffffffffffffffffffffffffffffffff163073ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef856040518082815260200191505060405180910390a35b610395846000803373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054610b1d90919063ffffffff16565b6000803373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055503373ffffffffffffffffffffffffffffffffffffffff163073ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef866040518082815260200191505060405180910390a361045184600154610b1d90919063ffffffff16565b600181905550600560009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166108fc869081150290604051600060405180830381858888f193505050501580156104bf573d6000803e3d6000fd5b505050505050005b3480156104d357600080fd5b506104dc610b52565b6040518080602001828103825283818151815260200191508051906020019080838360005b8381101561051c578082015181840152602081019050610501565b50505050905090810190601f1680156105495780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b34801561056357600080fd5b506105a2600480360381019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919080359060200190929190505050610b8b565b604051808215151515815260200191505060405180910390f35b3480156105c857600080fd5b506105d1610c7d565b6040518082815260200191505060405180910390f35b3480156105f357600080fd5b50610652600480360381019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803573ffffffffffffffffffffffffffffffffffffffff16906020019092919080359060200190929190505050610c87565b604051808215151515815260200191505060405180910390f35b34801561067857600080fd5b50610681611041565b604051808263ffffffff1663ffffffff16815260200191505060405180910390f35b3480156106af57600080fd5b506106b8611046565b6040518082815260200191505060405180910390f35b3480156106da57600080fd5b506106e3611056565b6040518082815260200191505060405180910390f35b34801561070557600080fd5b50610744600480360381019080803573ffffffffffffffffffffffffffffffffffffffff1690602001909291908035906020019092919050505061105c565b604051808215151515815260200191505060405180910390f35b34801561076a57600080fd5b5061079f600480360381019080803573ffffffffffffffffffffffffffffffffffffffff1690602001909291905050506112ed565b6040518082815260200191505060405180910390f35b3480156107c157600080fd5b506107ca611335565b005b3480156107d857600080fd5b506107e16113eb565b604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b34801561082f57600080fd5b50610838611411565b005b34801561084657600080fd5b5061084f6114ab565b6040518080602001828103825283818151815260200191508051906020019080838360005b8381101561088f578082015181840152602081019050610874565b50505050905090810190601f1680156108bc5780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b3480156108d657600080fd5b50610915600480360381019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803590602001909291905050506114e4565b604051808215151515815260200191505060405180910390f35b34801561093b57600080fd5b50610944611703565b6040518082815260200191505060405180910390f35b34801561096657600080fd5b5061096f611709565b6040518082815260200191505060405180910390f35b34801561099157600080fd5b5061099a611716565b6040518082815260200191505060405180910390f35b3480156109bc57600080fd5b506109fb600480360381019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919080359060200190929190505050611726565b604051808215151515815260200191505060405180910390f35b348015610a2157600080fd5b50610a76600480360381019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050611922565b6040518082815260200191505060405180910390f35b348015610a9857600080fd5b50610acd600480360381019080803573ffffffffffffffffffffffffffffffffffffffff1690602001909291905050506119a9565b005b600080831415610ae25760009050610b01565b8183029050818382811515610af357fe5b04141515610afd57fe5b8090505b92915050565b60008183811515610b1457fe5b04905092915050565b60008183019050828110151515610b3057fe5b80905092915050565b6000828211151515610b4757fe5b818303905092915050565b6040805190810160405280600981526020017f416c6578546f6b656e000000000000000000000000000000000000000000000081525081565b600081600260003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508273ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925846040518082815260200191505060405180910390a36001905092915050565b6000600154905090565b60008073ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff1614151515610cc457600080fd5b6000808573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020548211151515610d1157600080fd5b600260008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020548211151515610d9c57600080fd5b610ded826000808773ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054610b3990919063ffffffff16565b6000808673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002081905550610e80826000808673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054610b1d90919063ffffffff16565b6000808573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002081905550610f5182600260008773ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054610b3990919063ffffffff16565b600260008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508273ffffffffffffffffffffffffffffffffffffffff168473ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef846040518082815260200191505060405180910390a3600190509392505050565b601281565b6b033b2e3c9fd0803ce800000081565b60035481565b600080600260003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205490508083111561116d576000600260003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002081905550611201565b6111808382610b3990919063ffffffff16565b600260003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055505b8373ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925600260003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008873ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020546040518082815260200191505060405180910390a3600191505092915050565b60008060008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020549050919050565b600560009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff1614151561139157600080fd5b60028081111561139d57fe5b600560149054906101000a900460ff1660028111156113b857fe5b141515156113c557600080fd5b6001600560146101000a81548160ff021916908360028111156113e457fe5b0217905550565b600560009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b600560009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff1614151561146d57600080fd5b60028081111561147957fe5b600560149054906101000a900460ff16600281111561149457fe5b141515156114a157600080fd5b6114a9611b01565b565b6040805190810160405280600381526020017f414c54000000000000000000000000000000000000000000000000000000000081525081565b60008073ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff161415151561152157600080fd5b6000803373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054821115151561156e57600080fd5b6115bf826000803373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054610b3990919063ffffffff16565b6000803373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002081905550611652826000808673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054610b1d90919063ffffffff16565b6000808573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508273ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef846040518082815260200191505060405180910390a36001905092915050565b60045481565b68056bc75e2d6310000081565b6b019d971e4fe8401e7400000081565b60006117b782600260003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054610b1d90919063ffffffff16565b600260003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508273ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925600260003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008773ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020546040518082815260200191505060405180910390a36001905092915050565b6000600260008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054905092915050565b600560009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff16141515611a0557600080fd5b600073ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff1614151515611a4157600080fd5b8073ffffffffffffffffffffffffffffffffffffffff16600560009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e060405160405180910390a380600560006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555050565b6002600560146101000a81548160ff02191690836002811115611b2057fe5b021790555060006004541115611c0a57611ba5600454600080600560009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054610b1d90919063ffffffff16565b600080600560009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055505b600560009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166108fc3073ffffffffffffffffffffffffffffffffffffffff16319081150290604051600060405180830381858888f19350505050158015611c89573d6000803e3d6000fd5b505600a165627a7a723058205bbef016cc7699572f944871cb6f05e69915ada3a92a1d9f03a3fb434aac0c2b0029You can find more details about smart contracts in the article: .
Conclusion
We have listed the technologies on which modern blockchains are built and how they are interconnected. Now, let's articulate the problems that can be solved using blockchain, and where, at best, solutions will be ineffective. So, using blockchain is not necessary if:
- Transactions are made in a trusted environment;
- The presence of intermediary fees does not worsen the experience for participants;
- Participants do not have ownership that can be represented as digital assets;
- There is no distribution of digital assets, meaning that value is owned or supplied by only one participant.
What future awaits blockchain? Right now, we can only speculate on potential paths for the development of blockchain technologies:
- Blockchain will become as common a database technology as, for example, SQL or NoSQL for solving its specific range of tasks;
- Blockchain will become a widely adopted protocol, like HTTP for the Internet;
- Blockchain will be the foundation for a new financial and political system of the planet!
In the next part, we will look at the existing blockchains and how they are applied across different industries.
This is just the beginning!
Source: habr.com
