pen on paper to represent a smart contract

A smart contract is a self-executing contract that is designed to enforce the terms of an agreement created between two parties. Terms of the contract are recorded in a computer language such as C++ as a set of instructions, and are carried out automatically. The aim of smart contracts is to facilitate the exchange of money, or anything of value, whilst also reducing costs associated with the formation of a contract e.g. legal fees. For example, If Bob wanted to enter into a contractual agreement with Alice for the sale of a house, normally, both parties would seek the help of a real estate agent or a lawyer in order to form a contract. However, through the use of a smart contract, the parties respective wishes can be encoded and automatically executed, therefore, eliminating the need for middlemen.

Example of a smart contract:

pragma solidity ^0.4.16;

contract MyToken {
    // This creates an array with all balances
    mapping (address => uint256) public balanceOf;

    // Initializes contract with initial supply tokens to the creator of the contract
    function MyToken(
        uint256 initialSupply
    ) {
        balanceOf[msg.sender] = initialSupply;              // Give the creator all initial tokens
    }

    // Send coins
    function transfer(address _to, uint256 _value) {
        require(balanceOf[msg.sender] >= _value);           // Check if the sender has enough
        require(balanceOf[_to] + _value >= balanceOf[_to]); // Check for overflows
        balanceOf[msg.sender] -= _value;                    // Subtract from the sender
        balanceOf[_to] += _value;                           // Add the same to the recipient
    }
}

Source: Ethereum.org

A well-known use of smart contracts can be found on the Ethereum blockchain, where they are integrated into decentralized applications (DApps). The trust less and self-executing nature of smart contracts means that the operation of DApps need not depend on a centralized network. However, the use of smart contracts does not come without risk. The code included in a smart contract may contain bugs and security holes that are exploitable. This was the case when, in June of 2016, approximately $50 million worth of ETH was stolen from the Decentralized Autonomous Organization (DAO), due to an exploitable security hole in its smart contract.

To find out more about smart contracts and how they can be used power DApps, check out this article here.



 

SHARE

I hope you enjoyed the article! You can connect with me on Twitter by clicking the icon below.