top of page
Search

Solidity : Smart Contract Language or Legal Contract Language?

By Elif Hilal Umucu.


Introduction

This article primarily focuses on how a smart contract written in the Solidity programming language can qualify as a legal contract. The use and examples of smart contracts in the world are increasing day by day. These smart contracts, in which computers define the will of the parties in codes, also relieve the legal sector and speed up the transactions. Although the basis of law is “language”, smart contracts are an excellent way to create contracts that can be put forth concretely without human emotions.


This article explains what smart contracts are and how to write a legal contract by showing the syntax of the Solidity programming language, known as the smart contract language. In the continuation of this article, starting from the definition of smart contract, it also includes in which sectors and in which projects smart contracts are used.


The article also focuses on the syntax of the Solidity programming language, which is a statically typed programming language designed to develop smart contracts running on the EVM. The article ends by showing how to write an Inheritance Agreement with this syntax.


1. What are Smart Contracts?


A smart contract is basically a code-based automated process that executes the transaction between two parties without an intermediary. On the other hand, the reflection of the issues agreed by the parties to the computer codes, which acts with the principle of code is the law, is expressed as a smart contract. The word “smart contract” is self-explanatory, often though the smartness of smart contract is considered a misnomer, the third party-less working of a contract in a decentralized ledger where each party enters into an agreement by programmed codes is what perhaps makes it “smart.”


The earliest definition of smart contract is Nick Szabo's article titled “Smart Contracts: Building Blocks for Digital Markets” published in early 1995. It is seen that smart contracts, which were put forward by Nick Szabo, a lawyer, cryptographer and computer programmer in 1994, have become widespread with Blockchain technology today. In Szabo's definition, a smart contract is 'a transaction protocol that executes the terms of a contract'.


To illustrate with an example, let's say I want my grandchildren to receive 20% of my inheritance. However, I have some conditions, for example, if my grandchildren are 25 years or older, they will be able to inherit this legacy. If we add this requirement to the smart contract, the smart contract will handle the transactions without the need for any third party. This is just the basic logic of a smart contract. Wherever a transaction needs to occur between two parties, you can use a smart contract that gives you full control and automates those transactions.


2. Sample Smart Contract Projects

  • Fizzy AXA, a French airline, uses Blockchain technology with Ethereum Smart Contracts to provide more secure insurance for its passengers. When passengers choose to take out insurance, flight information - such as departure time - appears in smart contracts. Also, their systems upload the flight status to their Blockchain codes. In the event of a delay exceeding two hours, passengers are offered compensation options.

  • The Indian Academy of Science states that a decentralized mortgage industry can be developed with the advantages of smart contracts. In their report, they show how technically useful smart contracts can be for the mortgage industry. As customers enter their credentials, the system verifies them by looking at their government's database. This example also sheds light on how smart contracts can be beneficial for governments. Along with secure verification, using smart contracts in the mortgage industry can save a lot of time.

  • In a healthcare project involving IBM, food supply is provided through smart contracts. The aim of this project, which includes Nestlé and Walmart companies, is to protect consumer health and to minimize deaths. In the project, foods are tracked in smart contracts transferred to the supply chain. Foods that impair people's health are identified through the chain and solutions are sought for problems.

  • The Smart Port Project is another project that came into effect at the Port of Rotterdam in the Netherlands. In this project, Blockchain and smart contracts were used in terms of maritime transport. The aim of the project is to record the communication and interaction between the receiver, sender and carrier during maritime transport. The information recorded are as follows: entry-exit of the goods to the port, arrival and departure information, transportation information, transportation conditions of the goods.

3. Example Sectors Where Smart Contracts Can Be Used:

  1. Financial Services a. Taxation (KDVcoin) b. Fund Transfer

  2. Health Services a. Roche Group b. MediLedger Project

  3. Digital Services a. Intellectual Property in Digital Works b. Counterfeiting of Digital goods

  4. Public Sector a. Land Registry Records b. Real estate purchase and sale

  5. Supply Chains and Automation

4. Introduction to Solidity


Solidity is a statically typed programming language designed to develop smart contracts running on the Ethereum Virtual Machine (EVM). Solidity is a contract-oriented, high-level language for implementing smart contracts. Smart contracts are programs which govern the behaviour of accounts within the Ethereum state. It was influenced by C++, Python, and JavaScript and was designed to target the Ethereum Virtual Machine. Solidity is compiled as bytecode executed in the EVM. Using Solidity, developers can write Decentralized Applications (dApp) that implement a self-enforcing business mechanism that is returned to smart contracts and leave an authoritative record of the transaction. While discussing Solidity in this article, first the syntax is explained in a simple way, then it is explained how to write an Inheritance contract using this syntax and codes. Contracts in Solidity are very similar to classes in object-oriented languages. They can contain state variables, functions, events, and struct types.


When getting started with the Solidity programming language, you don't need any prior experience with the language; However, having some experience with Blockchain technology or at least understanding the basics of what Blockchain is and how it works will help you. You can develop smart contracts on a Mac, Windows, or Linux using the Solidity programming language. In other words, the environment you use will not have any effect on your language learning. And in most cases, you can use the web-based Remix environment, which we will review below. If you want to discover what others are doing, you can check out the link at stateofthedapps.com where you will see hundreds of games and apps created using Ethereum and Solidity.


5. Ethereum Virtual Machine (EVM)

Ethereum is a system first introduced at the North American Bitcoin Conference by Ethereum founder Vitalik Buterin. Although it is actually seen as an alt coin, Ethereum is an innovative system that aims to develop blockchain technology and use it in more areas. Buterin has changed the certificate used by Blockchain. And he developed the blockchain-based software Ethereum using the SHA-256 certificate. Ethereum made it possible to produce documents consisting of codes, called smart contracts. To explain in a short and understandable way; as a function, smart contracts are non-intermediary systems that express the autonomous (so by itself) performance of the contractual acts without any additional discretion of the parties, in the event that the contractual terms agreed upon by the parties are fulfilled.

Smart contracts are a computer protocol that enables the exchange of money, real estate or any asset that can be traded without any intermediary. All transactions performed in these contracts are converted into computer code, stored and controlled by users on the blockchain network. In addition, smart contracts provide accounting feedback of transactions such as money transfers, purchases and sales of products or services.


E.g; If an individual who wants to buy a house uses the smart contract protocol in this transaction, the first thing to do is to create a digital contract with the seller on the blockchain network with the terms of purchase and sale. When a trigger transaction (payment, expiration, etc.) is initiated that is coded into the contract, the contract runs itself and the transaction is recorded in the blockchain network.

At the end of the transaction, digital receipts are added to be kept in the agreements of the parties and the shopping is completed.


If you want to delve deeper into cryptocurrencies and smart contracts, you will need to know:

  • Programming language: Solidity

  • The way the Ethereum network works

Tools that you will need:

  • Solidity compiler (solcjs)

  • Text editor : Remix

The web-based compiler called Remix is a convenient platform for coding and running smart contracts. Remix is a tool that allows writing smart contracts using a browser. In addition, Remix allows compiling contracts and uploading them to the network. Remix also supports JavaScript virtual machine, which allows you to simulate uploading and running a contract on the network. Then all functions will be testable.


So https://docs.soliditylang.org can be clicked first. And here click the link to install the Solidity compiler. Next you will need to find Docker. Docker is a nice and simple way to start using a local environment. In addition, in the Solidity integration section on the main page, all integrations that can be used with Solidity are available. Then all the extensions you have for the compiler can be downloaded from here. These are Atom, IntelliJ, Visual Studio etc. are examples.


6. Solidity Syntax


Everything is ready to start syntax in Solidity. First seen the compiler at remix.ethereum.org. Deleting everything from scratch will be helpful to understand the logic of the syntax.


The first thing to do is to import solidity, to do this, the pragma keyword should be used. This is done only once while coding the smart contract, Solidity must be loaded followed by the version number. In this case, one should go for version 0.4.0.


// import solidity

pragma solidity ^0.4.0;


After importing Solidity to file, it will be able to import any other file. That way and then you will be able to import the "filename". This is the import syntax.If certain files in a file are to be imported, symbol1 can be used symbol1 as an alias and symbol2 from a filename. Basically, it's possible to change any of these filenames, it's purely by convention so that alias can be used in this file and symbol2 can be used from .filename in this file. Then, finally, the contract establishment phase will be started.


import "filename";

import * symbolname from "filename";

import {symbol1 as alias, symbol2} from "filename"'


BasicContract, open curly brackets and close curly brackets. Whenever something is added, variables or functions are added, they need to be put inside the contract.


// this is my first contract

contract BasicContract {}


Solidity needs to be imported first.

Then the filenames or any files that may be needed need to be imported.

And then it comes to the stage where the contract will be established.

And the code will go into the contract here..

Everything is ready for the first smart contract written with basic syntax.


The next thing to do is to declare a state variable. So the way you declare a state variable and the word state by the way means that it is the current state of that “variable”. First the type is made, in this case the "uint" statement is applied and the types will be described in future codes, then the name of the variable will be “storedData”.


// this is my first contract

contract BasicContract {

// state variable

uint storedData;

}


There are also “functions” and “modifiers”. Modifiers are conditional to a function or conditions before executing the function. So it will do the modifier first. By the way, the compiler may return an error if it is run as stated in these examples.


This is normal for now because the codes are

not fully completed yet. But when the final contract is actually written, the compiler will be able to run. Also, the code can be written

with comments (the green line with //) as you can see below, which are always useful to help remember or show where you left off. Now it is necessary to assign a modifier.


// modifier is a conditional

modifier onlyData() {


In this case, the modifier keyword is used after the modifier's name. So it's preferable to make the modifier name "onlyData" in the code. In this case, it may be requested that the value of the stored data be equal to or greater than zero, it is entirely at the discretion of the people who prepared the contract. Then the semicolon must be underlined to close the modifier. This syntax belongs to Solidity.


// modifier is a conditional

modifier onlyData() {

require (

storedData >= 0);

_;

}


It is important to note that the modifier will usually need a function. A function must now be written. Functions work like any other programming language. Therefore, it is necessary to start by writing the function word.


// function


It is possible to write the name of this function later. It can be written what kind of parameters this function takes. It is also possible to say that my function takes an integer named “e”, this expression is entirely up to the person writing the code.


function set(uint e) public {


The “public function” will be used so that everyone can see this function. However, code writers can choose a private function instead of a public function by making a different choice in their own contracts. The stored data is equal to e, which will be the body of the function.


function set(uint e) public {

storedData = e;

}


So basically the modifier will check that the value has a value greater than or equal to zero before running the function. This check is available in the above codes:


storedData >= 0);

_;


If there is a value that matches the given example, that is, if this condition is met, the function will actually run. If the condition is met, the function works fine, which means that the code should not throw an error.


The last thing to write in a contract is an “event”. Also this is the syntax for an event. First of all event is the keyword here. In the contract in question, the name of the event is “Sent”. So the event is basically expecting an address and then the address type needs to be determined.


event Sent(address from, address to

uint storedData);

}


7. Coding an Inheritance Contract with Solidity


First of all, the syntax of the Solidity programming language is briefly as described above.


Now, "Inheritance" contract can be written with solidity programming language. First of all, it is necessary to start coding by creating a few variables. Of course, the expression that should not be forgotten is the “pragma” expression. It is possible to write the name of the contract after “pragma” and it depends on the person who wrote the code. The smart contract in this article will be named “Inheritance”.


// import solidity

pragma solidity ^0.4.0;

contract Inheritance {

address owner;

}


An address will be needed when defining variables. It is possible to use "bool" after specifying the address, and it is necessary to construct the bool expression with "deceased".


contract Inheritance {

address owner;

bool deceased;

uint money;

}


Then it would be necessary to introduce a new “constructor”, the constructor would be public which means it must be “public”.


But whether this constructor is public or private depends on the person who wrote the code, it is possible to change it.


contract Inheritance {

address owner;

bool deceased;

uint money;

constructor() public payable {

owner = msg.sender;

money = msg.value;

deceased = false;

}


In this situation, the owner variable created above needs to be passed to msg.sender. The message will come with a value, so it is necessary to pass it on to money. Initially the deceased must be set to false. Then it would be correct to specify a range of “addresses”. This address string is called a “wallets".


constructor() public payable {

owner = msg.sender;

money = msg.value;

deceased = false;

address[] wallets;

}


Next, mapping needs to be used to pass integers (money amounts) to addresses in Inheritance. In this case, again, a modifier will be used. Then the name of the modifier needs to be defined and the curly brackets to open and close.


constructor() public payable {

owner = msg.sender;

money = msg.value;

deceased = false;

}

modifier oneOwner {

require (msg.sender == owner);

}


There is one thing that should be added and not forgotten. After writing the contract, it is necessary to make sure that there is someone who is executing the contract so that this message or money can be transmitted.


So this is actually an important situation that needs to be checked. If this situation is not checked, the conclusion of the contract will have no meaning. Do not forget the semicolon and underscore right after it. Because that's how a modifier is written in the solidity programming language.


modifier oneOwner {

require (msg.sender == owner);

_;

}


Then another modifier called "isDeceased" can be set. Therefore, it is necessary to make sure that the person has passed away before actually executing the inheritance contract. Again, it is necessary to open and close the curly brackets here. Then the definition of "require" is necessary and important. The same must be done again. Do not forget to add the underscore with a semicolon.


modifier oneOwner {

require (msg.sender == owner);

_;

}

modifier isDeceased {

require (deceased == true);

_;

}


Therefore these two modifiers will be run before the function is run to check for these values. By having a value of "true" on these modifiers, the function that runs the contract will actually be executable. When continued later, a function will be used again. The name of the function will be "setup". And this function will need to use two parameters. The first parameter will be "wallet" and the second parameter value will be "uint" for inheritance. Also, this will preferably be made “public”, but it can also be private depending on the person coding the contract. This means that when it is set as a public value, it is readable and accessible to everyone. Also this operation will need "oneOwner". (By the way, the modifier assigned as "oneOwner" is very important for the system. If it works properly and passes the modifier, the next codes of the system will work smoothly and properly. )


function setup(address _wallet, uint _Inheritance) public oneOwner {

}


Again, the curly brackets will need to be opened and closed, as exemplified above. In the next code, it will be necessary to add the existing wallet to the "wallets" using the "push" function.


function setup(address _wallet, uint _Inheritance) public oneOwner {

wallets.push(_wallet);

}


In fact, it can be said that this is the most important point for the contract. Because this is where the contract is established. In this section, an array will be created that contains or holds the wallet transferred here. Therefore, the code below can be called the crux of the contract.


Inheritance[_wallet] = _Inheritance;

It will now create a second function called “moneyPaid” without parameters. This function will be written as private, not public. The person's death must be confirmed and confirmed.


This time it will be necessary to run a for loop in the code. Loops are used to repeatedly execute a series of statements until a certain condition is met. Therefore, it would be appropriate to use a for loop in this code. An integer value will be passed inside the for loop and the loop will be set up with normal or typical for loop code.


And then as long as this loop is running, in essence, a loop will be run that will send the inheritance funds if they die.


Inheritance[_wallet] = _Inheritance;

}

function moneyPaid() private isDeceased { for (uint i=0; 1<wallets.length; i++) {

wallets[i].transfer(Inheritance[wallets[i]]);

}

}


To summarize, basically a for loop is executed and the inheritance is distributed accordingly. A final function will need to be added to the contract.


This function is the "dead" function.


This functionality needs to be made public. A "oneOwner" will also be needed. Basically this is the function to run to indicate that this person is dead.In this case, the deceased will be changed to "true" and the contract will then continue and carry out the inheritance with moneyPaid. This function works if the person is declared dead, and then when this person dies, the money set up in the wallet is transferred to the designated places.


It is very important for inheritance contracts to create a wallet that will hold the actual inheritance waiting for the person to die when the actual contract is first established. As a result, all functions and the contract that needs to be established are completed.


function died() public oneOwner {

deceased = true;

moneyPaid();

}


A look at the Code of Inheritance Contract written in Solidity programming language.


Conclusion

Since the transactions in smart contracts are carried out with computer codes, whether these contracts will be legally accepted is still among the issues discussed in the doctrine. Understanding the logic of smart contracts, where codes are law, is important for the development and advancement of technology law. As a tech enthusiast and blockchain researcher, I started this post because I wanted to keep up with the digitizing world and contribute to the digitization of law. But my main purpose in writing this article is to simplify the Solidity language so that lawyers can understand it and to write a contract in that language.

 

About the Author

Entering her Blockchain and Technology Law career with cryptography, Elif Hilal developed her own encryption method when she was only 10 years old.She then began to learn encryption mechanisms and the science of cryptography. She found the way to communicate with computers by learning to code, she learned to code when she was a freshman at university.

While she was a university student, she had the chance to work as a blockchain researcher in the Digital Transformation Office of the Presidency of the Republic of Turkey. In addition, she was elected as the Microsoft Turkey Student Ambassador and represented her country many times in the international arena.


Elif Hilal, who has been working on Blockchain for about 6 years, is currently working on Blockchain at Chainlink Labs.


2 Kommentare


Khan Zain
07. März

This article provides an insightful exploration of the intersection between smart contracts, specifically those written in the Solidity programming language, and legal contracts. By elucidating the concept of smart contracts and their growing prevalence in various sectors, the author effectively captures the significance of coding contracts as a means to automate transactions and streamline processes.

The comprehensive breakdown of Solidity syntax, coupled with practical examples such as coding an Inheritance Contract, facilitates understanding for both tech enthusiasts and legal professionals. The inclusion of modifiers, functions, and events within the Solidity code exemplifies a meticulous approach to explaining complex programming concepts in a digestible manner.

Furthermore, the article's consideration of legal implications and the ongoing discourse surrounding the acceptance of smart…

Gefällt mir

Sharmi Kutta
Sharmi Kutta
27. Okt. 2022

Go Gauge is an International Freight Forwarding & Transportation Company covering various industries such as Energy, Steel, Power, Oil & Gas, Infrastructure, Automotive and Rail sectors.Cargo and Freight Company Our business is to provide integrated logistics services such as Project Cargo Management Solutions, Factory Decommissioning Solutions, International Freight Management, Customs and Cross Border Movement, Heavy and Over-Dimensional Cargo Movement, etc. Go Gauge provides end-to-end visibility using cutting-edge technologies throughout the entire supply chain.

Gefällt mir
bottom of page