Skip to main content

Solidity

Solidity is an object-oriented programming language designed for developing smart contracts that run on Ethereum. It is highly influenced by C++, JavaScript and Python and used for implementing small contracts on various blockchain platforms such as Ethereum. It has been made to target the Ethereum Virtual Machine. It is a statically- typed curly braces programming language which supports inheritance, libraries and also complex user-defined types among other features.
You can create contracts for uses such as crowdfunding, voting and multi-signature wallets with the help of Solidity.

Methods to setup Solidity compiler on CentOS machine :


Method 1 - npm / Node.js

Install Node.js by using the following commands -

#### First install epel-release
$sudo yum install epel-release

Now install nodejs

$sudo yum install nodejs

Next install npm (Nodejs Package Manager )

$sudo yum install npm

Finally verify installation

$npm --version

> After installation, you will get an output something like this -

3.10.10

> Install solc(Solidity compiler)

$sudonpm install -g solc

> The above command will install `solcjs` program. Now you can test your solidity by issuing following command -

$solcjs-version


> If everything goes fine, then this will print something as follows -

0.5.2+commit.1df8f40c.Emscripten.clang


### Method 2 - Docker Image
> Following is the command to pull a Solidity Docker Image and start using it to start with Solidity programming -

$docker pull ethereum/solc:stable

> You can verify whether a docker image is downloaded or not by using the following command -

$docker run ethereum/solc:stable-version

> This will print something as follows -

$ docker run ethereum/solc:stable -version

solc, the solidity compiler commandlineinterfaceVersion: 0.5.2+commit.1df8f40c.Linux.g++

## Solidity - Basic Syntax :
---
A Solidity source files can contain an any number of _import directives_, _pragma directives_ and _contract definitions_.
Following is an example of a simple source file of Solidity -

pragma solidity >=0.4.0 <0.6.0; contract SimpleStorage { uint storedData; function set(uint x) public { storedData = x; } function get() public view returns (uint) { return storedData; } }

## Importing Files :
---
Solidity supports import statements similar to those available in JavaScript.
> The following statement imports all global symbols from "filename".
```js
import "filename";

The following example makes a new global symbol symbolName whose members are all the global symbols from "filename".

import * as symbolName from "filename";

Use import "./x" as x; to import a file from the same directory as the current file.

Reserved Keywords :

Following are the reserved keywords in Solidity -

  • abstract
  • auto
  • default
  • implements
  • macro
  • of
  • reference
  • static
  • typedef
  • after
  • case
  • define
  • match
  • override

References :


  1. tutorialspoint