Smart contracts within the Lightning Network: the essence of the concept and technical details

Without smart contracts can not do almost any blockchain. Next, we will discuss the mechanism of such contracts in the framework of the network Lightning Network.

Smart contract
Initially, you need to understand why bitcoin was nicknamed programmable funds. Storage system assets in the Bitcoin network is different from the usual concept: there are no accounts tied to them no numbers corresponding to the balance.

Instead of the classical scheme of this process is the following: when transferring funds to the recipient, they are blocked by a program called smart contract. For the use of funds side, the recipient must present the system with login details that will allow you to achieve a positive result during the operation.

Storage smart contracts is within the blockchain, and their execution is made by miners and not one specific, and their total number. If one of the miners attempting to perpetrate a fraud and bypassing the system, it will be thrown out of the cycle of emissions, and its profit will be lost.

Cryptocurrency Ethereum type used technology smart contracts and led her to a new stage of development is allowed to consider bitcoin as a decentralized power that use the blockchain technology as a storage for software. The community of miners plays the role of the processing layer.
In the elementary scheme of the input data, allowing for the unlocking of funds is the signature, or electronic signature. It generates cryptocurrency wallet by using private keys of the user. For this reason, privacy and reliability of public and private keys are so important, because if they are lost, for whatever reason, then the electronic signature can not be generated and, accordingly, will not receive access to funds.

In these articles, considering the principle of operation of the system will use the analogy of the boxes, that is, when each transfer of funds by the sender creates a kind of virtual safe in which to place the specified volume of assets and is locked so that only upon presentation by the recipient the necessary data is received the access to money. As advocates of safe money storage and a lock to it and is a smart contract. It involves the use of a special password, which has only the recipient of the assets.

In standard situations, smart contracts are generated in a cryptocurrency wallet. In the case of skills for independent writing such contracts they may have the most various form. For example, you can make a lock so that the opening of the safe and the money will be available to anyone who decides example 3+3.

Network Lightning Network uses several kinds of smart contracts, but rather their hybrids:

2x2 multisig – this smart contract grants the user access to the media through the use of electronic signatures by both parties;
Htlc, or hash lock time contract – this smart contract allows you to access the funds, provided that will have the number x is a secret value that is owned by the Creator of the contract. If you pass a number x, then, in fact, is passed to access cash. The transfer is made in open form, i.e., x is visible to all users, and it is recorded in the smart contract in the form of equation h = H (x), given that H is a hash function;
Time-lock – this smart contract uses as unlock the specified time.
The combination of different kinds of smart contracts allows to obtain the desired properties for the operation, and to observe non-standard behavior. An example of this can be blocking of funds until a certain time, and then to access the money you need to solve the basic equation.

Sending funds
In the case when you need to make a good use of money, crypto scans the blockchain for the presence in it of the safes that belong to you, or inputs. This is followed by generation of evidence of belonging of the assets that is you, or segregated witness. After this, the address which the sender is used by the system to generate a smart contract – he will block the required amount in the generated Deposit box, or outputs, which will be available only to the recipient of the funds.



The above data are components of a single structure of the transaction. The system sends them to MINERCOL network.

Upon receipt of the transaction by the miner uses evidence supplies safe for you, and run smart contracts for safes. If you return a positive result smart contract means you can use it. After this is obtained in the course of the transaction, smart contract used to create the next box. In fact, the broadcast operation in the network the box is active and the assets stored therein, can be used.



Insights on the work of smart contracts to Lightning Network
This article has covered the basic principles of smart contracts in the framework of the network Lightning Network. You can then do an abstract definition of the term "payment channel", speech about which will go in the next publication.

Payment channel represents an interaction between two users of the network, which is recorded in the blockchain and regulated through the use of smart contracts. It provides the network members to exchange funds in the format of high-speed transactions outside the network blockchain.
+ 0 -
Should I now invest in a cryptocurrency, or is it too late? What cryptocurrency is better to invest money in? What are the peculiarities of investing in cloud mining? What are the most promising areas for investment in cryptocurrency? investments in cryptocurrency 2018. How to invest in Bitcoin and other cryptocurrency? How to invest in cryptocurrency and whether to do it now. Do investments in token-ICO in the fall of cryptocurrency? What are the rules for successful investment in ICO? Investments in token-ICO in the fall of cryptocurrency: does it make sense