Immersion in blockchain technology: fast and secure transactions

    We present to you a series of articles about the first projects in Russia developed on the basis of blockchain technology. We asked the participating teams of the InspiRussia hackathon about the technological component of their solutions.

    This article will discuss the winners of the hackathon - a project from the team of developers of Modulbank, which solves existing problems in the banking sector and helps to carry out fast and secure transactions between legal entities.



    Series of articles “Immersion in Blockchain Technology”


    1. A series of materials on Emer technology:
    1.1. Secrets of EmerCoin .
    1.2. A decentralized uncensored domain name system .
    1.3. World-wide public key infrastructure .
    1.4. Decentralized passwordless security system .
    2. Fast and secure transactions .
    3. The ecosystem of digital dentistry .
    4. The fight against counterfeit goods .
    5. Mutual animal insurance .
    6. What is an ICO and how to conduct it .
    7. Loading ...

    Problems in the banking sector that can be solved using blockchain technology


    Since the project representatives work in the banking sector, they are familiar with the problem of settlement between legal entities: this process can take up to three days, which is extremely long for small businesses and dynamic entrepreneurs. In addition, banks today have another problem: part of non-cash payments between companies is a “transit” of black money. Usually it is very difficult to determine, because there is no transaction chain and the connection between them. There is no history of the movement of money in other banks. Banks come up with various analytical algorithms to identify such transactions. But they are often mistaken, since there is not enough data for a full analysis. In turn, the blockchain network implies a single distributed transaction store. This means that each payment will forever remain in a single base of movement of funds,



    Payment rate


    The problem of the speed of payments is solved by the fact that transactions in the blockchain occur instantly. The only slowing factor may be the time that the receiving party will wait for confirmation of this transaction, since they come from other network participants - PoW.

    Transaction security


    Transaction security is ensured by the fact that the calculated checksum of the previous block is embedded in each block of data in the blockchain, so each block has a link to the previous one. We believe that thanks to this feature, blockchain technology will significantly and even radically increase the transparency of transactions and make verification procedures (in terms of combating money laundering and terrorist financing) simple and effective.

    At the hackathon, a solution was tested that simplified the analysis of cash flows between accounts: when a transaction passed through each account, “money” was marked with a special unique label for this account. Therefore, every ruble that passes through the network can pull not only the tail of all labels, but also the sequence of all accounts through which it passes. Together with the other advantages of the blockchain network (speed, security, a single transaction database), this solution eliminates the non-transparent flow of money and allows you to unequivocally restore the route of their movement at any time in the framework of the financial consortium.

    Implementation of the idea


    The key goal of the team was to show that their idea is working for the end user, so for clarity, the following were created: a client application for a mobile device, a web application for the bank and regulators. For the back-end, it was decided to deploy the Ethereum network (a platform for creating decentralized online services based on the blockchain) based on Azure Blockchain as a Service.

    A mobile application for iOS for translations was created on Objective-C. Web monitoring applications - on Angular. For back-end integration, we used the C # language and Visual Studio tools.

    The architecture of the implemented system is quite simple. Below you can see her.



    Why Microsoft Azure?


    Microsoft Azure was chosen because there is a ready-made template for deploying all the necessary infrastructure for Ethereum - DevTest Labs for Blockchain as a Service. This template deploys in Azure a virtual machine on Ubuntu, inside which the Ethereum network is deployed from the standard repository, after which the parameters of its operation are configured using artifacts.

    Why Ethereum?


    Since .NET WebApi was used to connect client applications to the Ethereum network, it is extremely convenient to use Nethereum - a ready-made solution for accessing the Ethereum network. Ethereum's main advantage for the current solution is programmable smart contracts. To create them, there is a convenient tool Solidity extension for Visual Studio. An additional advantage is that the back-end application can also be easily deployed to a web service in Azure.

    Blockchain network deployment


    The most difficult and at the same time interesting was the task of deploying a blockchain network. For this, the DevTest Labs template was used, which allows you to deploy Ethereum to Azure with a minimum of effort, since many things happen automatically in it.



    In fact, using it creates a resource group that is completely ready to deploy the Ethereum network. But! She does not create a virtual machine. The solution is simple - by clicking on Add, we simply select and add a new resource - a virtual machine on Ubuntu Server 14.04:



    After about 5 minutes, you will see a ready-made environment for deploying a blockchain network:



    Note: here it is worth mentioning that the Ethereum network deployment can take place in fully automatic mode with by connecting artifacts before creating a virtual machine. This method is described inthis article. But within the Azure test account provided for the hackathon, this option was not available. Therefore, the network was deployed manually.

    Next, using the prepared scripts , picking up to the virtual machine through the SSH client, we execute several commands (add the Ethereum repository, update the list of packages, install Ethereum):

    sudo add-apt-repository -y ppa:ethereum/ethereum
    sudo apt-get update
    sudo apt-get install ethereum
    

    Next, you need to run it all. To do this, send scripts to the virtual machine using the command:

    pscp "C:\path to your scripts folder\*" @:./
    

    Next, launch the Ethereum network by doing:

    sh seed-blockchain.sh
    

    Here, when creating a network, a genesis file is used lab-seed.json, which contains the following:

    {
    	"config": {
              		 "homesteadBlock": 10
      	 },
    	"alloc": {},
    	"nonce": "0x0000000000000042",
    	"difficulty": "0x0400",
    	"mixhash": "0x00000000000000000000000000000000000000647572616c65787365646c6578",
    	"coinbase": "0x0000000000000000000000000000000000000000",
    	"timestamp": "0x00",
    	"parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
    	"extraData": "0x11bbe8db4e347b4e8c937c1c8370e4b5ed33adb3db69cbdb7a38e1e50b1b82ee",
    	"gasLimit": "0x4c4b40"
    }
    

    After that, create the first account:

    geth --datadir "chains/devtest" account new
    

    And we start mining:

    geth --mine --identity "Node1" --datadir "/home/deathys/chains/devtest/" --nodiscover --rpc --rpccorsdomain "*" --networkid 552 console
    

    As a result, we see the launch of the mining process - new blocks are created on the network. Now they are without transactions:



    Note: note that if mining does not occur on the network, the network does not consider the transactions created in it to be confirmed.

    Now that the virtual machines are ready, you can immerse yourself in the "network" itself. In order not to stop mining, we connect to it in a parallel session. The command to connect is given in the script attachOne.sh. Since mining is in full swing, we get a reward for it on the air - the standard network currency. Currently, we have the following number of ethers for testing the solution:



    Note: in fact, this is a pretty impressive amount for Homestead "production". At the time of the hackathon, the cost of one ether was approaching C $ 17.

    Blockchain Distributed Network


    In order to deploy a distributed blockchain network, at least one more virtual machine (node) will be needed. To raise the second node of our network, you need to perform all the steps similar to creating the main node.

    In addition, in Azure, in the Network security group section, you need to open the outgoing and incoming ports on which the Ethereum network works. In the Inbound security rules section, open ports 30303 and 34964:



    Now we will connect the nodes so that they can see each other on the network. To do this, you need to introduce one node to another by entering a command, as part of connecting one of the nodes:

    admin.addPeer("enode://@:30303")
    

    To find out the ID of the represented node, you need to run the command as part of connecting to it:

    admin.nodeInfo.enode
    



    So, now we have a distributed blockchain network and you can start transferring cryptocurrency between accounts.

    To make it more interesting, we’ll create more accounts:

    personal.newAccount()
    



    As a result, we get:



    Now we can transfer ether between them, but there is one caveat - to transfer money from one account to another, you need to remove the lock from the account from which we will transfer. The lock on the account is set automatically. This is done to ensure the safety of using your account.

    personal.unlockAccount('0xa2081622fcc99aec3c1efb575b548c90bdadf8cf','12345678', 0)
    

    Here, the first argument is the address of the account, the second is the password, and the last argument is the time for which the account will be unlocked (if you specify 0, the account will be unlocked for the lifetime of this connection to the Ethereum network). If the connection is interrupted, the account is immediately blocked.



    We proceed to create the transaction:

    eth.sendTransaction({from: “0xa2081622fcc99aec3c1efb575b548c90bdadf8cf", to: "0x847a20cdec0b3ba98aced771bd1df7e8a2e004f5", value: web3.toWei(1, "ether")})
    

    In this case, we transfer 1 ether between the accounts. In response to a call, if everything went well, the transaction



    address will be returned: At this address, you can request data that the transaction contains:

    eth.getTransaction('0x88839260b77b250458731ba07d351753aba5042dd22c8420a1f6f104f3deede9')
    



    Now let's see the balance on the destination account:



    We see that the network is functioning successfully. Now fasten the client applications to it. You can use the SSH client for this. Usage example:

    using (var client = new SshClient(hostUrl, 22, userName, pass))
         	{
             	client.Connect();
             	string commStr = @"curl http://localhost:8545 -X POST --data '{""method"":         
                                ""eth_sendTransaction"",
                 	""params"": [{
                       	""from"": ""0xa2081622fcc99aec3c1efb575b548c90bdadf8cf"",
                       	""to"": ""0x847a20cdec0b3ba98aced771bd1df7e8a2e004f5"",
                       	""gas"": ""0x76c0"",
                       	""gasPrice"": ""0x9184e72a000"",
                       	""value"": ""0x9184e72a"",
                       	""data"": ""bla bla""
             	}], ""id"":1}'";
             	var comm = client.RunCommand(commStr);
             	client.Disconnect();
         	}
    

    This is part of the code in which funds are transferred from one account to another, using a command curl- in fact, an RPC request to our network. In response, we get the result of executing the command in JSON format with the data of the created transaction.

    Conclusion


    With industrial applications, everything will be much more complicated, since it is necessary to introduce and develop intelligent analytical algorithms that allow you to establish the full path of movement of funds from account to account. And also, it will be necessary to take into account the interaction of this solution on the blockchain platform with existing services within the bank.

    In this article, we have only shown ether transfers between accounts. The ways in which ether transfers from one account to another were noted are already topics of future articles.

    In the photo below, the authors of the material: Levin Denis, Anastasiev Svyatoslav, Andrey Varikov, is the development team of Modulbank.


    Also popular now: