Blockchain’s Smart Contracts

Blockchain

Nick Szabo, an expert in encryption and the creator of a Bitcoin precursor "Bit Gold",also suspected of being the mysterious inventor of Bitcoin, wrote for the first time about Smart Contracts in 1994. But it is only recently that the concept is starting to become really popular. What Nick did is that he realized that the blockchain’s decentralized ledger could be used to create smart contracts or digital contracts, where lawyers or notary’s services are no more required. If we’re able to use digitalized coins, then why not digitalized contracts!

What is a Smart contract?
Smart contracts are one of the most promising applications of the Blockchain ecosystem. Unlike a traditional contract whose realization is guaranteed by a legislative framework, the execution of a smart contract is governed by a computer code. A normal contract is converted to blocks of code and automatically triggered when its conditions are met. A smart contract therefore defines the terms of an agreement between several parties and its implementation does not require any trusted third party (legislative framework, notary, etc.).

A Smart Contract example:
You can find below a basic code of a smart contract written on the Ethereum blockchain to ease your understanding of the algorithm.
Source: https://www.ethereum.org/token


contract TokenERC20 {
    // Public variables of the token
    string public name;
    string public symbol;
    uint8 public decimals = 18;
    // 18 decimals is the strongly suggested default, avoid changing it
    uint256 public totalSupply;

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

    // This generates a public event on the blockchain that will notify clients
    event Transfer(address indexed from, address indexed to, uint256 value);

    // This notifies clients about the amount burnt
    event Burn(address indexed from, uint256 value);

    /** Initializes contract with initial supply tokens to the creator of the contract */
    function TokenERC20(
        uint256 initialSupply,
        string tokenName,
        string tokenSymbol
    ) public {
        totalSupply = initialSupply * 10 ** uint256(decimals);  // Update total supply with the decimal amount
        balanceOf[msg.sender] = totalSupply;                // Give the creator all initial tokens
        name = tokenName;                                   // Set the name for display purposes
        symbol = tokenSymbol;                               // Set the symbol for display purposes
    }

    /** Internal transfer, only can be called by this contract */
    function _transfer(address _from, address _to, uint _value) internal {
        // Prevent transfer to 0x0 address. Use burn() instead
        require(_to != 0x0);
        // Check if the sender has enough
        require(balanceOf[_from] >= _value);
        // Check for overflows
        require(balanceOf[_to] + _value >= balanceOf[_to]);
        // Save this for an assertion in the future
        uint previousBalances = balanceOf[_from] + balanceOf[_to];
        // Subtract from the sender
        balanceOf[_from] -= _value;
        // Add the same to the recipient
        balanceOf[_to] += _value;
        emit Transfer(_from, _to, _value);
        // Asserts are used to use static analysis to find bugs in your code. They should never fail
        assert(balanceOf[_from] + balanceOf[_to] == previousBalances);
    }

    /** Transfer tokens */
    function transfer(address _to, uint256 _value) public {
        _transfer(msg.sender, _to, _value);
    }

    /** Set allowance for other address */
    function approve(address _spender, uint256 _value) public
        returns (bool success) {
        allowance[msg.sender][_spender] = _value;
        return true;
    }

    /** Set allowance for other address and notify  */
    function approveAndCall(address _spender, uint256 _value, bytes _extraData)
        public
        returns (bool success) {
        tokenRecipient spender = tokenRecipient(_spender);
        if (approve(_spender, _value)) {
            spender.receiveApproval(msg.sender, _value, this, _extraData);
            return true;
        }
    }

    /** Destroy tokens */
    function burn(uint256 _value) public returns (bool success) {
        require(balanceOf[msg.sender] >= _value);   // Check if the sender has enough
        balanceOf[msg.sender] -= _value;            // Subtract from the sender
        totalSupply -= _value;                      // Updates totalSupply
        emit Burn(msg.sender, _value);
        return true;
    }
}

Some possible use cases of Smart Contracts:
Smart Contracts have a promising potential deployment in a large number of companies, from financial services to logistics, insurance, IoT... Here is an example:
Insurance: insurance companies will be able to imagine conditional offers. For example, with a Smart Contract, an insurer can offer different policies depending on the location of the vehicle at the time T. Driving on a clear day (data from a third party weather service) on a road in good state (another public source of information) could give rise to a compensation different from that of driving in bad weather on a deteriorated road.

The negative side of a smart contract:
It is impossible to stop a contract once it has been sent to the execution.
This can create severe consequences if programs have been poorly written. There is only one way to fix a smart program that has this kind of problem, and this is the traditional way - the legal voice. Today, there is no better solution. it appears as inevitable that the idea of a decentralized court / judgment / etc platform based on a blockchain could one day be created. (to solve smart contract problems ... or even more)

Comments

Info@skelpo.com

Shoot us an email, we’ll find a way to be helpful.

No pressure. Really.