Using solidity programming language, smart contract development is deployed on ethereum, the blockchain platform. This article provides a quick start on how to develop smart contracts with real life examples and experience the power of Ethereum to build a decentralized and trusted transaction technology. Smart contracts are essentially “computer trading agreements that enforce the terms of the contract”. All users on the blockchain can see the blockchain-based smart contract.

A Smart contract is a computer protocol designed to propagate, validate, or enforce contracts in an informationalized manner. Smart contracts allow trusted transactions to take place without a third party. These transactions are traceable and irreversible. The concept of smart contracts was first proposed by Nick Szabo in 1994. Smart contracts aim to provide security over traditional contract methods and reduce other transaction costs associated with contracts.

Since all users on the blockchain can see the blockchain-based smart contract. This also makes all vulnerabilities, including security holes, visible and may not be quickly fixed. Such attacks are difficult to resolve quickly.

In June 2016, The DAOEther bug caused a loss of $50 million while developers tried to reach a consensus on a solution. The DAO’s program had a delay before the hacker deleted the funds. A hard fork in Ethereum’s software completed the attacker’s cash recovery before the time limit expired. Issues in ethereum smart contracts include contract programming Solidity, compiler errors, Ethereum virtual machine errors, attacks on blockchain networks, immutable program errors, and other attacks that have not yet been documented.

Classic examples of smart contract deployment include:

  1. Ethereum implements an almost Turing-complete language on its blockchain, a prominent framework for smart contracts.
  2. RootStock (RSK) is a smart contract platform that connects to the Bitcoin blockchain via side-chain technology. RSK is compatible with smart contracts created for Ethereum.

If you are a blockchain developer, I suggest you watch this tutorial: Ethereum DApp Primer

A typical solidity programming example or example of the solidity language for smart contracts is the following proxy voting system, which makes some remarks:

Website example, https://solidity.readthedocs.io/en/develop/solidity-by-example.html#possible-improvements

This example is up to date and mainly uses some of the features of the Ethereum programming language Solidity. The example implements a voting smart contract that is an electronic voting system. The main problem is how to allocate proper permissions to the right people and prevent tampering. This example demonstrates how to vote by proxy. The counting process is automatic and completely transparent.

Functionally it first creates a contract for voting, and the originator is called a chairperson let’s just call the chairperson and assign permissions to each individual address. Each voter can vote for himself or entrust someone he trusts. The code returns the bill or initiative that received the most votes.

Pragma solidity ^ 0.4.22; /// @title Voting with delegation. Contract Ballot {// This declares a new complextype whichWill defines a complex type // be usedfor// It will represent a single voter. Struct Voter {uint weight; // Weight is accumulated by delegating weight. //if trueThat person already voted if the value istrueThe voter has already voted. // delegate to the delegated delegated vote. } // This is a votetype forStruct proposal {bytes32 name; // short name (up to 32 bytes) The name of the proposal uint voteCount; // Address public Chairperson; // Address public Chairperson; // This declares a greater state variable that // stores a 'Voter' structforMapping (address => Voter) public Voter; // A dynamically-sized array of `Proposal` structs. [] public proposals; /// Create a new ballot to choose one of `proposalNames`. Pass in the bill name to define a voting objectfunctionBallot(bytes32[] proposalNames) public { chairperson = msg.sender; voters[chairperson].weight = 1; // For each of the provided proposal names, // create a new proposal object and add it // to the end of the array. Creates a motion with the name of the incoming motion and adds it to the array of motions defined earlierfor(uint i = 0; i < proposalNames.length; i++) { // `Proposal({... })` creates a temporary // Proposal object and `proposals.push(...) ` // appends it to the end of `proposals`. Proposals. Push (Proposal({name: proposalNames[I], voteCount: 0})) } } // Give `voter` the right to vote on this ballot. // May only be called by `chairperson`. Assign voting rights to voters, an operation that only the chairman can dofunction giveRightToVote(address voter) public {
        // If the first argument of `require` evaluates
        // to `false`, execution terminates and all
        // changes to the state and to Ether balances
        // are reverted.
        // This used to consume all gas in old EVM versions, but
        // not anymore.
        // It is often a good idea to use `require` to check if
        // functions are called correctly.
        // As a second argument, you can also provide an
        // explanation about what went wrong.
        require(
            msg.sender == chairperson,
            "Only chairperson can give right to vote."); require( ! voters[voter].voted,"The voter already voted."); require(voters[voter].weight == 0); voters[voter].weight = 1; } /// Delegate your vote to the voter `to`. A proxy vote is given to another voterfunctionDelegate (address to) public {// Assigns reference to identify the assert originator and terminate the program Voter storage sender = voters[msg.sender] if it voted. require(! sender.voted,"You already voted."); require(to ! = msg.sender,"Self-delegation is disallowed.");

        // Forward the delegation as long as
        // `to` also delegated.
        // In general, such loops are very dangerous,
        // because if they run too long, they might
        // need more gas than is available in a block.
        // In this case, the delegation will not be executed,
        // but in other situations, such loops might
        // cause a contract to get "stuck" completely.
        while(voters[to].delegate ! = address(0)) { to = voters[to].delegate; // We found a loopinThe delegation, not allowed. The originator and the delegation must not be the same, otherwise the program requires (to! = msg.sender,"Found loop in delegation."); } // Since 'sender' is a reference, this // modifies' voters[MSGtrue;
        sender.delegate = to;
        Voter storage delegate_ = voters[to];
        if(delegate_.votes) {// If the delegate already voted, // directly add to the number of votes, The total number of votes and the corresponding weights of the proposals[Delegate_.vote]. VoteCount += sender.weight; }else{ // If the delegate did not vote yet, // add to her weight. If no vote has been cast, the originator weight assigns the value to the principal delegate_.weight += sender.weight; } } /// Give your vote (including votes delegated to you) /// to proposal `proposals[proposal].name`. Vote for a billfunctionvote(uint proposal) public { Voter storage sender = voters[msg.sender]; require(! sender.voted,"Already voted.");
        sender.voted = true; sender.vote = proposal; // If `proposal` is out of the range of the array, // this will throw automatically and revert all // changes. proposals[proposal].voteCount += sender.weight; } /// @dev Computes the winning proposal taking all /// previous votes into account. Find the bill with the most votesfunction winningProposal() public view
            returns (uint winningProposal_)
    {
        uint winningVoteCount = 0;
        for (uint p = 0; p < proposals.length; p++) {
            if (proposals[p].voteCount > winningVoteCount) {
                winningVoteCount = proposals[p].voteCount;
                winningProposal_ = p;
            }
        }
    }

    // Calls winningProposal() function to get the index
    // of the winner contained in the proposals array and then
    // returns the name of the winner
    functionwinnerName() public view returns (bytes32 winnerName_) { winnerName_ = proposals[winningProposal()].name; }}Copy the code

If this code can be basically understood, it should be able to directly start the learning process of Ethereum blockchain, share two tutorials, can be learned through online programming environment:

1. Ethereum DApp development suitable for blockchain novices:

Xc.hubwiz.com/course/5a95…

2. Use blockchain, IPFS, Node.js and MongoDB to build ethereum DApp e-commerce platform:

Xc.hubwiz.com/course/5abb…

If you want to join the ethereum technology development group can add wechat to pull you into the group.