Skip to content

Solidity Language Extended Reading

BlockGeek edited this page Apr 24, 2019 · 2 revisions

Solidity is a kind of high-level smart contract language operating on HPB main chain -- virtual machine (EVM). This language is first widely used on Ethereum main chain. Now almost all blockchain projects support Solidity language and HPB also perfectly supports this high-level language.

Language Characteristics

Solidity is an object-oriented language whose syntax is similar to that of Javascript. But as a really decentralized contract that runs on the network, it has a quite a few differences and here are some:

  • Ethereum is based on account instead of UTXO, so there is a special Address type. It is used to locate users, contracts and contract codes (the contract itself is also an account).
  • Since the language embedded framework is payable, it provides some keywords, such as payable, which enables it to be directly payable at the language level.
  • Storage uses blockchain on the network and data can be permanently stored in every state, so it is necessary to decide whether the variable occupies memory or blockchain.
  • The operating environment is based on a decentralized network which highlights the contract or function as the method to call. This is because a previous simple function call is replaced by code execution in a node on the network.
  • The last major difference lies in its exception mechanism. In case of abnormalities, all execution will be withdrawn to maintain the atomicity of contract execution so as to avoid data inconsistency in the intermediate state.

Example

The following is the example of a simple contract HelloWorld programmed in Solidity language:

pragma solidity ^0.4.0;

contract HelloWorld{
    uint balance;
    function update(uint amount) returns (address, uint){
        balance += amount;
        return (msg.sender, balance);
    }
}

For more details about Solidity language, please visit Official English website or Official Chinese website

Clone this wiki locally