What is Smart Contracts? The Beginner’s Guide to Smart Contracts

What is Smart Contracts? The Beginner’s Guide to Smart Contracts

The phrase “Smart Contracts” was proposed Nick Szabo to expand the functionality of electronic transactions such as POS (point-of-sale) to the digital realm.

  1. What is Smart Contracts?

    Smart contracts are computer programs that run automatically when certain conditions are met.

    Trustless Contracts

    Smart contracts allow you to share any value among strangers in a transparent and conflict-free manner.

    Smart contracts can be thought of as a Blockchain-based vending machine. Smart contracts, just like vending machines that take dollars to dispense your item of choice, use ether to fuel code that is based on pre-configured rules.

Deploy Your First Ethereum Smart Contract

 

  1. Smart Contracts by Nick Szabo

    Szabo suggested that a contract be executed for synthetic assets such as bonds and derivatives. These new securities can be created by combining securities (such a bonds) with derivatives (options or futures) in many different ways. Computerized analysis of complex term structures can be used to create standardized contracts that allow for trading with low transaction costs.

 

Blockchain Training

BLOCKCHAIN TRAINING COURSE

Blockchain Certification Training Course

Review 5(22661)

ETHEREUM DEVELOPER COURSE CERTIFICATION

Ethereum Developer Certification Course

Review 5(1485)

  1. Why Smart Contracts Are Important?

    Many solutions can be automated by using a Blockchain. Let’s see how smart contracts compare to traditional contracts.

    Smart contracts: Complexity as Per Use Cases

    The use cases that you want to code on the Blockchain will determine the complexity of your contracts. This image will help you understand the complexity of smart contracts.

    Contextualized smart contracts will allow companies to be automated. However, a decentralized autonomous government can also be created.

    Let’s look at a use case to understand how smart contracts work.

    Smart Contracts: Healthcare Industry

    Patient data management: There are two major issues when it comes to the patient data management in the healthcare sector:

    • First Each patient is unique. Access to all medical records is essential to tailor treatment and provide personalized care.
    • Second Information sharing among medical professionals is a significant challenge

    The above-mentioned issues can now be solved using smart contracts functionality on Blockchains.

    Smart Contract Advantages

    Here are the benefits of Smart Contracts:

    Blockchain Platforms to Write Smart Contracts

    HTML3_ HTML4_ HTML5_ HTML3_ HTML5_ are the most used platforms for creating contracts. However, they are not the only ones. Here are some other platforms that can be used to create smart contracts.

    Bitcoins Bitcoins uses Script with limited capabilities for processing documents. These scripts are designed specifically to process Bitcoin transactions.

    Hyperledger fabric: Chaincode is programmatic software that is deployed on the network and is validated by the chain validators during the consensus process.

    NXT This is a public blockchain platform with a limited number of templates for smart contract creation. You can only use the code that is already there.

    Side Chains : side chains improve Blockchain’s performance and privacy protections. Side chains add additional capabilities such as smart contracts, secure handles and real world property registry.

    Tools to Write & Deploy Smart Contracts

    1. Mist browser – This tool allows you to browse and use dApps. It’s a separate browser that allows you to browse and interact with dApps.
    2. Truffle Framework Truffle is a popular Ethereum development framework. It supports smart contract compilation, linking and deployment as well as binary management.
    3. Metamask – MetaMask allows you to access the distributed web of tomorrow from your browser today. It allows users to run Ethereum apps directly in their browser, without having to install an Ethereum node.
    4. Remix– Remix, a web browser-based IDE, allows users to create Solidity smart contracts and then deploy them.

    Programming Languages for Writing Ethereum Smart Contracts

    Solidity and Serpent can be used to create Ethereum Smart Contracts.

    Solidity –It’s a contract-oriented high level language with syntax that is similar to JavaScript. It is intended to target the Ethereum Virtual machine (EVM).

    Serpent Serpent: Serpent, a high-level language for writing Ethereum contracts, is a high level language. Although it is similar to Python, Solidity has become the preferred language for Ethereum developers as of September 2017.

    Solidity is the most used language for smart contracts at the moment, but there are several upcoming smart contract languages that could be of great importance in the future.

    New Programming Languages

    1. Viper: viper uses a Python-like indentation system. It is focused on security, language and simplicity of the compiler.
    2. LiskLisk uses Javascript as a smart contractual language, which makes it easier to develop applications.
    3. chain: chain provides enterprise-grade blockchain infrastructure using SDKs in popular languages like Ruby, Java and NodeJS.

     

    Let me now show you how to write a Solidity contract, as Solidity is the most commonly used programming language for Ethereum Smart Contracts.

    Property Transfer Smart Contract

    Problem: At the moment, the central authority is used to transfer property ownership. It is time-consuming, expensive, and carries additional paperwork. There is also the possibility of fraud because the system is centralized.

    Solution The plan is to use technology to make details of real estate transactions available to all parties, including banks, brokers and government officials as well as buyers and sellers.

    Okay, I’ll write a Smart Contract.

    1

    2

    3

    4

    5

    6

    7

    8

    9

    10

    11

    12

    13

    14

    15

    16

    17

    18

    19

    20

    21

    22

    23

    24

    25

    26

    27

    28

    29

    30

    31

    32

    33

    34

    35

    36

    37

    38

    39

    40

    41

    42

    43

    44

    45

    46

    47

    48

    49

    50

    51

    52

    53

    54

    55

    56

    57

    58

    59

    60

    61

    62

    63

    64

    65

    66

    67

    68

    69

    70

    71

    72

    73

    74

    75

    76

    77

    78

    79

    80

    81

    82

    83

    84

    85

    86

    87

    88

    89

    90

    91

    92

    93

    94

    95

    pragma stability 0.4.11;

     

    // This use case is meant to imitate the real-world property transfer

    // This use case requires

    // A digital ID is in-place

    // Government agrees to place land records on the public Blockchain

    // Each Development Authority (DA) becomes the defacto owner of the property that exist under their constituency/legislative body

    // After ensuring that all conditions have been met, the DA (owner) can attach the property to the owner.

    // We will be formulating the function around that set assumption.

    // We assume that each DA will deploy their smart contract according to their regulation and rule. The whole smart contract is written with DA as the owner. This means that DA can allot property.

    // The govt may be added to these DA. The Govt has the power to decide which DA(address), becomes the owner of which contituency.

    // This can be easily extended. You will be able to understand how it might work after reading this smart contract.

    {contract PropertyTransfer contract PropertyTransfer

     

    Address public DA; // The owner shall be DA. We will initialize this variable's value using the address of the user who is going to use it. e.g. Let's take, for example, DA itself.

     

    uint256 Public TotalNoOfProperty // Total no of properties covered by a DA at any time. After verification, they should be increased according to the allotment of their respective owners.

    // The constructor code below is only run when the contract has been created.

    {function PropertyTransfer() function PropertyTransfer()

    // Setting the contract owner as DA.

    // modifier to check the tx is coming from the DA(owner) or not| Use the modifier to verify that the tx comes from the DA (owner) or .}

    {modifier onlyOwner()Modifier onlyOwner()

    require(msg.sender == DA);

    _;}

    // This structure can be used to store a lot more than the name

    {struct Propertystruct Property

    string name; //keeping the address and map of the property. We will provide the name of the property

    // We're keeping the count for each address

    }

    mapping(address => mapping(uint256=>Property)) public propertiesOwner; // we shall have the properties mapped against each address by its name and it's individual count.

    mapping(address => uint256) individualCountOfPropertyPerOwner; // how many property does a particular person hold

    event PropertyAlloted(address indexed _verifiedOwner, uint256 indexed _totalNoOfPropertyCurrently, string _nameOfProperty, string _msg);

    event PropertyTransferred(address indexed _from, address indexed _to, string _propertyName, string _msg);

    // This will give us an exact count of the property that any address has at any given time

    function getPropertyCountOfAnyAddress(address _ownerAddress) constant returns (uint256){

    uintcount=0;

    for(uint i =0; i

    if(propertiesOwner[_ownerAddress][i].isSold != true)

    count++;

    }

    Return count;

    }

    // This function will be called by DA after verification

    function allotProperty(address _verifiedOwner, string _propertyName)

    OnlyOwner

    {

    propertiesOwner[_verifiedOwner][individualCountOfPropertyPerOwner[_verifiedOwner]++].name = _propertyName;

    totalNoOfProperty++;

    PropertyAlloted(_verifiedOwner,individualCountOfPropertyPerOwner[_verifiedOwner], _propertyName, "property allotted successfully");

    }

    // Check if the owner has the property. If yes, then return the index

    {function isOwner(address _checkOwnerAddress, string _propertyName) constant returns (uint)Function isOwner (address _checkOwnerAddress string _propertyName constant returns (uint).

    uint i ;

    bool flag ;

    For(i=0; i

    if(propertiesOwner[_checkOwnerAddress][i].isSold == true){

    break;

    }

    flag = stringsEqual(propertiesOwner[_checkOwnerAddress][i].name,_propertyName);

    if(flag == true){

    break;

    }

    }

    if(flag == true){

    Return i;

    }

    {else other

    Return 999999999 // We expect that no one will own this many properties .

    }}

    // Check the equality between two strings in Solidity

    {function stringsEqual (string a1, string a2) constant returns (bool) function stringsEqual(string a1, string A2) constant returns (bool).

    Return sha3 (a1) == return sha3 (a2) true:false;

    }

    // Transfer the property to the new owners

    // todo: Change from to msg.sender

    function transferProperty

    returns (bool, uint)

    {

    uint256 CheckOwner = isOwner (msg.sender; _propertyName);

    bool flag;

     

    if(checkOwner != 999999999 && propertiesOwner[msg.sender][checkOwner].isSold == false){

    // Step 1. Remove the property from the current owner.

    // Step 2. Step 2: Assign the property to the new owner.

    propertiesOwner[msg.sender][checkOwner].isSold = true;

    propertiesOwner[msg.sender][checkOwner].name = “Sold”;// really nice finding. We can’t use empty strings

    propertiesOwner[_to][individualCountOfPropertyPerOwner[_to]++].name = _propertyName;

    flag = true;

    PropertyTransferred(msg.sender , _to, _propertyName, "Owner has been changed." );

    }

    {else other

    flag = false;

    PropertyTransferred(msg.sender , _to, _propertyName, "Owner doesn't own the property." );}

    return (flag, checkOwner);

    }}

    You’ve now programmed a way for property to be transferred on a distributed network. That’s awesome! !

    It is clear that there are significant opportunities for smart contracts to change aspects of society.

    This Smart Contract blog is now closed. I hope you enjoyed this blog and found it useful.

     

source https://www.edureka.co/blog/smart-contracts/

See also  Frequently Asked Questions about POS Systems
Partners : cloudbasedpos.com | Blockchain solutions | Fintech | queenbests | | cloudbasedpos.com | Queenbests | Shopify POS | Woocommerce point of sale | Firearms POS | Firearms Point of sale | Magento POS |