2. How Blockchain works
Node
2
Node
5,000
Node
N
Node
25
Transaction is
Broadcasted
to Blockchain
peer-to-peer
network
User
Requests
A transaction
Transaction will be validated by any
node in this Network through some
algorithms and smart contract
Once the transaction is verified by
multiple Nodes in the Blockchain
network then new block gets added to
chain and replicated across all the nodes
User
Requested
Transaction
Is completed
Node
500
Node
5
Node
1
Node
20,00
0
@Murughan_P
3. Ethereum Blockchain framework
Ethereum is a decentralized platform that
runs smart contracts: applications that run
exactly as programmed without any
possibility of downtime, censorship, fraud or
third-party interference.
Solidity-Programming-Essentials @Murughan_P
4. Smart Contract
Agreements are written as Smart Contracts.
Smart Contracts are business logic
Transactions are validated against Smart Contract
Digitized and codified rules of transaction between
accounts
In Ethereum world smart contracts are written in language
called Solidity and deployed into Ethereum network
@Murughan_P
7. Where you can
use Smart
Contract
@Murughan_P
Financial derivatives
Insurance premiums
Breach contracts
Property law
Credit enforcement
Financial services
Legal processes
Crowdfunding agreements
And more
8. Solidity – Language to write Smart Contract
Solidity is a contract-oriented, high-level language for
implementing smart contracts.
It was influenced by C++, Python and JavaScript and is designed to
target the Ethereum Virtual Machine (EVM).
Solidity is statically typed, supports inheritance, libraries and
complex user-defined types among other features.
Written in .sol files
https://solidity.readthedocs.io/en/v0.4.24/index.html
@Murughan_P
10. Remix web tool
Remix is
a web
browser
based
IDE that
allows
you to
write Solidity smart contracts
Test smart contract
Deploy
Run the smart contracts.
https://remix.ethereum.org/
@Murughan_P
11. Hello World
pragma solidity ^0.4.24;
contract HelloWorld
{
function WelCome() public view
returns(string)
{
return "Hello World";
}
}
@Murughan_P
13. Deploy & run HelloWorld program in Remix
@Murughan_P
14. Modify the
HelloWorld
contract to accept
input message
from user
pragma solidity ^0.4.24;
contract HelloWorld
{
function GetHelloWorld(string
message) public view returns(string)
{
return message;
}
}
@Murughan_P
15. Comments
There are the
following three types
of comment in
Solidity:
Single-line comments
Multiline comments
Ethereum Natural Specification (Natspec)
Single-line comments are denoted by a double forward slash //,
Multiline comments are denoted using /* and */.
Natspec has two formats: ///
@Murughan_P
16. Import
The import keyword helps import other Solidity files and we can
access its code within the current Solidity file and code. This helps us
write modular Solidity code.
The syntax for using import is
as follows:
import <<filename>> ;
File names can be fully explicit
or implicit paths.
import
'CommonLibrary.sol';
@Murughan_P
17. State variables
Variables in programming refer to storage location that can contain values.
These values can be changed during runtime.
State variables that are permanently stored in a blockchain/Ethereum ledger
by miners.
State variables store the current values of the contract.
The allocated memory for a state variable is statically assigned and it cannot
change (the size of memory allocated) during the lifetime of the contract.
@Murughan_P
18. State variable access
internal: this variable can only be used
within current contract functions and
any contract that inherits from them.
int internal
StateVariable ;
private
int public
stateIntVariable ;
constant: This qualifier makes state
variables immutable. bool constant
hasIncome = true;
@Murughan_P
21. Function Types
public - Anyone can call this function
private - Only this contract can call this function.
view - This function returns data and does not modify the contract's data
constant - This function returns data and does not modify the contract's data
pure - Function will not modify or even read the contract's data
payable - When someone call this function they might send ether along
@Murughan_P
22. Constructors
Solidity supports declaring a constructor within a contract.
Constructors are optional in Solidity and the compiler induces a default constructor when no constructor is
explicitly defined.
The constructor is executed once while deploying the contract.
@Murughan_P
contract HelloWorld {
function HelloWorld() public
{
}
}
23. Modifier
In Solidity, a modifier is always associated with a function.
A modifier in programming languages refers to a construct that changes the behavior of the
executing code.
@Murughan_P
modifier isOwner {
// require(msg.sender == owner);
if(msg.sender == owner) {
_;
}
}
function AssignDoubleValue(int _data) public
isOwner {
mydata = _data * 2;
}
24. Conditions
function GetHelloWorld(int age) public view returns(string)
{
if(age > 21)
return "you are eligible to drive";
else
return "you are not eligible to drive";
}
@Murughan_P
25. Loops – While, Do While, For loop
while (age < 21) {
return "you are not eligible to drive";
}
do {
return "you are not eligible to drive";
}
while (age < 21);
for(int i=0; i<= age; i++)
{
//statement
}
@Murughan_P
26. Inheritance
Solidity supports inheritance between smart contracts.
Inheritance is the process of defining multiple contracts that are related to each other through
parent-child relationships.
Solidity supports multiple types of inheritance, including multiple inheritance.
@Murughan_P
pragma solidity ^0.4.24;
contract ParentContract
{
}
contract ChildContract is ParentContract
{
}
27. Polymorphism
Polymorphism means having multiple forms of functions.
contract helloFunctionPloymorphism
{
function getVariableData(int8 data) public constant
returns(int8 output)
{
return 1;
}
function getVariableData(int16 data) public constant
returns(int16 output)
{
return 12;
}
}
@Murughan_P