Hello world contract

Gene Leybzon
Gene LeybzonSoftware Architect and Experienced Technical Leader
“HELLO WORLD” SMART
CONTRACT
Hands-on introduction to
the world of Solidity and
Smart contract
programming on Ethereum
PLAN FOR TODAY
Blockchain introduction for Engineers
Understand basis Etherium concepts
Selenium Language
Create your first contract
Compile
Test
BLOCKCHAIN
INTRODUCTION
• Why?
• What?
• How?
WHY BLOCKCHAIN IS A BIG DEAL
“Bitcoin is a technological tour de force.”
– Bill Gates
”I think the fact that within the bitcoin universe an algorithm replaces
the function of the government …[that] is actually pretty cool.”
- Al Gore
“[Bitcoin] is a remarkable cryptographic achievement… The ability to
create something which is not duplicable in the digital world has
enormous value…Lot’s of people will build businesses on top of that.”
- Eric Schmidt
BLOCKCHAIN IS
Ledger of facts
Ledger of facts replicated across large number of
computers
Ledger of facts replicated across large number of
computers connected as peer-to-peer network
Ledger of facts replicated across large number of
computers connected as peer-to-peer network that
implements consensus algorithm that can securely
identify sender and receiver of facts
FACT
S
Monetary
transactio
n
Content
hash
Signature
Asset
informatio
n
Ownership
Agreemen
t
Contract
IS IT JUST ANOTHER SHARED
DATABASE?
NOT JUST ANOTHER
DATABASE
Multiple
Writers
Non-trusting
writers
Disintermediati
on
Interaction
between
transactions
Conflict
resolution
Blockchain is a source of truth
Blockchain Use Cases
HOW?
Blocks
Decentralized consensus
Byzantine fault tolerance.
CHAIN OF TRANSACTIONS
TIMESTAMPS
Introduction to
Smart Contracts
Smart Contract Definition
Smart contract are
applications that run
exactly as programmed
without any possibility of
downtime, censorship,
fraud or third party
interference.
EXAMPLE OF A CONTRACT
EXAMPLE OF SMART
CONTRACT (TOKENS)
CONCEPTS
• Accounts
• Contracts
• Messages
TWO TYPES OF ACCOUNTS
Account
StorageBalance Code
<>
Externally Owned Account
StorageBalance
Account
StorageBalance Code
<>
Contract
StorageBalance Code
<>
CONTRACTS
Contracts are accounts that contain
code
Store the state
• Example:
keeps account
balance
Source of
notifications
(events)
• Example:
messaging
service that
forwards only
messages when
certain
conditions are
met
Mapping -
relationship
between users
• Example:
mapping real-
world financial
contract to
Etherium
contract
Act like a
software library
• Example:
return
calculated value
based on
message
arguments
CALLS AND MESSAGES
Contract A Contract B
Message Call
• Source
• Target
• Data Payload
• Ether
• Gas
• Return Data
Externally
owned
account
Message CallSend Transaction
Call
WHAT CONTRACT CAN DO?
Read internal state
contract
ReadStateDemo {
uint public state;
function read() {
console.log(“State:
"+state);
}
}
Modify internal
State
contract
ModStateDemo {
uint public state;
function update() {
state=state+1;
}
}
Consume message
contract
ReadStateDemo {
uint public state;
function hi() {
console.log(“Hello
from: “
"+msg.sender + “
to “ + msg.
receiver);
}
}
Trigger execution
of another contract
contract CallDemo {
function
send(address
receiver, uint
amount) public {
Sent(msg.sender,
receiver, amount);
}
}
CONTRACT LANGUAGES
Solidity
Serpent
LLL
Bytecodes
Etherium Virtual
Machine (EVM)
REGISTRARS (ETHEREUM NAME SERVICE, ENS)
1. Send ether to an address in
Metamask (soon: MEW, Mist, Bitfinex)
1. Use it inside your own contracts to
resolve names of other contracts and
addresses
2. Store contract ABIs for easy lookup
using the ethereum-ens library
3. Address of a Swarm site
Use Cases
Registry
Registar
Resolver
ETHER
• Wei: 1
• Ada: 1000
• Fentoether: 1000
• Kwei: 1,000
• Mwei: 1,000,000
• Babbage:
1,000,000
• Pictoether: 1,000,000
• Shannon: 1,000,000,000
• Gwei: 1,000,000,000
• Nano: 1,000,000,000
• Szabo: 1,000,000,000,000
• Micro: 1,000,000,000,000
• Microether: 1,000,000,000,000
• Finney: 1,000,000,000,000,000
• Milli: 1,000,000,000,000,000
• Milliether: 1,000,000,000,000,000
• Ether:
1,000,000,000,000,000,000
Wei = 10-18 Ether
GAS
step 1 Default amount of gas to pay for an execution
cycle
stop 0 Nothing paid for the STOP operation
suicide 0 Nothing paid for the SUICIDE operation
sha3 20 Paid for a SHA3 operation
sload 30 Paid for a SLOAD operation
sstore 100 Paid for a normal SSTORE operation
(doubled or waived sometimes)
balance 20 Paid for a BALANCE operation
create 100 Paid for a CREATE operation
call 20 Paid for a CALL operation
memory 1 Paid for every additional word when
expanding memory
txdata 5 Paid for every byte of data or code for a
transaction
Example:
300 CPU cycles = 300 gas units = 0.000006 ETH =
$0.00553
(as of 2/20/2018)
Cost of Gas as in 2018
TEST NETWORKS
Ropsten
Rinkeby
Kovan
2 MINUTE
INTRODUCTION TO
SOLIDITY
Data Types
Functions
ELEMENTARY DATA TYPES
Data Type Example
uint<M> , M=1,2,4, …, 256
int<M>, uint, int
Unsigned/signed integer uint256 counter = 1;
address 160-bit value that does not
allow any arithmetic
operations. It is suitable for
storing addresses of contracts
or keypairs belonging to
external persons
address owner = msg.sender;
bool Same as uint8 but values are 0
or 1
Bool b = 0;
fixed<M>x<N>
ufixed<M>x<N>
Signed fixed-point decimal
number of M bits
fixed128x19 f = 1.1;
bytes<M>, M=1..32 Binary of M bytes bytes32 n=123;
function Same as bytes24 Function f;
ARRAYS
Data Type Example
<type>[M] fixed-length array of fixed-
length type
byte[100]
<type>[] variable-length array of fixed-
length type
byte[]
bytes dynamic sized byte sequence bytes ab;
string dynamic sized Unicode string String s = “String”;
fixed<M>x<N>
ufixed<M>x<N>
Signed fixed-point decimal
number of M bits
fixed128x19 f = 1.1;
FUNCTIONS
Functio
ns
Consta
nt
Transactio
nal
Function Visibility
External Can be called via
transactions
Public Can be called via
messages or locally
Internal Only locally called or from
derived contracts
Private Locally called
pragma solidity^0.4.12;
contract Test {
function test(uint[20] a) public returns (uint){
return a[10]*2;
}
function test2(uint[20] a) external returns (uint){
return a[10]*2; }
}
}
HANDS-ON Code time
HELLO WORLD CONTRACT
(SOLIDITY CODE)
pragma solidity ^0.4.24;
contract Hello {
constructor() public {
// constructor
}
function sayHello() public pure returns (string) {
return 'Hello World!';
}
}
REMIX https://remix.ethereum.or
g/
REMIX https://remix.ethereum.or
g/
REMIX https://remix.ethereum.or
g/
SECOND CONTRACT
(COUNTING)
pragma solidity ^0.4.24;
contract Count {
uint public value = 0;
function plus() public returns
(uint) {
value++;
return value;
}
}
More Contracts to Work On
https://github.com/leybzon/solidity-
baby-steps/tree/master/contracts
TOKENS
• ERC20
• ERC223
• ERC721
ERC223 TOKEN
ERC223 is backwards compatible with ERC20
merges the token transfer function among wallets and contracts into one
single function ‘transfer()’
does not allow token to be transferred to a contract that does not allow
token to be withdrawn
Improvements with ERC223
• Eliminates the problem of lost tokens which happens during the transfer of ERC20 tokens to a contract
(when people mistakenly use the instructions for sending tokens to a wallet). ERC223 allows users to send
their tokens to either wallet or contract with the same function transfer, thereby eliminating the potential
for confusion and lost tokens.
• Allows developers to handle incoming token transactions, and reject non-supported tokens (not possible
with ERC20)
• Energy savings. The transfer of ERC223 tokens to a contract is a one step process rather than 2 step
process (for ERC20), and this means 2 times less gas and no extra blockchain bloating.
ERC223 TOKEN INTERFACE
contract ERC223 {
uint public totalSupply;
function balanceOf(address who) public view returns (uint);
function name() public view returns (string _name);
function symbol() public view returns (string _symbol);
function decimals() public view returns (uint8 _decimals);
function totalSupply() public view returns (uint256 _supply);
function transfer(address to, uint value) public returns (bool ok);
function transfer(address to, uint value, bytes data) public
returns (bool ok);
function transfer(address to, uint value, bytes data, string
custom_fallback) public returns (bool ok);
event Transfer(address indexed from, address indexed to, uint
value, bytes indexed data);
}
ERC721
▪People love collecting
▪Allow smart contracts to operate as tradable tokens
▪Each ERC721 is unique (non-fungible)
▪Support “ownership” functions
▪Each token is referenced by unique id
▪Tokens can have metadata (attributes)
ERC721
contract ERC721 {
event Transfer(address indexed _from, address indexed
_to, uint256 _tokenId);
event Approval(address indexed _owner, address indexed
_approved, uint256 _tokenId);
function balanceOf(address _owner) public view returns
(uint256 _balance);
function ownerOf(uint256 _tokenId) public view returns
(address _owner);
function transfer(address _to, uint256 _tokenId) public;
function approve(address _to, uint256 _tokenId) public;
function takeOwnership(uint256 _tokenId) public;
}
STAY IN
TOUCH
Gene Leybzon https://www.linkedin.com/in/leybzon/
https://www.meetup.com/Blockchain-
Applications-and-Smart-Contracts/
https://www.meetup.com/members/9074420/
https://www.leybzon.com
NEXT STEPS
http://solidity.readthedocs.ioLanguage
• Learn Solidity
Ideas
People
• Meetups
• Conferences
1 of 44

Recommended

Hands on with smart contracts by
Hands on with smart contractsHands on with smart contracts
Hands on with smart contractsGene Leybzon
79 views26 slides
Hands on with Smart Contracts session #3 by
Hands on with Smart Contracts session #3Hands on with Smart Contracts session #3
Hands on with Smart Contracts session #3Gene Leybzon
367 views38 slides
Blockchain and smart contracts day 2 by
Blockchain and smart contracts day 2Blockchain and smart contracts day 2
Blockchain and smart contracts day 2Gene Leybzon
150 views38 slides
Accessing decentralized finance on Ethereum blockchain by
Accessing decentralized finance on Ethereum blockchainAccessing decentralized finance on Ethereum blockchain
Accessing decentralized finance on Ethereum blockchainGene Leybzon
88 views37 slides
Smart Contracts with Solidity hands-on training session by
Smart Contracts with Solidity hands-on training session  Smart Contracts with Solidity hands-on training session
Smart Contracts with Solidity hands-on training session Gene Leybzon
310 views32 slides
Hands on with smart contracts 2. Presentation for the Blockchain Applications... by
Hands on with smart contracts 2. Presentation for the Blockchain Applications...Hands on with smart contracts 2. Presentation for the Blockchain Applications...
Hands on with smart contracts 2. Presentation for the Blockchain Applications...Gene Leybzon
251 views26 slides

More Related Content

What's hot

Solidity Security and Best Coding Practices by
Solidity Security and Best Coding PracticesSolidity Security and Best Coding Practices
Solidity Security and Best Coding PracticesGene Leybzon
440 views31 slides
Blockchain and Smart Contracts by
Blockchain and Smart ContractsBlockchain and Smart Contracts
Blockchain and Smart ContractsGene Leybzon
260 views22 slides
Solidity Simple Tutorial EN by
Solidity Simple Tutorial ENSolidity Simple Tutorial EN
Solidity Simple Tutorial ENNicholas Lin
1.8K views53 slides
Blockchain Coding Dojo - BlockchainHub Graz by
Blockchain Coding Dojo - BlockchainHub GrazBlockchain Coding Dojo - BlockchainHub Graz
Blockchain Coding Dojo - BlockchainHub GrazBlockchainHub Graz
878 views29 slides
Ripple by
RippleRipple
RippleGene Leybzon
174 views19 slides
Smart Contract programming 101 with Solidity #PizzaHackathon by
Smart Contract programming 101 with Solidity #PizzaHackathonSmart Contract programming 101 with Solidity #PizzaHackathon
Smart Contract programming 101 with Solidity #PizzaHackathonSittiphol Phanvilai
2.4K views53 slides

What's hot(20)

Solidity Security and Best Coding Practices by Gene Leybzon
Solidity Security and Best Coding PracticesSolidity Security and Best Coding Practices
Solidity Security and Best Coding Practices
Gene Leybzon440 views
Blockchain and Smart Contracts by Gene Leybzon
Blockchain and Smart ContractsBlockchain and Smart Contracts
Blockchain and Smart Contracts
Gene Leybzon260 views
Solidity Simple Tutorial EN by Nicholas Lin
Solidity Simple Tutorial ENSolidity Simple Tutorial EN
Solidity Simple Tutorial EN
Nicholas Lin1.8K views
Smart Contract programming 101 with Solidity #PizzaHackathon by Sittiphol Phanvilai
Smart Contract programming 101 with Solidity #PizzaHackathonSmart Contract programming 101 with Solidity #PizzaHackathon
Smart Contract programming 101 with Solidity #PizzaHackathon
Sittiphol Phanvilai2.4K views
Ethereum Contracts - Coinfest 2015 by Rob Myers
Ethereum Contracts - Coinfest 2015Ethereum Contracts - Coinfest 2015
Ethereum Contracts - Coinfest 2015
Rob Myers1.2K views
Solidity by gavofyork
SoliditySolidity
Solidity
gavofyork2.8K views
Smart contract and Solidity by 겨울 정
Smart contract and SoliditySmart contract and Solidity
Smart contract and Solidity
겨울 정1.3K views
“Create your own cryptocurrency in an hour” - Sandip Pandey by EIT Digital Alumni
“Create your own cryptocurrency in an hour” - Sandip Pandey“Create your own cryptocurrency in an hour” - Sandip Pandey
“Create your own cryptocurrency in an hour” - Sandip Pandey
EIT Digital Alumni259 views
ERC20 Token Contract by KC Tam
ERC20 Token ContractERC20 Token Contract
ERC20 Token Contract
KC Tam192 views
BlockchainDay "Ethereum Dapp - Asset Exchange YOSEMITE alpha" Session by 병완 임
BlockchainDay "Ethereum Dapp - Asset Exchange YOSEMITE alpha" Session BlockchainDay "Ethereum Dapp - Asset Exchange YOSEMITE alpha" Session
BlockchainDay "Ethereum Dapp - Asset Exchange YOSEMITE alpha" Session
병완 임462 views
Smart contracts in Solidity by Felix Crisan
Smart contracts in SoliditySmart contracts in Solidity
Smart contracts in Solidity
Felix Crisan606 views
How to be a smart contract engineer by Oded Noam
How to be a smart contract engineerHow to be a smart contract engineer
How to be a smart contract engineer
Oded Noam726 views
Ejemplos Programas Descompilados by Luis Viteri
Ejemplos Programas DescompiladosEjemplos Programas Descompilados
Ejemplos Programas Descompilados
Luis Viteri301 views
Timur Shemsedinov "Пишу на колбеках, а что... (Асинхронное программирование)" by OdessaJS Conf
Timur Shemsedinov "Пишу на колбеках, а что... (Асинхронное программирование)"Timur Shemsedinov "Пишу на колбеках, а что... (Асинхронное программирование)"
Timur Shemsedinov "Пишу на колбеках, а что... (Асинхронное программирование)"
OdessaJS Conf118 views

Similar to Hello world contract

Hands on with smart contracts by
Hands on with smart contractsHands on with smart contracts
Hands on with smart contractsGene Leybzon
157 views26 slides
Security in the blockchain by
Security in the blockchainSecurity in the blockchain
Security in the blockchainBellaj Badr
3.5K views40 slides
Ethereum by
EthereumEthereum
EthereumBrian Yap
577 views29 slides
Ethereum Solidity Fundamentals by
Ethereum Solidity FundamentalsEthereum Solidity Fundamentals
Ethereum Solidity FundamentalsEno Bassey
621 views35 slides
Ethereum by
EthereumEthereum
EthereumV C
202 views51 slides
Smart contracts using web3.js by
Smart contracts using web3.jsSmart contracts using web3.js
Smart contracts using web3.jsFelix Crisan
1K views31 slides

Similar to Hello world contract(20)

Hands on with smart contracts by Gene Leybzon
Hands on with smart contractsHands on with smart contracts
Hands on with smart contracts
Gene Leybzon157 views
Security in the blockchain by Bellaj Badr
Security in the blockchainSecurity in the blockchain
Security in the blockchain
Bellaj Badr3.5K views
Ethereum by Brian Yap
EthereumEthereum
Ethereum
Brian Yap577 views
Ethereum Solidity Fundamentals by Eno Bassey
Ethereum Solidity FundamentalsEthereum Solidity Fundamentals
Ethereum Solidity Fundamentals
Eno Bassey621 views
Ethereum by V C
EthereumEthereum
Ethereum
V C202 views
Smart contracts using web3.js by Felix Crisan
Smart contracts using web3.jsSmart contracts using web3.js
Smart contracts using web3.js
Felix Crisan1K views
Blockchain, Ethereum and Business Applications by Matthias Zimmermann
Blockchain, Ethereum and Business ApplicationsBlockchain, Ethereum and Business Applications
Blockchain, Ethereum and Business Applications
Matthias Zimmermann2.7K views
Braga Blockchain - Ethereum Smart Contracts programming by Emanuel Mota
Braga Blockchain - Ethereum Smart Contracts programmingBraga Blockchain - Ethereum Smart Contracts programming
Braga Blockchain - Ethereum Smart Contracts programming
Emanuel Mota220 views
Jerome de Tychey - Building Web3.0 with Ethereum - Codemotion Berlin 2018 by Codemotion
Jerome de Tychey - Building Web3.0 with Ethereum - Codemotion Berlin 2018Jerome de Tychey - Building Web3.0 with Ethereum - Codemotion Berlin 2018
Jerome de Tychey - Building Web3.0 with Ethereum - Codemotion Berlin 2018
Codemotion40 views
Jerome de Tychey - Building Web3.0 with Ethereum - Codemotion Berlin 2018 by Codemotion
Jerome de Tychey - Building Web3.0 with Ethereum - Codemotion Berlin 2018Jerome de Tychey - Building Web3.0 with Ethereum - Codemotion Berlin 2018
Jerome de Tychey - Building Web3.0 with Ethereum - Codemotion Berlin 2018
Codemotion168 views
An Introduction to Upgradable Smart Contracts by Mark Smalley
An Introduction to Upgradable Smart ContractsAn Introduction to Upgradable Smart Contracts
An Introduction to Upgradable Smart Contracts
Mark Smalley518 views
A Decompiler for Blackhain-Based Smart Contracts Bytecode by Shakacon
A Decompiler for Blackhain-Based Smart Contracts BytecodeA Decompiler for Blackhain-Based Smart Contracts Bytecode
A Decompiler for Blackhain-Based Smart Contracts Bytecode
Shakacon1.9K views
Algorand Smart Contracts by ssusercc3bf81
Algorand Smart ContractsAlgorand Smart Contracts
Algorand Smart Contracts
ssusercc3bf81414 views
Ethereum Block Chain by SanatPandoh
Ethereum Block ChainEthereum Block Chain
Ethereum Block Chain
SanatPandoh222 views
以太坊代幣付款委託 @ Open Source Developer Meetup #12 by Aludirk Wong
以太坊代幣付款委託 @ Open Source Developer Meetup #12以太坊代幣付款委託 @ Open Source Developer Meetup #12
以太坊代幣付款委託 @ Open Source Developer Meetup #12
Aludirk Wong1.2K views
Best practices to build secure smart contracts by Gautam Anand
Best practices to build secure smart contractsBest practices to build secure smart contracts
Best practices to build secure smart contracts
Gautam Anand426 views
"Programming Smart Contracts on Ethereum" by Anatoly Ressin from AssistUnion ... by Dace Barone
"Programming Smart Contracts on Ethereum" by Anatoly Ressin from AssistUnion ..."Programming Smart Contracts on Ethereum" by Anatoly Ressin from AssistUnion ...
"Programming Smart Contracts on Ethereum" by Anatoly Ressin from AssistUnion ...
Dace Barone312 views
Blockchain Development by preetikumara
Blockchain DevelopmentBlockchain Development
Blockchain Development
preetikumara127 views

More from Gene Leybzon

Generative AI Use cases for Enterprise - Second Session by
Generative AI Use cases for Enterprise - Second SessionGenerative AI Use cases for Enterprise - Second Session
Generative AI Use cases for Enterprise - Second SessionGene Leybzon
200 views29 slides
Generative AI Use-cases for Enterprise - First Session by
Generative AI Use-cases for Enterprise - First SessionGenerative AI Use-cases for Enterprise - First Session
Generative AI Use-cases for Enterprise - First SessionGene Leybzon
180 views17 slides
Non-fungible tokens (nfts) by
Non-fungible tokens (nfts)Non-fungible tokens (nfts)
Non-fungible tokens (nfts)Gene Leybzon
366 views47 slides
Introduction to Solidity and Smart Contract Development (9).pptx by
Introduction to Solidity and Smart Contract Development (9).pptxIntroduction to Solidity and Smart Contract Development (9).pptx
Introduction to Solidity and Smart Contract Development (9).pptxGene Leybzon
128 views26 slides
Ethereum in Enterprise.pptx by
Ethereum in Enterprise.pptxEthereum in Enterprise.pptx
Ethereum in Enterprise.pptxGene Leybzon
103 views23 slides
ERC-4907 Rentable NFT Standard.pptx by
ERC-4907 Rentable NFT Standard.pptxERC-4907 Rentable NFT Standard.pptx
ERC-4907 Rentable NFT Standard.pptxGene Leybzon
138 views25 slides

More from Gene Leybzon(20)

Generative AI Use cases for Enterprise - Second Session by Gene Leybzon
Generative AI Use cases for Enterprise - Second SessionGenerative AI Use cases for Enterprise - Second Session
Generative AI Use cases for Enterprise - Second Session
Gene Leybzon200 views
Generative AI Use-cases for Enterprise - First Session by Gene Leybzon
Generative AI Use-cases for Enterprise - First SessionGenerative AI Use-cases for Enterprise - First Session
Generative AI Use-cases for Enterprise - First Session
Gene Leybzon180 views
Non-fungible tokens (nfts) by Gene Leybzon
Non-fungible tokens (nfts)Non-fungible tokens (nfts)
Non-fungible tokens (nfts)
Gene Leybzon366 views
Introduction to Solidity and Smart Contract Development (9).pptx by Gene Leybzon
Introduction to Solidity and Smart Contract Development (9).pptxIntroduction to Solidity and Smart Contract Development (9).pptx
Introduction to Solidity and Smart Contract Development (9).pptx
Gene Leybzon128 views
Ethereum in Enterprise.pptx by Gene Leybzon
Ethereum in Enterprise.pptxEthereum in Enterprise.pptx
Ethereum in Enterprise.pptx
Gene Leybzon103 views
ERC-4907 Rentable NFT Standard.pptx by Gene Leybzon
ERC-4907 Rentable NFT Standard.pptxERC-4907 Rentable NFT Standard.pptx
ERC-4907 Rentable NFT Standard.pptx
Gene Leybzon138 views
Onchain Decentralized Governance 2.pptx by Gene Leybzon
Onchain Decentralized Governance 2.pptxOnchain Decentralized Governance 2.pptx
Onchain Decentralized Governance 2.pptx
Gene Leybzon112 views
Onchain Decentralized Governance.pptx by Gene Leybzon
Onchain Decentralized Governance.pptxOnchain Decentralized Governance.pptx
Onchain Decentralized Governance.pptx
Gene Leybzon255 views
Web3 File Storage Options by Gene Leybzon
Web3 File Storage OptionsWeb3 File Storage Options
Web3 File Storage Options
Gene Leybzon372 views
Web3 Full Stack Development by Gene Leybzon
Web3 Full Stack DevelopmentWeb3 Full Stack Development
Web3 Full Stack Development
Gene Leybzon301 views
Instantly tradeable NFT contracts based on ERC-1155 standard by Gene Leybzon
Instantly tradeable NFT contracts based on ERC-1155 standardInstantly tradeable NFT contracts based on ERC-1155 standard
Instantly tradeable NFT contracts based on ERC-1155 standard
Gene Leybzon479 views
Non-fungible tokens. From smart contract code to marketplace by Gene Leybzon
Non-fungible tokens. From smart contract code to marketplaceNon-fungible tokens. From smart contract code to marketplace
Non-fungible tokens. From smart contract code to marketplace
Gene Leybzon325 views
The Art of non-fungible tokens by Gene Leybzon
The Art of non-fungible tokensThe Art of non-fungible tokens
The Art of non-fungible tokens
Gene Leybzon308 views
Graph protocol for accessing information about blockchains and d apps by Gene Leybzon
Graph protocol for accessing information about blockchains and d appsGraph protocol for accessing information about blockchains and d apps
Graph protocol for accessing information about blockchains and d apps
Gene Leybzon207 views
OpenZeppelin + Remix + BNB smart chain by Gene Leybzon
OpenZeppelin + Remix + BNB smart chainOpenZeppelin + Remix + BNB smart chain
OpenZeppelin + Remix + BNB smart chain
Gene Leybzon254 views
Chainlink, Cosmos, Kusama, Polkadot: Approaches to the Internet of Blockchains by Gene Leybzon
Chainlink, Cosmos, Kusama, Polkadot:   Approaches to the Internet of BlockchainsChainlink, Cosmos, Kusama, Polkadot:   Approaches to the Internet of Blockchains
Chainlink, Cosmos, Kusama, Polkadot: Approaches to the Internet of Blockchains
Gene Leybzon144 views

Recently uploaded

How to think like a threat actor for Kubernetes.pptx by
How to think like a threat actor for Kubernetes.pptxHow to think like a threat actor for Kubernetes.pptx
How to think like a threat actor for Kubernetes.pptxLibbySchulze1
5 views33 slides
Affiliate Marketing by
Affiliate MarketingAffiliate Marketing
Affiliate MarketingNavin Dhanuka
17 views30 slides
The Dark Web : Hidden Services by
The Dark Web : Hidden ServicesThe Dark Web : Hidden Services
The Dark Web : Hidden ServicesAnshu Singh
14 views24 slides
information by
informationinformation
informationkhelgishekhar
10 views4 slides
Marketing and Community Building in Web3 by
Marketing and Community Building in Web3Marketing and Community Building in Web3
Marketing and Community Building in Web3Federico Ast
14 views64 slides
hamro digital logics.pptx by
hamro digital logics.pptxhamro digital logics.pptx
hamro digital logics.pptxtupeshghimire
10 views36 slides

Recently uploaded(9)

How to think like a threat actor for Kubernetes.pptx by LibbySchulze1
How to think like a threat actor for Kubernetes.pptxHow to think like a threat actor for Kubernetes.pptx
How to think like a threat actor for Kubernetes.pptx
LibbySchulze15 views
The Dark Web : Hidden Services by Anshu Singh
The Dark Web : Hidden ServicesThe Dark Web : Hidden Services
The Dark Web : Hidden Services
Anshu Singh14 views
Marketing and Community Building in Web3 by Federico Ast
Marketing and Community Building in Web3Marketing and Community Building in Web3
Marketing and Community Building in Web3
Federico Ast14 views
Building trust in our information ecosystem: who do we trust in an emergency by Tina Purnat
Building trust in our information ecosystem: who do we trust in an emergencyBuilding trust in our information ecosystem: who do we trust in an emergency
Building trust in our information ecosystem: who do we trust in an emergency
Tina Purnat110 views
IETF 118: Starlink Protocol Performance by APNIC
IETF 118: Starlink Protocol PerformanceIETF 118: Starlink Protocol Performance
IETF 118: Starlink Protocol Performance
APNIC414 views
ATPMOUSE_융합2조.pptx by kts120898
ATPMOUSE_융합2조.pptxATPMOUSE_융합2조.pptx
ATPMOUSE_융합2조.pptx
kts12089835 views

Hello world contract

  • 1. “HELLO WORLD” SMART CONTRACT Hands-on introduction to the world of Solidity and Smart contract programming on Ethereum
  • 2. PLAN FOR TODAY Blockchain introduction for Engineers Understand basis Etherium concepts Selenium Language Create your first contract Compile Test
  • 4. WHY BLOCKCHAIN IS A BIG DEAL “Bitcoin is a technological tour de force.” – Bill Gates ”I think the fact that within the bitcoin universe an algorithm replaces the function of the government …[that] is actually pretty cool.” - Al Gore “[Bitcoin] is a remarkable cryptographic achievement… The ability to create something which is not duplicable in the digital world has enormous value…Lot’s of people will build businesses on top of that.” - Eric Schmidt
  • 5. BLOCKCHAIN IS Ledger of facts Ledger of facts replicated across large number of computers Ledger of facts replicated across large number of computers connected as peer-to-peer network Ledger of facts replicated across large number of computers connected as peer-to-peer network that implements consensus algorithm that can securely identify sender and receiver of facts FACT S Monetary transactio n Content hash Signature Asset informatio n Ownership Agreemen t Contract
  • 6. IS IT JUST ANOTHER SHARED DATABASE?
  • 8. Blockchain is a source of truth
  • 14. Smart Contract Definition Smart contract are applications that run exactly as programmed without any possibility of downtime, censorship, fraud or third party interference.
  • 15. EXAMPLE OF A CONTRACT
  • 18. TWO TYPES OF ACCOUNTS Account StorageBalance Code <> Externally Owned Account StorageBalance Account StorageBalance Code <> Contract StorageBalance Code <>
  • 19. CONTRACTS Contracts are accounts that contain code Store the state • Example: keeps account balance Source of notifications (events) • Example: messaging service that forwards only messages when certain conditions are met Mapping - relationship between users • Example: mapping real- world financial contract to Etherium contract Act like a software library • Example: return calculated value based on message arguments
  • 20. CALLS AND MESSAGES Contract A Contract B Message Call • Source • Target • Data Payload • Ether • Gas • Return Data Externally owned account Message CallSend Transaction Call
  • 21. WHAT CONTRACT CAN DO? Read internal state contract ReadStateDemo { uint public state; function read() { console.log(“State: "+state); } } Modify internal State contract ModStateDemo { uint public state; function update() { state=state+1; } } Consume message contract ReadStateDemo { uint public state; function hi() { console.log(“Hello from: “ "+msg.sender + “ to “ + msg. receiver); } } Trigger execution of another contract contract CallDemo { function send(address receiver, uint amount) public { Sent(msg.sender, receiver, amount); } }
  • 23. REGISTRARS (ETHEREUM NAME SERVICE, ENS) 1. Send ether to an address in Metamask (soon: MEW, Mist, Bitfinex) 1. Use it inside your own contracts to resolve names of other contracts and addresses 2. Store contract ABIs for easy lookup using the ethereum-ens library 3. Address of a Swarm site Use Cases Registry Registar Resolver
  • 24. ETHER • Wei: 1 • Ada: 1000 • Fentoether: 1000 • Kwei: 1,000 • Mwei: 1,000,000 • Babbage: 1,000,000 • Pictoether: 1,000,000 • Shannon: 1,000,000,000 • Gwei: 1,000,000,000 • Nano: 1,000,000,000 • Szabo: 1,000,000,000,000 • Micro: 1,000,000,000,000 • Microether: 1,000,000,000,000 • Finney: 1,000,000,000,000,000 • Milli: 1,000,000,000,000,000 • Milliether: 1,000,000,000,000,000 • Ether: 1,000,000,000,000,000,000 Wei = 10-18 Ether
  • 25. GAS step 1 Default amount of gas to pay for an execution cycle stop 0 Nothing paid for the STOP operation suicide 0 Nothing paid for the SUICIDE operation sha3 20 Paid for a SHA3 operation sload 30 Paid for a SLOAD operation sstore 100 Paid for a normal SSTORE operation (doubled or waived sometimes) balance 20 Paid for a BALANCE operation create 100 Paid for a CREATE operation call 20 Paid for a CALL operation memory 1 Paid for every additional word when expanding memory txdata 5 Paid for every byte of data or code for a transaction Example: 300 CPU cycles = 300 gas units = 0.000006 ETH = $0.00553 (as of 2/20/2018) Cost of Gas as in 2018
  • 28. ELEMENTARY DATA TYPES Data Type Example uint<M> , M=1,2,4, …, 256 int<M>, uint, int Unsigned/signed integer uint256 counter = 1; address 160-bit value that does not allow any arithmetic operations. It is suitable for storing addresses of contracts or keypairs belonging to external persons address owner = msg.sender; bool Same as uint8 but values are 0 or 1 Bool b = 0; fixed<M>x<N> ufixed<M>x<N> Signed fixed-point decimal number of M bits fixed128x19 f = 1.1; bytes<M>, M=1..32 Binary of M bytes bytes32 n=123; function Same as bytes24 Function f;
  • 29. ARRAYS Data Type Example <type>[M] fixed-length array of fixed- length type byte[100] <type>[] variable-length array of fixed- length type byte[] bytes dynamic sized byte sequence bytes ab; string dynamic sized Unicode string String s = “String”; fixed<M>x<N> ufixed<M>x<N> Signed fixed-point decimal number of M bits fixed128x19 f = 1.1;
  • 30. FUNCTIONS Functio ns Consta nt Transactio nal Function Visibility External Can be called via transactions Public Can be called via messages or locally Internal Only locally called or from derived contracts Private Locally called pragma solidity^0.4.12; contract Test { function test(uint[20] a) public returns (uint){ return a[10]*2; } function test2(uint[20] a) external returns (uint){ return a[10]*2; } } }
  • 32. HELLO WORLD CONTRACT (SOLIDITY CODE) pragma solidity ^0.4.24; contract Hello { constructor() public { // constructor } function sayHello() public pure returns (string) { return 'Hello World!'; } }
  • 36. SECOND CONTRACT (COUNTING) pragma solidity ^0.4.24; contract Count { uint public value = 0; function plus() public returns (uint) { value++; return value; } }
  • 37. More Contracts to Work On https://github.com/leybzon/solidity- baby-steps/tree/master/contracts
  • 39. ERC223 TOKEN ERC223 is backwards compatible with ERC20 merges the token transfer function among wallets and contracts into one single function ‘transfer()’ does not allow token to be transferred to a contract that does not allow token to be withdrawn Improvements with ERC223 • Eliminates the problem of lost tokens which happens during the transfer of ERC20 tokens to a contract (when people mistakenly use the instructions for sending tokens to a wallet). ERC223 allows users to send their tokens to either wallet or contract with the same function transfer, thereby eliminating the potential for confusion and lost tokens. • Allows developers to handle incoming token transactions, and reject non-supported tokens (not possible with ERC20) • Energy savings. The transfer of ERC223 tokens to a contract is a one step process rather than 2 step process (for ERC20), and this means 2 times less gas and no extra blockchain bloating.
  • 40. ERC223 TOKEN INTERFACE contract ERC223 { uint public totalSupply; function balanceOf(address who) public view returns (uint); function name() public view returns (string _name); function symbol() public view returns (string _symbol); function decimals() public view returns (uint8 _decimals); function totalSupply() public view returns (uint256 _supply); function transfer(address to, uint value) public returns (bool ok); function transfer(address to, uint value, bytes data) public returns (bool ok); function transfer(address to, uint value, bytes data, string custom_fallback) public returns (bool ok); event Transfer(address indexed from, address indexed to, uint value, bytes indexed data); }
  • 41. ERC721 ▪People love collecting ▪Allow smart contracts to operate as tradable tokens ▪Each ERC721 is unique (non-fungible) ▪Support “ownership” functions ▪Each token is referenced by unique id ▪Tokens can have metadata (attributes)
  • 42. ERC721 contract ERC721 { event Transfer(address indexed _from, address indexed _to, uint256 _tokenId); event Approval(address indexed _owner, address indexed _approved, uint256 _tokenId); function balanceOf(address _owner) public view returns (uint256 _balance); function ownerOf(uint256 _tokenId) public view returns (address _owner); function transfer(address _to, uint256 _tokenId) public; function approve(address _to, uint256 _tokenId) public; function takeOwnership(uint256 _tokenId) public; }
  • 43. STAY IN TOUCH Gene Leybzon https://www.linkedin.com/in/leybzon/ https://www.meetup.com/Blockchain- Applications-and-Smart-Contracts/ https://www.meetup.com/members/9074420/ https://www.leybzon.com
  • 44. NEXT STEPS http://solidity.readthedocs.ioLanguage • Learn Solidity Ideas People • Meetups • Conferences