SlideShare a Scribd company logo
1 of 34
Write Smart Contract
with Solidity on
Ethereum
Murughan Palaniachari
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
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
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
Smart Contract
@Murughan_P
@Murughan_P
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
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
Solidity Compiler
Contract
Definition
Solidity Compiler
Application Binary
Interface
Byte code
@Murughan_P
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
Hello World
pragma solidity ^0.4.24;
contract HelloWorld
{
function WelCome() public view
returns(string)
{
return "Hello World";
}
}
@Murughan_P
Write & compile HelloWorld program in Remix
@Murughan_P
Deploy & run HelloWorld program in Remix
@Murughan_P
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
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
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
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
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
Data types
bool
uint/int
bytes
address
mapping
enum
struct
bytes/String
@Murughan_P
Functions
function WelCome() public pure returns(string)
{
return "Hello World";
}
Function Name Function Type Return Types
@Murughan_P
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
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
{
}
}
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;
}
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
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
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
{
}
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
Wallet – Install Metamask to Chrome Browser
@Murughan_P
Get free ether for Ropsten Ethereum test
network
https://faucet.metamask.io/
@Murughan_P
Deploy HelloWorld to Ropsten TestNet
@Murughan_P
Deploy HelloWorld to Ropsten TestNet
@Murughan_P
View your Contract
https://ropsten.etherscan.io/ @Murughan_P
Deploy HelloWorld to Ethereum Main Network
@Murughan_P
WARNING: this will deducted real Ether, do this only when you want to deploy to Main
Reference/Further reading
• Solidity-Programming-Essentials
• https://solidity.readthedocs.io/en/v0.4.24/index.html
• https://www.ethereum.org/

More Related Content

What's hot

Ethereum Tutorial - Ethereum Explained | What is Ethereum? | Ethereum Explain...
Ethereum Tutorial - Ethereum Explained | What is Ethereum? | Ethereum Explain...Ethereum Tutorial - Ethereum Explained | What is Ethereum? | Ethereum Explain...
Ethereum Tutorial - Ethereum Explained | What is Ethereum? | Ethereum Explain...
Simplilearn
 
PoW vs. PoS - Key Differences
PoW vs. PoS - Key DifferencesPoW vs. PoS - Key Differences
PoW vs. PoS - Key Differences
101 Blockchains
 
Blockchain Tutorial For Beginners - 2 | Blockchain Technology | Blockchain Tu...
Blockchain Tutorial For Beginners - 2 | Blockchain Technology | Blockchain Tu...Blockchain Tutorial For Beginners - 2 | Blockchain Technology | Blockchain Tu...
Blockchain Tutorial For Beginners - 2 | Blockchain Technology | Blockchain Tu...
Simplilearn
 

What's hot (20)

Ethereum Tutorial - Ethereum Explained | What is Ethereum? | Ethereum Explain...
Ethereum Tutorial - Ethereum Explained | What is Ethereum? | Ethereum Explain...Ethereum Tutorial - Ethereum Explained | What is Ethereum? | Ethereum Explain...
Ethereum Tutorial - Ethereum Explained | What is Ethereum? | Ethereum Explain...
 
Smart Contracts Programming Tutorial | Solidity Programming Language | Solidi...
Smart Contracts Programming Tutorial | Solidity Programming Language | Solidi...Smart Contracts Programming Tutorial | Solidity Programming Language | Solidi...
Smart Contracts Programming Tutorial | Solidity Programming Language | Solidi...
 
PoW vs. PoS - Key Differences
PoW vs. PoS - Key DifferencesPoW vs. PoS - Key Differences
PoW vs. PoS - Key Differences
 
Hyperledger Fabric Architecture
Hyperledger Fabric ArchitectureHyperledger Fabric Architecture
Hyperledger Fabric Architecture
 
Blockchain consensus algorithms
Blockchain consensus algorithmsBlockchain consensus algorithms
Blockchain consensus algorithms
 
Hyperledger Fabric and Tools
Hyperledger Fabric and ToolsHyperledger Fabric and Tools
Hyperledger Fabric and Tools
 
Ethereum-Cryptocurrency (All about Ethereum)
Ethereum-Cryptocurrency (All about Ethereum) Ethereum-Cryptocurrency (All about Ethereum)
Ethereum-Cryptocurrency (All about Ethereum)
 
Programming smart contracts in solidity
Programming smart contracts in solidityProgramming smart contracts in solidity
Programming smart contracts in solidity
 
Blockchain Tutorial For Beginners - 2 | Blockchain Technology | Blockchain Tu...
Blockchain Tutorial For Beginners - 2 | Blockchain Technology | Blockchain Tu...Blockchain Tutorial For Beginners - 2 | Blockchain Technology | Blockchain Tu...
Blockchain Tutorial For Beginners - 2 | Blockchain Technology | Blockchain Tu...
 
Blockchain 101 | Blockchain Tutorial | Blockchain Smart Contracts | Blockchai...
Blockchain 101 | Blockchain Tutorial | Blockchain Smart Contracts | Blockchai...Blockchain 101 | Blockchain Tutorial | Blockchain Smart Contracts | Blockchai...
Blockchain 101 | Blockchain Tutorial | Blockchain Smart Contracts | Blockchai...
 
Blockchain - HyperLedger Fabric
Blockchain - HyperLedger FabricBlockchain - HyperLedger Fabric
Blockchain - HyperLedger Fabric
 
Smart contracts using web3.js
Smart contracts using web3.jsSmart contracts using web3.js
Smart contracts using web3.js
 
Solidity Simple Tutorial EN
Solidity Simple Tutorial ENSolidity Simple Tutorial EN
Solidity Simple Tutorial EN
 
Blockchain Explained | Blockchain Simplified | Blockchain Technology | Blockc...
Blockchain Explained | Blockchain Simplified | Blockchain Technology | Blockc...Blockchain Explained | Blockchain Simplified | Blockchain Technology | Blockc...
Blockchain Explained | Blockchain Simplified | Blockchain Technology | Blockc...
 
Smart contract
Smart contractSmart contract
Smart contract
 
Introduction to Blockchain and Smart Contracts
Introduction to Blockchain and Smart ContractsIntroduction to Blockchain and Smart Contracts
Introduction to Blockchain and Smart Contracts
 
Blockchain concepts
Blockchain conceptsBlockchain concepts
Blockchain concepts
 
Decentralized applications 101: How and why to build a DApp
Decentralized applications 101: How and why to build a DAppDecentralized applications 101: How and why to build a DApp
Decentralized applications 101: How and why to build a DApp
 
Developing applications with Hyperledger Fabric SDK
Developing applications with Hyperledger Fabric SDKDeveloping applications with Hyperledger Fabric SDK
Developing applications with Hyperledger Fabric SDK
 
Blockchain Technology
Blockchain TechnologyBlockchain Technology
Blockchain Technology
 

Similar to Write smart contract with solidity on Ethereum

Write Smart Contract with Solidity on Ethereum
Write Smart Contract with Solidity on EthereumWrite Smart Contract with Solidity on Ethereum
Write Smart Contract with Solidity on Ethereum
劉 維仁
 

Similar to Write smart contract with solidity on Ethereum (20)

Solidity programming Language for beginners
Solidity programming Language for beginnersSolidity programming Language for beginners
Solidity programming Language for beginners
 
solidity programming solidity programming
solidity programming solidity programmingsolidity programming solidity programming
solidity programming solidity programming
 
Write Smart Contract with Solidity on Ethereum
Write Smart Contract with Solidity on EthereumWrite Smart Contract with Solidity on Ethereum
Write Smart Contract with Solidity on Ethereum
 
How to design, code, deploy and execute a smart contract
How to design, code, deploy and execute a smart contractHow to design, code, deploy and execute a smart contract
How to design, code, deploy and execute a smart contract
 
Hyperledger
HyperledgerHyperledger
Hyperledger
 
02 - Introduction to Hyperledger Fabric
02 - Introduction to Hyperledger Fabric  02 - Introduction to Hyperledger Fabric
02 - Introduction to Hyperledger Fabric
 
Ergo Hong Kong meetup
Ergo Hong Kong meetupErgo Hong Kong meetup
Ergo Hong Kong meetup
 
Ethereum
EthereumEthereum
Ethereum
 
The Decentralized Developer Toolbox by Petros Ring
The Decentralized Developer Toolbox by Petros RingThe Decentralized Developer Toolbox by Petros Ring
The Decentralized Developer Toolbox by Petros Ring
 
Upgradability of smart contracts: A Review
Upgradability of smart contracts: A ReviewUpgradability of smart contracts: A Review
Upgradability of smart contracts: A Review
 
Interesting Facts About Ethereum Smart contract Development
Interesting Facts About Ethereum Smart contract DevelopmentInteresting Facts About Ethereum Smart contract Development
Interesting Facts About Ethereum Smart contract Development
 
solidity programming.pptx
solidity programming.pptxsolidity programming.pptx
solidity programming.pptx
 
Blockchain architected
Blockchain architectedBlockchain architected
Blockchain architected
 
KrakenD API Gateway
KrakenD API GatewayKrakenD API Gateway
KrakenD API Gateway
 
Smart contracts in Solidity
Smart contracts in SoliditySmart contracts in Solidity
Smart contracts in Solidity
 
What is Solidity basic concepts_.pdf
What is Solidity basic concepts_.pdfWhat is Solidity basic concepts_.pdf
What is Solidity basic concepts_.pdf
 
Blockchain Explorer
Blockchain ExplorerBlockchain Explorer
Blockchain Explorer
 
Hyper ledger project
Hyper ledger projectHyper ledger project
Hyper ledger project
 
Hyperledger Architecture > Volume 1
Hyperledger Architecture > Volume 1Hyperledger Architecture > Volume 1
Hyperledger Architecture > Volume 1
 
Hyperledger arch wg_paper_1_consensus
Hyperledger arch wg_paper_1_consensusHyperledger arch wg_paper_1_consensus
Hyperledger arch wg_paper_1_consensus
 

More from Murughan Palaniachari

More from Murughan Palaniachari (16)

Blockchain on aws
Blockchain on awsBlockchain on aws
Blockchain on aws
 
Azure Blockchain Workbench
Azure Blockchain WorkbenchAzure Blockchain Workbench
Azure Blockchain Workbench
 
Create and Deploy your ERC20 token with Ethereum
Create and Deploy your ERC20 token with EthereumCreate and Deploy your ERC20 token with Ethereum
Create and Deploy your ERC20 token with Ethereum
 
Agile scrum with Microsoft VSTS
Agile scrum with Microsoft VSTSAgile scrum with Microsoft VSTS
Agile scrum with Microsoft VSTS
 
Git version control and trunk based approach with VSTS
Git version control and trunk based approach with VSTSGit version control and trunk based approach with VSTS
Git version control and trunk based approach with VSTS
 
DevOps culture
DevOps cultureDevOps culture
DevOps culture
 
DevOps continuous learning and experimentation
DevOps continuous learning and experimentationDevOps continuous learning and experimentation
DevOps continuous learning and experimentation
 
DevOps ci/cd with Microsoft vsts and azure
DevOps ci/cd with Microsoft vsts and azureDevOps ci/cd with Microsoft vsts and azure
DevOps ci/cd with Microsoft vsts and azure
 
DevOps the phoenix project simulation
DevOps the phoenix project simulationDevOps the phoenix project simulation
DevOps the phoenix project simulation
 
Dev ops culture and principles of high performing organization
Dev ops culture and principles of high performing organizationDev ops culture and principles of high performing organization
Dev ops culture and principles of high performing organization
 
DevOps culture in high performing organization and adoption & growth of DevOps
DevOps culture in high performing organization and adoption & growth of DevOps DevOps culture in high performing organization and adoption & growth of DevOps
DevOps culture in high performing organization and adoption & growth of DevOps
 
Zero downtime release through DevOps Continuous Delivery
Zero downtime release through DevOps Continuous DeliveryZero downtime release through DevOps Continuous Delivery
Zero downtime release through DevOps Continuous Delivery
 
DevOps principles and practices - accelerate flow
DevOps principles and practices - accelerate flowDevOps principles and practices - accelerate flow
DevOps principles and practices - accelerate flow
 
DevOps game marshmallow challenge
DevOps game marshmallow challengeDevOps game marshmallow challenge
DevOps game marshmallow challenge
 
DevOps game lego
DevOps game legoDevOps game lego
DevOps game lego
 
Top 10 devops values
Top 10 devops valuesTop 10 devops values
Top 10 devops values
 

Recently uploaded

Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 

Recently uploaded (20)

Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation Strategies
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 

Write smart contract with solidity on Ethereum

  • 1. Write Smart Contract with Solidity on Ethereum Murughan Palaniachari
  • 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
  • 12. Write & compile HelloWorld program in Remix @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
  • 20. Functions function WelCome() public pure returns(string) { return "Hello World"; } Function Name Function Type Return Types @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
  • 28. Wallet – Install Metamask to Chrome Browser @Murughan_P
  • 29. Get free ether for Ropsten Ethereum test network https://faucet.metamask.io/ @Murughan_P
  • 30. Deploy HelloWorld to Ropsten TestNet @Murughan_P
  • 31. Deploy HelloWorld to Ropsten TestNet @Murughan_P
  • 33. Deploy HelloWorld to Ethereum Main Network @Murughan_P WARNING: this will deducted real Ether, do this only when you want to deploy to Main
  • 34. Reference/Further reading • Solidity-Programming-Essentials • https://solidity.readthedocs.io/en/v0.4.24/index.html • https://www.ethereum.org/