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