Complete Solidity Tutorial | Ethereum Solidity | Solidity Blockchain Development | Smart Contract
What is Ethereum?
Ethereum is a decentralized ie. blockchain platform that runs smart contracts i.e. applications that run exactly as programmed without any possibility of downtime, censorship, fraud or third-party interference.
The Ethereum Virtual Machine (EVM)
The Ethereum Virtual Machine, also known as EVM, is the runtime environment for smart contracts in Ethereum. The Ethereum Virtual Machine focuses on providing security and executing untrusted code by computers all over the world.
The EVM specialised in preventing Denial-of-service attacks and ensures that programs do not have access to each other's state, ensuring communication can be established without any potential interference.
The Ethereum Virtual Machine has been designed to serve as a runtime environment for smart contracts based on Ethereum.
What is Smart Contract?
A smart contract is a computer protocol intended to digitally facilitate, verify, or enforce the negotiation or performance of a contract. Smart contracts allow the performance of credible transactions without third parties. These transactions are trackable and irreversible.
The concept of smart contracts was first proposed by Nick Szabo in 1994. Szabo is a legal scholar and cryptographer known for laying the groundwork for digital currency.
It is fine if you do not understand Smart Contract right now, we will go into more detail later.
Remix is a browser-based compiler and IDE that enables users to build Ethereum contracts with Solidity language and to debug transactions.
A Solidity source files can contain any number of contract definitions, import directives and pragma directives.
Let's start with a simple source file of Solidity. Following is an example of a Solidity file −
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;}}
Pragma
The first line is a pragma directive which tells that the source code is written for Solidity version 0.4.0 or anything newer that does not break functionality up to, but not including, version 0.6.0.
A pragma directive is always local to a source file and if you import another file, the pragma from that file will not automatically apply to the importing file.
So a pragma for a file which will not compile earlier than version 0.4.0 and it will also not work on a compiler starting from version 0.5.0 will be written as follows −
pragma solidity ^0.4.0;
Here the second condition is added by using ^.
Contract
A Solidity contract is a collection of code (its functions) and data (its state) that resides at a specific address on the Ethereumblockchain.
The line uintstoredData declares a state variable called stored data of type uint and the functions set and get can be used to modify or retrieve the value of the variable.
Importing Files
Though the above example does not have an import statement Solidity supports import statements that are very similar to those available in JavaScript.
The following statement imports all global symbols from "filename".
import "filename";
The following example creates a new global symbol symbolName whose members are all the global symbols from "filename".
import * as symbolName from "filename";
To import a file x from the same directory as the current file, use import "./x" as x;. If you use import "x" as x; instead, a different file could be referenced in a global "include directory".
Solidity - First Application
We're using Remix IDE to Compile and Run our Solidity Codebase.
Step 1 − Copy the given code in Remix IDE Code Section.
Example
pragma solidity ^0.5.0;contract SolidityTest {constructor() public{}function getResult() public view returns(uint){uint a = 1;uint b = 2;uint result = a + b;return result;}}
Step 2 − Under Compile Tab, click Start to Compile button.
Step 3 − Under Run Tab, click Deploy button.
Step 4 − Under Run Tab, Select SolidityTest at 0x... in drop-down.
Step 5 − Click getResult Button to display the result.
Output
0: uint256: 3
Comments
Post a Comment