Smartym Pro  /  Blog  /  Blockchain  / 
smart contract development

Ethereum Blockchain platform: delving into Smart Contract development

Blockchain is an open distributed ledger that maintains a continuously increasing number of transactions and data records. In fact, it is a technology of decentralized data storage that provides a high-security level and enables data manipulation occurred within the certain rules.

This confidence is ensured by the fact that data array is stored at once for each Blockchain participant, meaning that it won’t be enough to simply replace the entire array in one place.

And each subsequent piece of data, a so-called block, contains a hash of the previous block, providing the following advantages:

  • It’s impossible to substitute an intermediate block in the finished chain;
  • A block can’t be changed without changing its hash, therefore it is impossible to make it without breaking the chain integrity.

Having great prospects for a plenty of industries, Blockchain technology provides a wide range of abilities for developers. Let’s take an Ethereum Blockchain platform, serving as an extension (it is not a Blockchain competitor) to Blockchain and enabling smart contracts.

 

Ethereum Smart Contracts

 

Smart contracts are programs with contract clauses, determined by the parties and written into the lines of code. While each network participant has access to all the data, they automatically trace agreements’ completion and remove any intermediaries.

In fact, an Ethereum smart contract represents an ordinary contract, but the fixing goes not legally, but technically. So, there is no need for a notary or any other authorized administrator, recognized by both parties.

In Blockchain, smart contracts are responsible for data manipulation. Each smart contract has a small database and provides methods for changing its data.

Since contracts are replicated across all nodes, their databases also are. Every time a user calls a method from a contract, thus changing the data, this command is replicated and repeated by the entire network. This process enables to create a distributed consensus to fulfill agreements.

Noteworthy that Ethereum smart contracts describe what data to store in the ledger as well as a set of functions for performing operations on these data. Functions’ execution is carried out through the interface, provided by each contract and generated from the source code separately from the compilation. Also, the interface allows executing of the binary code.

Data changes occur via transactions, that require such 3 essential elements as transaction sender, transaction recipient, and the amount of currency.

More precisely, each transaction has the following structure:

  • Transaction sender
  • Transaction recipient
  • The amount of sending currency
  • Price per gas unit (gas is the payment received by the network participant for calling a smart contract code)
  • Gas limit per transaction
  • Arbitrary data (optional)

The execution of transactions needs the efforts of internal currency (ether – ETH) and waiting when another block (created by the miner) with your transaction is included in the chain.

The contract code is executed on the miner’s computer in the Ethereum virtual machine (EVM), and the minor receives a commission in return (gas).

When sending a transaction you define the amount of ETH you would pay for each gas unit as well as the maximum amount of gas you are ready to pay.

As the payment for gas is the payment for miners’ work, the more you set, the more priority your transaction has. Now, let’s get insight in smart contract development.

 

Smart Contract Development

 

Few are aware that even in Bitcoin programmers can create smart contracts. However, since Script programming language isn’t Turing-complete and “loses” many advantages and abilities, it’s better not to use it.

An Ethereum Blockchain platform provides Turing-complete languages for smart contract development. All you need for working on this service are Ethereum tokens, called ethers, that cover expenses for using computational performance.

So, to connect to Blockchain and become a network participant download an Ethereum digital wallet, for example, Mist (now it is the most popular wallet), that allows to issue your own tokens, manage user accounts, and use decentralized applications.

Decentralized applications, or DApps, are apps, created on the base of smart contracts. Simply put, a DApps represents smart contracts’ logic plus some user interface. Using decentralized applications and having certain equipment installed, a user can get access to Blockchain on his/her PC.

When rolling out Mist, you will have to choose between two networks, Main network and Test network. While in Main network ether costs money, in Test you won’t have to pay for ETH. Besides, mining here takes less time comparing to one in a real network.

Thus, select a Test network and choose between Ropsten and Rinkeby. Before starting all network data are downloaded on your computer. For Testnet Ropsten it is approximately 7 GB, for Testnet Rinkeby is 800 MB, and for a real network, the number is over 40 GB.

Both Ropsten and Rinkeby have their pros and cons. As Testnet Rinkeby doesn’t require mining, it’s more fast, simple, and convenient. However, Ropsten is more similar to a real network, enabling to use and “feel” its peculiarities.

In Ropsten, to get ethers (after the synchronization) you need to choose a menu option Develop->Start mining. Working with Rinkeby go to www.rinkeby.io, Crypto Faucet, and follow network instruction.

Once you have some amount of ethers on your account, you can get down to smart contract development. The most popular and just the best programming language for this purpose is Solidity, a statically typed object-oriented programming language, similar to JavaScript and C++ by its syntax. What’s important, it’s provided by active support and quality documentation.

Here is an example of a simple smart contract, developed on an Ethereum Blockchain platform using the simplest cryptocurrency form. Everyone can send coins to each other without registration, but only the contract creator can generate a cryptocurrency from scratch.

 

The example of a simple smart contract

 

pragma solidity ^0.4.0;

contract Coin {

// The keyword “public” makes those variables

// readable from outside.

address public minter;

mapping (address => uint) public balances;

// Events allow light clients to react on

// changes efficiently.

event Sent(address from, address to, uint amount);

// This is the constructor whose code is

// run only when the contract is created.

function Coin() {

    minter = msg.sender;

}

function mint(address receiver, uint amount) {

    if (msg.sender != minter) return;

    balances[receiver] += amount;
}

function send(address receiver, uint amount) {

    if (balances[msg.sender] < amount) return;

    balances[msg.sender] -= amount;

    balances[receiver] += amount;

    Sent(msg.sender, receiver, amount);

}

}

Smart contracts can be successfully used in a variety of cases, including voting, crowdfunding, financial and data transactions, digital wallets, decentralized workforce, and so on.

Find out more about their practical usage in our post: “Ethereum Blockchain Platform: How will it change the business environment?” 

Also, learn what are the restrictions of Ethereum smart contracts and how to avoid them.

Hope, the article has been useful and interesting. If you have a Blockchain-based project idea, feel free to apply to us and receive smart recommendations. Having expertise in Blockchain development, we are ready to offer you our knowledge and experience.