SlideShare a Scribd company logo
Smart Contract & Solidity
Solidity
winterj.me@gmail.com
JungWinter
Smart Contract
Smart Contract
• 

• 1994 Nick Szabo

• 

• 



Transaction 

Smart Contract
• 



• 

•
•


• Contacting external services, Enforcing on-chain
payments 

• (= )
Ethereum Contract
Bitcoin Contract
• Script 

• OPCODE 

• Output Input Public Key  HASH
 CHECKSIG  Private Key TRUE
Ethereum Contract
•
 Turing Complete 

• APPLY(S)=S’ 

(APPLY: , S: , S’: )

• Smart Contract

• Loop , Contract Account, Block Transaction
, Gas
Loop Gas
• Operation Gas Cost 

• Transaction fee = Gas_used * Gas_price[Gwei]

1 Gwei = 0.000000001 ETH

• Gas 

= Gas
Smart Contract Code
• Smart Contract 

Smart Contract Code 

• EVM(Ethereum Virtual Machine) 

EVM 

• 

• Mutan: C Deprecated

• LLL: Low level OPCODE

• Serpent: Python 

• Solidity: Javascript
Smart Contract
(https://maniara.github.io/sc_lecture.pdf)
Solidity
Solidity Hello World
pragma solidity ^0.4.0;
contract SimpleStorage {
uint storedData;
function set(uint x) {
storedData = x;
}
function get() constant returns (uint retVal) {
return storedData;
}
}
pragma
constant
returns
uint
http://solidity.readthedocs.io/en/develop/introduction-to-smart-contracts.html
Solidity Hello World
pragma solidity ^0.4.0;
contract SimpleStorage {
uint storedData;
function set(uint x) {
storedData = x;
}
function get() constant returns (uint retVal) {
return storedData;
}
}
pragma
constant
returns
uint




^0.4.0 Solidity 0.5.0 

npm 

	 ^1.2.3 → >=1.2.3 <2.0.0

	 ^0.2.3 → >=0.2.3 <0.3.0

	 ^0.0.3 → >=0.0.3 <0.0.4
Solidity Hello World
pragma solidity ^0.4.0;
contract SimpleStorage {
uint storedData;
function set(uint x) {
storedData = x;
}
function get() constant returns (uint retVal) {
return storedData;
}
}
pragma
constant
returns
uint
constant 

State 

constant Gas 

Modifier 

. 0.4.16 constant view pure constant view alias 

pure pure
Solidity Hello World
pragma solidity ^0.4.0;
contract SimpleStorage {
uint storedData;
function set(uint x) {
storedData = x;
}
function get() constant returns (uint retVal) {
return storedData;
}
}
pragma
constant
returns
uint
return 



1
Solidity Hello World
pragma solidity ^0.4.0;
contract SimpleStorage {
uint storedData;
function set(uint x) {
storedData = x;
}
function get() constant returns (uint retVal) {
return storedData;
}
}
pragma
constant
returns
uint


uint unsigned int uint8 uint256 

uint uint256
Solidity Code → Byte Code
SMART CONTRACT (http://goodjoon.tistory.com/261)
SMART CONTRACT (http://goodjoon.tistory.com/261)
dApp
Contract Meta data
pragma solidity ^0.4.0;
contract Coin{
address public minter;
mapping (address => uint ) public balances;
event Sent (address from, address to, uint amount);
function Coin() {
minter = msg.sender;
}
function mint(address receiver, uint amount) {
if (msg.sender != minter) return;
balances[receiver] += amount;
}
function send(address receiver, uint amount) {
if (balances[msg.sender] < amount) return;
balances[msg.sender] -= amount;
balances[receiver] += amount;
Sent(msg.sender, receiver, amount);
}
}
http://solidity.readthedocs.io/en/develop/introduction-to-smart-contracts.html
address
public
mapping
event
msg
address
public
mapping
event
msg
http://solidity.readthedocs.io/en/develop/introduction-to-smart-contracts.html
20byte( ) balance( ), transfer( )
Python dict . mapping(address => uint) address key uint
value dict
public 

address public minter; function minter() returns (address) { return
minter; }
), msg.sender , msg.value
Wei(Ether) 

.data, .gas, .sig
. listener
(3)—   

(https://medium.com/@soonhyungjung/ - - -3- - - -44a9d58d687a)
pragma solidity^0.4.0;
contract Bank {
uint totalDeposit;
mapping(address=> uint) balanceOf;
function deposit() payable {
balanceOf[msg.sender] += msg.value;
totalDeposit += msg.value;
}
function withdraw(uint _amount) payable {
balanceOf[msg.sender] -= _amount;
totalDeposit -= _amount;
msg.sender.call.value(_amount)();
// msg.sender.transfer(_amount);
}
function getTotalBalance()
constant returns(uint) {
return totalDeposit;
}
function getBalance(address _account)
constant returns(uint) {
return balanceOf[_account];
}
}
payable
payable & modifier
pragma solidity ^0.4.11;
contract Purchase {
address public seller;
modifier onlySeller() { // Modifier
require(msg.sender == seller);
_;
}
function abort() onlySeller { // Modifier usage
// ...
}
}
Solidity modifier  payable 

(https://medium.com/@ggogun/solidity -modifier- -payable-d892a833920c)
Python Decorator, Ruby on Rails before_filter 

_; modifier .
TODO
• Solidity Voting 

• Campaign & Crowdfunding 

• Custom Token
• Why Many Smart Contract Use Cases Are Simply Impossible (https://
www.coindesk.com/three-smart-contract-misconceptions/)

• Calculating Costs in Ethereum Contracts (https://hackernoon.com/ether-purchase-
power-df40a38c5a2f)

• Gas Cost from Yellow Paper (http://bit.ly/2xfBHWN)

• SMART CONTRACT - (http://goodjoon.tistory.com/253)

• SMART CONTRACT (http://goodjoon.tistory.com/261)

• dApp (http://www.chaintalk.io/archive/lecture/86)

• Solidity (https://www.gitbook.com/book/ggs134/solidityguide)

• Solidity (https://solidity.readthedocs.io/en/develop/)

More Related Content

PPTX
Solidity Simple Tutorial EN
PPTX
Solidity
PDF
Blockchain Coding Dojo - BlockchainHub Graz
PDF
Ethereum Contracts - Coinfest 2015
PPTX
Smart Contract programming 101 with Solidity #PizzaHackathon
PPTX
Hands on with smart contracts 2. Presentation for the Blockchain Applications...
PPTX
Dex and Uniswap
PPTX
Hands on with smart contracts
Solidity Simple Tutorial EN
Solidity
Blockchain Coding Dojo - BlockchainHub Graz
Ethereum Contracts - Coinfest 2015
Smart Contract programming 101 with Solidity #PizzaHackathon
Hands on with smart contracts 2. Presentation for the Blockchain Applications...
Dex and Uniswap
Hands on with smart contracts

What's hot (20)

PPTX
Accessing decentralized finance on Ethereum blockchain
PPTX
Smart Contracts with Solidity hands-on training session
PPTX
Hello world contract
PPTX
Solidity Security and Best Coding Practices
PPTX
Hands on with Smart Contracts session #3
PPTX
Blockchain and smart contracts day 2
PPT
PDF
Libbitcoin slides
DOCX
Oop lab report
PDF
Meteor and Bitcoin (Lightning Talk)
PPTX
Principais vulnerabilidades em Smart Contracts e como evitá-las
PDF
PDF
Js interpreter interpreted
PPTX
Advanced smart contract
PPTX
Oracles
PDF
The Ring programming language version 1.6 book - Part 25 of 189
PDF
05 - Qt External Interaction and Graphics
DOCX
Jarmo van de Seijp Shadbox ERC223
PPT
Qtum How To Make EVM Run On UTXO Model - Patrick Dai
PDF
The Ring programming language version 1.5.3 book - Part 92 of 184
Accessing decentralized finance on Ethereum blockchain
Smart Contracts with Solidity hands-on training session
Hello world contract
Solidity Security and Best Coding Practices
Hands on with Smart Contracts session #3
Blockchain and smart contracts day 2
Libbitcoin slides
Oop lab report
Meteor and Bitcoin (Lightning Talk)
Principais vulnerabilidades em Smart Contracts e como evitá-las
Js interpreter interpreted
Advanced smart contract
Oracles
The Ring programming language version 1.6 book - Part 25 of 189
05 - Qt External Interaction and Graphics
Jarmo van de Seijp Shadbox ERC223
Qtum How To Make EVM Run On UTXO Model - Patrick Dai
The Ring programming language version 1.5.3 book - Part 92 of 184
Ad

Similar to Smart contract and Solidity (20)

PDF
“Create your own cryptocurrency in an hour” - Sandip Pandey
PPTX
Introduction to Solidity and Smart Contract Development (9).pptx
PPTX
Ethereum
 
PDF
How to Write & Deploy a Smart Contract
PDF
Programming smart contracts in solidity
ODP
Stefano Maestri - Blockchain and smart contracts, what they are and why you s...
PPTX
Web3 - Solidity - 101.pptx
PDF
Writing smart contracts
PDF
Interesting Facts About Ethereum Smart contract Development
PDF
Ethereum Solidity: an intro to the bread and butter language for smart contracts
PPTX
The Ethereum Blockchain - Introduction to Smart Contracts and Decentralized A...
PDF
What is Solidity basic concepts_.pdf
PPTX
Kriptovaluták, hashbányászat és okoscicák
DOCX
solidity programming solidity programming
PDF
Smart contracts in Solidity
PDF
solutions.hamburg | web3 // smart contracts // ethereum
PPTX
Zoltán Balázs - Ethereum Smart Contract Hacking Explained like I’m Five
PPTX
Explain Ethereum smart contract hacking like i am a five
PPTX
Hands on with smart contracts
PDF
How to be a smart contract engineer
“Create your own cryptocurrency in an hour” - Sandip Pandey
Introduction to Solidity and Smart Contract Development (9).pptx
Ethereum
 
How to Write & Deploy a Smart Contract
Programming smart contracts in solidity
Stefano Maestri - Blockchain and smart contracts, what they are and why you s...
Web3 - Solidity - 101.pptx
Writing smart contracts
Interesting Facts About Ethereum Smart contract Development
Ethereum Solidity: an intro to the bread and butter language for smart contracts
The Ethereum Blockchain - Introduction to Smart Contracts and Decentralized A...
What is Solidity basic concepts_.pdf
Kriptovaluták, hashbányászat és okoscicák
solidity programming solidity programming
Smart contracts in Solidity
solutions.hamburg | web3 // smart contracts // ethereum
Zoltán Balázs - Ethereum Smart Contract Hacking Explained like I’m Five
Explain Ethereum smart contract hacking like i am a five
Hands on with smart contracts
How to be a smart contract engineer
Ad

Recently uploaded (20)

PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PPT
Teaching material agriculture food technology
PDF
Encapsulation theory and applications.pdf
PDF
Machine learning based COVID-19 study performance prediction
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PDF
Spectral efficient network and resource selection model in 5G networks
PDF
Electronic commerce courselecture one. Pdf
PPTX
Cloud computing and distributed systems.
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
Per capita expenditure prediction using model stacking based on satellite ima...
Teaching material agriculture food technology
Encapsulation theory and applications.pdf
Machine learning based COVID-19 study performance prediction
Advanced methodologies resolving dimensionality complications for autism neur...
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
Spectral efficient network and resource selection model in 5G networks
Electronic commerce courselecture one. Pdf
Cloud computing and distributed systems.
Understanding_Digital_Forensics_Presentation.pptx
20250228 LYD VKU AI Blended-Learning.pptx
Building Integrated photovoltaic BIPV_UPV.pdf
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Diabetes mellitus diagnosis method based random forest with bat algorithm
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Dropbox Q2 2025 Financial Results & Investor Presentation

Smart contract and Solidity

  • 1. Smart Contract & Solidity Solidity winterj.me@gmail.com JungWinter
  • 3. Smart Contract • • 1994 Nick Szabo • • 
 
 Transaction 

  • 6. • • Contacting external services, Enforcing on-chain payments • (= )
  • 8. Bitcoin Contract • Script • OPCODE • Output Input Public Key  HASH  CHECKSIG  Private Key TRUE
  • 9. Ethereum Contract •  Turing Complete • APPLY(S)=S’ 
 (APPLY: , S: , S’: ) • Smart Contract • Loop , Contract Account, Block Transaction , Gas
  • 10. Loop Gas • Operation Gas Cost • Transaction fee = Gas_used * Gas_price[Gwei]
 1 Gwei = 0.000000001 ETH • Gas 
 = Gas
  • 11. Smart Contract Code • Smart Contract 
 Smart Contract Code • EVM(Ethereum Virtual Machine) 
 EVM • • Mutan: C Deprecated • LLL: Low level OPCODE • Serpent: Python • Solidity: Javascript
  • 14. Solidity Hello World pragma solidity ^0.4.0; contract SimpleStorage { uint storedData; function set(uint x) { storedData = x; } function get() constant returns (uint retVal) { return storedData; } } pragma constant returns uint http://solidity.readthedocs.io/en/develop/introduction-to-smart-contracts.html
  • 15. Solidity Hello World pragma solidity ^0.4.0; contract SimpleStorage { uint storedData; function set(uint x) { storedData = x; } function get() constant returns (uint retVal) { return storedData; } } pragma constant returns uint ^0.4.0 Solidity 0.5.0 npm ^1.2.3 → >=1.2.3 <2.0.0 ^0.2.3 → >=0.2.3 <0.3.0 ^0.0.3 → >=0.0.3 <0.0.4
  • 16. Solidity Hello World pragma solidity ^0.4.0; contract SimpleStorage { uint storedData; function set(uint x) { storedData = x; } function get() constant returns (uint retVal) { return storedData; } } pragma constant returns uint constant State constant Gas Modifier . 0.4.16 constant view pure constant view alias pure pure
  • 17. Solidity Hello World pragma solidity ^0.4.0; contract SimpleStorage { uint storedData; function set(uint x) { storedData = x; } function get() constant returns (uint retVal) { return storedData; } } pragma constant returns uint return 1
  • 18. Solidity Hello World pragma solidity ^0.4.0; contract SimpleStorage { uint storedData; function set(uint x) { storedData = x; } function get() constant returns (uint retVal) { return storedData; } } pragma constant returns uint uint unsigned int uint8 uint256 uint uint256
  • 19. Solidity Code → Byte Code SMART CONTRACT (http://goodjoon.tistory.com/261)
  • 21. pragma solidity ^0.4.0; contract Coin{ address public minter; mapping (address => uint ) public balances; event Sent (address from, address to, uint amount); function Coin() { minter = msg.sender; } function mint(address receiver, uint amount) { if (msg.sender != minter) return; balances[receiver] += amount; } function send(address receiver, uint amount) { if (balances[msg.sender] < amount) return; balances[msg.sender] -= amount; balances[receiver] += amount; Sent(msg.sender, receiver, amount); } } http://solidity.readthedocs.io/en/develop/introduction-to-smart-contracts.html address public mapping event msg
  • 22. address public mapping event msg http://solidity.readthedocs.io/en/develop/introduction-to-smart-contracts.html 20byte( ) balance( ), transfer( ) Python dict . mapping(address => uint) address key uint value dict public address public minter; function minter() returns (address) { return minter; } ), msg.sender , msg.value Wei(Ether) 
 .data, .gas, .sig . listener
  • 24. pragma solidity^0.4.0; contract Bank { uint totalDeposit; mapping(address=> uint) balanceOf; function deposit() payable { balanceOf[msg.sender] += msg.value; totalDeposit += msg.value; } function withdraw(uint _amount) payable { balanceOf[msg.sender] -= _amount; totalDeposit -= _amount; msg.sender.call.value(_amount)(); // msg.sender.transfer(_amount); } function getTotalBalance() constant returns(uint) { return totalDeposit; } function getBalance(address _account) constant returns(uint) { return balanceOf[_account]; } } payable
  • 25. payable & modifier pragma solidity ^0.4.11; contract Purchase { address public seller; modifier onlySeller() { // Modifier require(msg.sender == seller); _; } function abort() onlySeller { // Modifier usage // ... } } Solidity modifier  payable (https://medium.com/@ggogun/solidity -modifier- -payable-d892a833920c) Python Decorator, Ruby on Rails before_filter _; modifier .
  • 26. TODO • Solidity Voting • Campaign & Crowdfunding • Custom Token
  • 27. • Why Many Smart Contract Use Cases Are Simply Impossible (https:// www.coindesk.com/three-smart-contract-misconceptions/) • Calculating Costs in Ethereum Contracts (https://hackernoon.com/ether-purchase- power-df40a38c5a2f) • Gas Cost from Yellow Paper (http://bit.ly/2xfBHWN) • SMART CONTRACT - (http://goodjoon.tistory.com/253) • SMART CONTRACT (http://goodjoon.tistory.com/261) • dApp (http://www.chaintalk.io/archive/lecture/86) • Solidity (https://www.gitbook.com/book/ggs134/solidityguide) • Solidity (https://solidity.readthedocs.io/en/develop/)