Smart contract and Solidity
-
Upload
- -
Category
Technology
-
view
366 -
download
1
Transcript of Smart contract and Solidity
![Page 2: Smart contract and Solidity](https://reader034.fdocuments.net/reader034/viewer/2022052318/5a6779d77f8b9a656a8b55dd/html5/thumbnails/2.jpg)
Smart Contract
![Page 3: Smart contract and Solidity](https://reader034.fdocuments.net/reader034/viewer/2022052318/5a6779d77f8b9a656a8b55dd/html5/thumbnails/3.jpg)
Smart Contract
•
• 1994 Nick Szabo
•
•
Transaction
![Page 4: Smart contract and Solidity](https://reader034.fdocuments.net/reader034/viewer/2022052318/5a6779d77f8b9a656a8b55dd/html5/thumbnails/4.jpg)
Smart Contract
![Page 5: Smart contract and Solidity](https://reader034.fdocuments.net/reader034/viewer/2022052318/5a6779d77f8b9a656a8b55dd/html5/thumbnails/5.jpg)
•
•
•
![Page 6: Smart contract and Solidity](https://reader034.fdocuments.net/reader034/viewer/2022052318/5a6779d77f8b9a656a8b55dd/html5/thumbnails/6.jpg)
•
• Contacting external services, Enforcing on-chain payments
• (= )
![Page 7: Smart contract and Solidity](https://reader034.fdocuments.net/reader034/viewer/2022052318/5a6779d77f8b9a656a8b55dd/html5/thumbnails/7.jpg)
Ethereum Contract
![Page 8: Smart contract and Solidity](https://reader034.fdocuments.net/reader034/viewer/2022052318/5a6779d77f8b9a656a8b55dd/html5/thumbnails/8.jpg)
Bitcoin Contract
• Script
• OPCODE
• Output Input Public Key HASH CHECKSIG Private Key TRUE
![Page 9: Smart contract and Solidity](https://reader034.fdocuments.net/reader034/viewer/2022052318/5a6779d77f8b9a656a8b55dd/html5/thumbnails/9.jpg)
Ethereum Contract
• Turing Complete
• APPLY(S)=S’ (APPLY: , S: , S’: )
• Smart Contract
• Loop , Contract Account, Block Transaction , Gas
![Page 10: Smart contract and Solidity](https://reader034.fdocuments.net/reader034/viewer/2022052318/5a6779d77f8b9a656a8b55dd/html5/thumbnails/10.jpg)
Loop Gas
• Operation Gas Cost
• Transaction fee = Gas_used * Gas_price[Gwei]1 Gwei = 0.000000001 ETH
• Gas = Gas
![Page 11: Smart contract and Solidity](https://reader034.fdocuments.net/reader034/viewer/2022052318/5a6779d77f8b9a656a8b55dd/html5/thumbnails/11.jpg)
Smart Contract Code• Smart Contract
Smart Contract Code
• EVM(Ethereum Virtual Machine) EVM
• • Mutan: C Deprecated• LLL: Low level OPCODE• Serpent: Python • Solidity: Javascript
![Page 13: Smart contract and Solidity](https://reader034.fdocuments.net/reader034/viewer/2022052318/5a6779d77f8b9a656a8b55dd/html5/thumbnails/13.jpg)
Solidity
![Page 14: Smart contract and Solidity](https://reader034.fdocuments.net/reader034/viewer/2022052318/5a6779d77f8b9a656a8b55dd/html5/thumbnails/14.jpg)
Solidity Hello Worldpragma 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
![Page 15: Smart contract and Solidity](https://reader034.fdocuments.net/reader034/viewer/2022052318/5a6779d77f8b9a656a8b55dd/html5/thumbnails/15.jpg)
Solidity Hello Worldpragma 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
![Page 16: Smart contract and Solidity](https://reader034.fdocuments.net/reader034/viewer/2022052318/5a6779d77f8b9a656a8b55dd/html5/thumbnails/16.jpg)
Solidity Hello Worldpragma 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
![Page 17: Smart contract and Solidity](https://reader034.fdocuments.net/reader034/viewer/2022052318/5a6779d77f8b9a656a8b55dd/html5/thumbnails/17.jpg)
Solidity Hello Worldpragma 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
![Page 18: Smart contract and Solidity](https://reader034.fdocuments.net/reader034/viewer/2022052318/5a6779d77f8b9a656a8b55dd/html5/thumbnails/18.jpg)
Solidity Hello Worldpragma 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
![Page 19: Smart contract and Solidity](https://reader034.fdocuments.net/reader034/viewer/2022052318/5a6779d77f8b9a656a8b55dd/html5/thumbnails/19.jpg)
Solidity Code → Byte Code
SMART CONTRACT (http://goodjoon.tistory.com/261)
![Page 20: Smart contract and Solidity](https://reader034.fdocuments.net/reader034/viewer/2022052318/5a6779d77f8b9a656a8b55dd/html5/thumbnails/20.jpg)
SMART CONTRACT (http://goodjoon.tistory.com/261)
dApp
Contract Meta data
![Page 21: Smart contract and Solidity](https://reader034.fdocuments.net/reader034/viewer/2022052318/5a6779d77f8b9a656a8b55dd/html5/thumbnails/21.jpg)
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
![Page 22: Smart contract and Solidity](https://reader034.fdocuments.net/reader034/viewer/2022052318/5a6779d77f8b9a656a8b55dd/html5/thumbnails/22.jpg)
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
![Page 23: Smart contract and Solidity](https://reader034.fdocuments.net/reader034/viewer/2022052318/5a6779d77f8b9a656a8b55dd/html5/thumbnails/23.jpg)
(3)— (https://medium.com/@soonhyungjung/ - - -3- - - -44a9d58d687a)
![Page 24: Smart contract and Solidity](https://reader034.fdocuments.net/reader034/viewer/2022052318/5a6779d77f8b9a656a8b55dd/html5/thumbnails/24.jpg)
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
![Page 25: Smart contract and Solidity](https://reader034.fdocuments.net/reader034/viewer/2022052318/5a6779d77f8b9a656a8b55dd/html5/thumbnails/25.jpg)
payable & modifierpragma 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 .
![Page 26: Smart contract and Solidity](https://reader034.fdocuments.net/reader034/viewer/2022052318/5a6779d77f8b9a656a8b55dd/html5/thumbnails/26.jpg)
TODO
• Solidity Voting
• Campaign & Crowdfunding
• Custom Token
![Page 27: Smart contract and Solidity](https://reader034.fdocuments.net/reader034/viewer/2022052318/5a6779d77f8b9a656a8b55dd/html5/thumbnails/27.jpg)
• 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/)