Over the last year, the Stellar platform has shown rapid growth in the background of other blockchain solutions.

One of the first striking examples of that was the decentralised Mobius applications platform. It was built on the Stellar platform and during the course of ICO gained a record $ 36 million for the Mobius. Since then, it’s became clear that the Stellar’s potential is not only as a quick and easy platform for cross-border payments but also as a reliable and efficient platform for ICO implementation.

Unlike the Ethereum, Stellar has not got a full Turing-complete language for creating Smart Contracts and is limited to a minimum set of operators running under different conditions.

A Stellar Smart Contract (SSC) is expressed as compositions of transactions that are connected and executed using various constraints.

Depending on tasks that you are facing, this can be both a plus and a minus. The Stellar would be a better choice than Etherum for the majority of ICOs, with a simple token model, and plain token-flow. The choice becomes obvious if we add to that serious security problems in Ethereum Smart contracts.

Security researchers have found, on average, five security flaws in each cryptocurrency ICO (Initial Coin Offering) held last year. Only one ICO held in 2017 did not contain any critical flaws.

Therefore, here at GoodX Network, we chose Stellar as the ideal partner for the given tasks.

In this article, I would like to draw your attention to the capabilities and features of Stellar during the write up of smart contracts.

The first thing that developers of Smart contracts on Stellar have to deal with is the absence of any programming language that is used to describe the necessary actions and conditions; this is in contrast to the same Solidity in Ethereum or Rootstock. Instead of that, you should present your smart contract work frame in the form of a sequence of certain transactions occurring in the Stellar blockchain under certain conditions and in a certain sequence. In this case, it is important to keep in mind that there’s not as many conditions, and as simple at first glance actions are described by completely non-trivial sequences.

For the comparison, it is best to look at the low-level programming languages, such as Assembler. Where it is necessary to perform a sequence of simple operations with certain conditions for operations of division or multiplication.

Let’s take a look now at a possible version of the Smart contract for one of the challenges proposed by the Stellar at the 7m Stellar Build Challenge (SBC #7)

Peer-to-Peer-Wallet:

This one is the biggest and most ambitious of the suggestions. This wallet would facilitate peer-to-peer payments without the need for anchors. It could be used to make small payments all over the world.

The complexity of the challenge is not only based on the fact that the transaction is going from Alice to Bob, but also on that it is going through an undefined length of the chain of Stellar users. Where each user knows only his neighbour on the left or right, and probably has not got a clue of the existence of Alice or Bob. The length of such chain may be infinite. Therefore, by following the well-known theory of “Six degrees of separation”, we have made the decision to limit the chain to a maximum of 6 people.

Conditions of the task:

Alice, who lives in Australia, has a wallet in Stellar and she wants to transfer 100 dollars to Bob, who lives in Cuba. Bob wants to get paid in cash as he has no idea about crypto-currencies. Here at GoodX, we’ve developed a prototype app for this; it allows you to make such transaction through the network of friends. Since the purpose of this article is to show the capabilities of Stellar Smart contracts, let’s assume that our application is already installed by a vast number of users around the world. In the app, each user has marked their friends, whom they trust and indicated the amount of trusted funds (see the original challenge on web page SBC #7). Also, in what countries, he is ready to transfer money in cash to the recipient. Alice, using the application, indicates that she wants to transfer 100 dollars to Bob living in Cuba. The

application restores for Alice the optimal pathway the transfer has to pass, with a length of 6 friends, where Alice is the first and Bob is the 6th in the chain. In this regard, Alice knows only the next person after her in the chain — her friend, whom she trusts and the 3rd , 4th and 5th person in the chain she does not trust. The 2nd participant in the chain trusts the 3rd one, the 3rd trusts the 4th one, and the 4th trusts the 5th one.

Solution of the task:

A possible version of the Smart contract for one of the challenges proposed by the Stellar

Alice creates a new wallet in Stellar — A1 (Escrow) and transfers into the wallet the required amount ($ 100) + the total sum of intermediary commissions + Stellar network costs of transactions + reserved funds. Alice generates a random X and calculates SHA256 Hash from it — in the Stellar network, it’s called Hash(X). Alice assigns the calculated Hash(X) as a Signer for A1 with a signature weight of 2. Alice creates a transaction to make the transfer to the 2nd participant of the network on the route and wraps the transaction into the “Envelope” by signing it with her private key. Alice gets the current Sequence number for A1 Wallet and sets for the transaction that was made on the 4th step with the Sequence Number = N+1. XDR of the resulting transaction is saved in the DataEntry of the account A1.At the end of the 6 th step, the A1 account is created in the Stellar blockchain network, that contains $ 100 for the transfer and for which a transaction has already been created to make the transfer of $ 100 to the second participant in the chain. XDR transaction is published on the

network and is available for viewing by any interested user in the Stellar network. The transaction mentioned above is signed by the Hash (X) key — which allows any user who knows X, to sign a transaction and send it to the network. Alice informs the 2nd participant in the chain that she has prepared a transfer to his address and indicates wallet A1. 2nd participant gets a record of XDR transaction from the A1 wallet and validates it. The sum, sequence number and Hash (X) — are also available to the public on the Stellar network. After the validation of XDR record, the 2nd participant undertakes the same steps 1 to 6 just like Alice did. Precisely, the 2nd participant creates a B1 Wallet (Escrow), and transfers the required amount into it, with the following difference, that Hash (X) is already known from the XDR record in A1 and from the 2nd participant the only requirement is to specify it as a signature for B1 with a weight of 2.

Same things are observed with the 3rd and the 4th participants in the chain. All of the above actions are fully automatic and do not require user intervention. So that their seeming complexity remains invisible.

When the 5th participant of the chain receives and checks the notification from the 4th participant, he contacts Bob and gives him $ 100. As soon as Bob gets $ 100, he informs Alice that everything went well. As you may recall, Alice promised $ 100 to her friend (the 2nd participant of the network), and she can’t trick him. If Bob received promised $ 100, then Alise’s friend fulfilled his promise to transfer the money further, through his friends.

This is where the magic of Stellar smart contracts begins.

Alice signs previously placed transaction using X, that she has generated in step two. And sends it into the network. The signed transaction is executed, and Alice’s friend (2 nd participant) receives the promised $100. From now on, X is available to the public on the Stellar network in the open form. This means that all the other participants in the chain can easily sign the XDR transactions they received earlier, transferring $ 100 to their address using assigned X and receive the money that was pledged.

The result has been achieved, Bob received $ 100 without even knowing anything about crypto-currencies. The intermediaries have earned their little interest when the money been passing through them.

In reality, the above mentioned smart contract is a lot more complicated. Because it covers automatic transmission of notices between the participants of the chain as well as to save and obtain ways to calculate routes, merging of Escrow accounts with the main user account, to release funds from the remaining balance and so on. So, my aim here was to show you how nice and neat the Stellar smart contracts can be and that their application in practice can be limited only by your imagination and understanding.