Skip to main content

What Are Smart Contracts in Blockchain in Simple Words: Examples, Use

One of the effective tools for moving some activities into the virtual world and tracking their completion is the growth of smart contracts

smart-contract-2022

In this article, we will look at what smart contracts are, what they are, get acquainted with different smart contract platforms, their features, and also discuss how they work and what advantages they can bring. This material will be very useful for readers who are not familiar enough with the topic of smart contracts, but want to get closer to understanding it.

In this article, we'll cover:

  1. What are smart Contracts in blockchain?
  2. Smart contract history
  3. How does a smart contract work
  4. An example of a smart contract written in Solidity
  5. Smart contract programming language
  6. Smart contract benefits
  7. Smart contract use cases - Applications of smart contracts
  8. Conclusion

What are smart Contracts in blockchain?

Simply put, smart contracts are blockchain-stored programs that execute when certain criteria are met. They are often used to automate the execution of an agreement so that all parties may be confident of the conclusion right away, without the need for an intermediary or extra delay. They can also automate a workflow, causing the subsequent action to be taken when a certain condition is satisfied.

smart-contract-2022
smart-contract-2022

Smart contract history

No, smart contracts did not start to be used at the same time as cryptocurrencies. A similar idea appeared in the distant 90s thanks to Nick Szabo, an American scientist and cryptographer. Szabo defined smart contracts as protocols for data transfer that ensure that the conditions of each party are fully met.

Since at that time there was no environment for the existence of smart contracts, the hour of technology came only in 2008 (then blockchain technology and bitcoin appeared).

Thus, in 2013, the Ethereum platform was born, where smart contracts could prove their usefulness. Developers could now make applications without having to run their own blockchain.

How does a smart contract work?

Simple "if/when...then" phrases that are typed into code and placed on a blockchain are how smart contracts work.
When predefined circumstances have been verified to have been satisfied, a network of computers will carry out the actions.
These can entail paying out money to the right people, registering a car, sending out notices, or writing a ticket. When the transaction is finished, the blockchain is then updated.
As a result, the transaction cannot be modified, and only parties to whom permission has been granted can view the outcome.

To make it more clear, I will explain with a real example

Let’s imagine that Noah wants to buy Jorge’s Car. This agreement is formed on the Ethereum blockchain using a smart contract. This smart contract contains an agreement between Noah and Jorge.

In the simplest terms, the agreement will look like this: “WHEN Noah pays Jorge 100 Ether, THEN Noah will receive ownership of the Car”.

smart-contract-2022

Noah may feel secure in paying Jorge 100 Ether for the Car, since once this smart contract arrangement is set up, it cannot be changed.

In this case, Mike and John would have to pay a lot of fees to other businesses if a smart contract hadn't been used. Including the bank, an attorney, and a real estate agent.

Read also:

What is a Blockchain? — And How does it work | ID7saine

It's wonderful, right? No more waiting for a lawyer and broker to process the agreement, and no more commissions! This is just one of many applications for smart contracts, we shall see more examples later in this article.

Scroll to Continue

An example of a smart contract written in Solidity

Front Running

Transactions take some time before they are mined. An attacker can watch the transaction pool and send a transaction, have it included in a block before the original transaction. This mechanism can be abused to re-order transactions to the attacker's advantage

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.13;

/*
Alice creates a guessing game.
You win 10 ether if you can find the correct string that hashes to the target
hash. Let's see how this contract is vulnerable to front running.
*/

/*
1. Alice deploys FindThisHash with 10 Ether.
2. Bob finds the correct string that will hash to the target hash. ("Ethereum")
3. Bob calls solve("Ethereum") with gas price set to 15 gwei.
4. Eve is watching the transaction pool for the answer to be submitted.
5. Eve sees Bob's answer and calls solve("Ethereum") with a higher gas price
   than Bob (100 gwei).
6. Eve's transaction was mined before Bob's transaction.
   Eve won the reward of 10 ether.

What happened?
Transactions take some time before they are mined.
Transactions not yet mined are put in the transaction pool.
Transactions with higher gas price are typically mined first.
An attacker can get the answer from the transaction pool, send a transaction
with a higher gas price so that their transaction will be included in a block
before the original.
*/

contract FindThisHash {
    bytes32 public constant hash =
        0x564ccaf7594d66b1eaaea24fe01f0585bf52ee70852af4eac0cc4b04711cd0e2;

    constructor() payable {}

    function solve(string memory solution) public {
        require(hash == keccak256(abi.encodePacked(solution)), "Incorrect answer");

        (bool sent, ) = msg.sender.call{value: 10 ether}("");
        require(sent, "Failed to send Ether");
    }
}

Code source: www.solidity-by-example.org

Smart contract programming language

There isn't just one language for creating these smart contracts; there are a number of them, but the most well-known is

1.solidity

Solidity is an object-oriented programming language created specifically by the Ethereum Network team for constructing and designing smart contracts on Blockchain platforms.

  • It's used to create smart contracts that implement business logic and generate a chain of transaction records in the blockchain system.
  • It has a lot of similarities with C and C++ and is pretty simple to learn and understand. For example, a “main” in C is equivalent to a “contract” in Solidity.
smart-contract-2022

Other languages such as:

2. Vyper

smart-contract-2022

It is a programming language with a heavy influence on Python, tailored particularly for Python smart contract development. The three fundamental design principles and goals of Vyper provide a solid foundation for its efficiency in smart contract development. The three principles in the design of Vyper are,

  • Auditability - Security - Simplicity

3. Yul

smart-contract-2022

Yul is an incredible little language written by the Solidity Developers as a compilation target for further optimizations. It features simplistic and functional low-level grammar. It allows the developer to get much closer to raw EVM than Solidity, and with that comes the promise of drastically improved gas usage. The three principles in the design of Yul are,

4. DAML

smart-contract-2022

It is an open-source (anyone can see, modify, and distribute) programming language that is used to write distributed applications in a correct, quick, and concise manner. More precisely, DAML is an easy, safe, and efficient smart contract language. DAML is mainly intended for distributed ledgers. It provides a high-level and unambiguous specification of business logic in real time.

5. JavaScript

smart-contract-2022

You might want to familiarize yourself with Solidity if you're a JavaScript developer who wants to create your own smart contract. Given that it shares some syntactic similarities with JavaScript and is the most widely used smart contract language, learning it might be simpler.


And more, but these are the most popular languages for writing smart contracts in 2022

Smart contract benefits

  • Security

Blockchain transaction records are encrypted, which makes them very hard to hack. Moreover, because each record is connected to the previous and subsequent records on a distributed ledger, hackers would have to alter the entire chain to change a single record.

  • Trust and transparency

There is no need to worry about information being altered for one participant's gain because there is no third party involved and participants share encrypted records of transactions.

  • Speed, efficiency, and accuracy

The contract is immediately carried out after a condition is satisfied. Smart contracts are digital and automated, so there is no paperwork to process or time spent fixing mistakes that frequently occur when documents are filled out manually.

  • Savings

Smart contracts eliminate the need for intermediaries to handle transactions, and consequently, their time delays and fees, As we saw in the example of Noah and Jorge.


Now that we know some features of these smart contracts and the programming languages in which they are written, let's see areas in which these smart contracts are used

smart-contract-2022

Smart contract use cases - Applications of smart contracts

Based on Deloitte’s analysis, clearing is the main candidate for the implementation of smart contracts. There are other promising areas, including healthcare, logistics, and online shopping. Let's take a look at each area.

  • Clearing

Clearing means many agreements that take place between banks, as well as both legal entities and individuals. The clearing company is obliged to take into account absolutely all mutual settlements between their clients to minimize the movement of funds from one account to another and the commission for making transfers.

Because manual transaction processing is very expensive and takes a long time, companies use a blockchain registry that independently takes into account transactions and the conditions of the parties, after which smart contracts do the rest.

  • Healthcare

With the help of blockchain and smart contracts, they create secure registries for medical records. Since this type of information is confidential, it is possible to impose restrictions on viewing records signed with a multi-signature. For example, if both parties (the patient and his doctor) wish to share information with another specialist, they will be able to do this by putting their digital signatures.

This pooling of information will facilitate research and anonymous surveys. If the researcher wants to thank the person who shared good information with him, then the best way to make a payment would be a smart contract.

  • Logistics

Due to the bureaucracy, due to which it is necessary to approve various forms in the relevant authorities, logistics also suffers. Therefore, fraudsters have a chance to earn while companies suffer only losses. The use of blockchain will help prevent such problems because each of the participants has access to a secure system that controls both the execution of work and their payment.

♦ For example, Barclays Corporate Bank uses smart contracts to register the transfer of ownership and automatically transfer funds to other financial institutions.

  • Online shopping

Smart contracts allow you to track the entire supply chain.

♦ For example, you placed an order in an online store. The blockchain fixes the payment for the order, but the funds are transferred to the seller's account only after you receive your goods and confirm your satisfaction.

Conclusion

Nowadays, some banks are already experimenting with the technology and are also investing in projects in this area. The number of government agencies implementing a distributed ledger (blockchain) and smart contracts to optimize work and account transparency is only growing.

Smart contracts can replace most of the workflow because every agreement concluded during insurance or transfer of property can be turned into smart contracts. Despite this, in non-standard cases, standard paper contracts will continue to be the main elements of the document. Most likely, smart contracts will be used in the main role both for distributed applications and as an analog of an ordinary program for a distributed environment.



Source:

  • www.ibm.com
  • www.101blockchains.com
  • www.www2.deloitte.com
  • www.ethereum.org
  • www.altcoinlog.com

This content is accurate and true to the best of the author’s knowledge and is not meant to substitute for formal and individualized advice from a qualified professional.

© 2022 Idhsaine imad

Related Articles