SlideShare a Scribd company logo
BLOCKCHAIN AND SMART
CONTRACTS SESSION 2
Hands-on introduction for
Software Developers and
Architects
PLAN FOR TODAY
Understand basis Etherium concepts
Selenium Language
Install Etherium Test Network
Install truffle code development environment
Create your first contract
Compile
Test
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
Solidit
y
Serpent
LL
L
Bytecodes
Etherium
Virtual Machine
(EVM)
REGISTRARS (ETHEREUM NAME
SERVICE, ENS)
1. Send ether to an address in Metamask
(soon: MEW, Mist, Bitfinex)
2. Use it inside your own contracts to
resolve names of other contracts and
addresses
3. Store contract ABIs for easy lookup
using the ethereum-ens library
4. Address of a Swarm site
Use Cases
Registry
Regista
r
Resolve
r
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
transaction 500 Paid for every transaction
Example:
300 CPU cycles = 300 gas units = 0.000006 ETH =
$0.00553
(as of 2/20/2018)
Cost of Gas as in 2018
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
Functions
Constant
Transactional
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
PREREQUISITES
INSTALL TRUFFLE FRAMEWORK
•$ sudo npm install -g truffle
•$ mkdir solidity-experiments
•$ cd solidity-experiments/
•$ truffle init
Truffle
Framework
INSTALL AND START LOCAL TEST
NETWORK
•$ npm install -g
ganache-cli
•$ ganache-cli &
Etherium
test
network
CONFIGURE TRUFFLE
• module.exports = {
• networks: {
• development: {
• host: "localhost",
• port: 8545,
• network_id: "*"
• }
• }
• }
Update
truffle.js
DEVELOPING SMART CONTRACT
WITH TRUFFLE
Write Code
Create
deployment
script
Migrate/Deploy
HELLO WORLD CONTRACT
(SOLIDITY CODE)
pragma solidity ^0.4.4;
contract Hello {
function Hello() public {
// constructor
}
function sayHello() public pure returns
(string) {
//console.log("sayHello() function
called...");
return 'Hello World!';
}
}
DEPLOYMENT SCRIPT
var Hello1 =
artifacts.require("./Hello.sol");
module.exports =
function(deployer) {
deployer.deploy(Hello1);
};
DEPLOY CONTRACT TO THE TEST
NETWORK$ truffle console
truffle(development)> truffle migrate --reset
Using network 'development'.
Running migration: 1_initial_migration.js
Deploying Migrations...
...
0xb6bbeaaf3649ecb38d548cba96f681682dad9e0225726924fbee3ce3
6eff94e3
Migrations: 0xc08c46796ba0edc0bebbbd0d90868c010055cb0e
Saving successful migration to network...
...
0x16fe364b9f2c3e8f07fa1ebd6b84b8ad9b4e750d8698a7e920d824eb
d019dd80
Saving artifacts...
Running migration: 2_deploy_contracts.js
Deploying Hello...
...
0xfe120836b2d7395bd988104feff018fe352f93555f71003bbf1a6467
1cca9ba1
Hello: 0x2b649a87d20ce1ac3b6a0218e911165fa0f095f0
Saving successful migration to network...
...
0x1a09073a3b3f7996f3d63a81a99d8cd09198ad7b467f35f7ddc500a
4291332b9
Saving artifacts...
truffle(development)>
TEST CONTRACT
truffle(development)> var he =
Hello.at(Hello.address)
Undefined
truffle(development)> he.sayHello()
'Hello World!'
STAY IN TOUCH
Gene Leybzon https://www.linkedin.com/in/leybzon/
https://www.meetup.com/members/90744
20/
https://www.leybzon.com

More Related Content

What's hot (20)

PPTX
Smart Contract programming 101 with Solidity #PizzaHackathon
Sittiphol Phanvilai
 
PPTX
Oracles
Gene Leybzon
 
PPT
Oop1
Vaibhav Bajaj
 
PDF
Smart contract and Solidity
겨울 정
 
PDF
Blockchain Coding Dojo - BlockchainHub Graz
BlockchainHub Graz
 
PPTX
Solidity
gavofyork
 
PDF
ERC20 Token Contract
KC Tam
 
PDF
C++ TUTORIAL 5
Farhan Ab Rahman
 
PPTX
Solidity Simple Tutorial EN
Nicholas Lin
 
DOCX
Oop lab report
khasmanjalali
 
PDF
C++ TUTORIAL 4
Farhan Ab Rahman
 
PDF
C++ TUTORIAL 1
Farhan Ab Rahman
 
PDF
“Create your own cryptocurrency in an hour” - Sandip Pandey
EIT Digital Alumni
 
PDF
Timur Shemsedinov "Пишу на колбеках, а что... (Асинхронное программирование)"
OdessaJS Conf
 
PDF
C++ TUTORIAL 3
Farhan Ab Rahman
 
PDF
C++ TUTORIAL 10
Farhan Ab Rahman
 
PDF
Yurii Shevtsov "V8 + libuv = Node.js. Under the hood"
OdessaJS Conf
 
PPTX
Principais vulnerabilidades em Smart Contracts e como evitá-las
Júlio Campos
 
PDF
C++ TUTORIAL 7
Farhan Ab Rahman
 
PDF
C++ TUTORIAL 9
Farhan Ab Rahman
 
Smart Contract programming 101 with Solidity #PizzaHackathon
Sittiphol Phanvilai
 
Oracles
Gene Leybzon
 
Smart contract and Solidity
겨울 정
 
Blockchain Coding Dojo - BlockchainHub Graz
BlockchainHub Graz
 
Solidity
gavofyork
 
ERC20 Token Contract
KC Tam
 
C++ TUTORIAL 5
Farhan Ab Rahman
 
Solidity Simple Tutorial EN
Nicholas Lin
 
Oop lab report
khasmanjalali
 
C++ TUTORIAL 4
Farhan Ab Rahman
 
C++ TUTORIAL 1
Farhan Ab Rahman
 
“Create your own cryptocurrency in an hour” - Sandip Pandey
EIT Digital Alumni
 
Timur Shemsedinov "Пишу на колбеках, а что... (Асинхронное программирование)"
OdessaJS Conf
 
C++ TUTORIAL 3
Farhan Ab Rahman
 
C++ TUTORIAL 10
Farhan Ab Rahman
 
Yurii Shevtsov "V8 + libuv = Node.js. Under the hood"
OdessaJS Conf
 
Principais vulnerabilidades em Smart Contracts e como evitá-las
Júlio Campos
 
C++ TUTORIAL 7
Farhan Ab Rahman
 
C++ TUTORIAL 9
Farhan Ab Rahman
 

Similar to Hands on with smart contracts 2. Presentation for the Blockchain Applications and Smart Contracts meetup. (20)

PPTX
Hands on with smart contracts
Gene Leybzon
 
PDF
Building Apps with Ethereum Smart Contract
Vaideeswaran Sethuraman
 
PPTX
Ethereum
V C
 
PDF
Smart contracts in Solidity
Felix Crisan
 
PPTX
The Ethereum Blockchain - Introduction to Smart Contracts and Decentralized A...
I.I.S. G. Vallauri - Fossano
 
PDF
Introduction to Blockchain with an Ethereuem Hands-on
Johann Romefort
 
PDF
Ethereum Solidity Fundamentals
Eno Bassey
 
PDF
Programming smart contracts in solidity
Emanuel Mota
 
PPTX
Learning Solidity
Arnold Pham
 
PPTX
Kriptovaluták, hashbányászat és okoscicák
hackersuli
 
PPTX
Ethereum
Brian Yap
 
PDF
Blockchain Development
preetikumara
 
PDF
Blockchain Programming
Rhea Myers
 
PDF
Ethereum Contracts - Coinfest 2015
Rhea Myers
 
PDF
"Programming Smart Contracts on Ethereum" by Anatoly Ressin from AssistUnion ...
Dace Barone
 
PPTX
Ethereum.pptx
INAMULLAH699891
 
PDF
A Decompiler for Blackhain-Based Smart Contracts Bytecode
Shakacon
 
PDF
Grokking TechTalk #17: Introduction to blockchain
Grokking VN
 
PPTX
Ethereum Block Chain
SanatPandoh
 
PPTX
Dappsmedia smartcontract _write_smartcontracts_on_console_ethereum
Tomoaki Sato
 
Hands on with smart contracts
Gene Leybzon
 
Building Apps with Ethereum Smart Contract
Vaideeswaran Sethuraman
 
Ethereum
V C
 
Smart contracts in Solidity
Felix Crisan
 
The Ethereum Blockchain - Introduction to Smart Contracts and Decentralized A...
I.I.S. G. Vallauri - Fossano
 
Introduction to Blockchain with an Ethereuem Hands-on
Johann Romefort
 
Ethereum Solidity Fundamentals
Eno Bassey
 
Programming smart contracts in solidity
Emanuel Mota
 
Learning Solidity
Arnold Pham
 
Kriptovaluták, hashbányászat és okoscicák
hackersuli
 
Ethereum
Brian Yap
 
Blockchain Development
preetikumara
 
Blockchain Programming
Rhea Myers
 
Ethereum Contracts - Coinfest 2015
Rhea Myers
 
"Programming Smart Contracts on Ethereum" by Anatoly Ressin from AssistUnion ...
Dace Barone
 
Ethereum.pptx
INAMULLAH699891
 
A Decompiler for Blackhain-Based Smart Contracts Bytecode
Shakacon
 
Grokking TechTalk #17: Introduction to blockchain
Grokking VN
 
Ethereum Block Chain
SanatPandoh
 
Dappsmedia smartcontract _write_smartcontracts_on_console_ethereum
Tomoaki Sato
 
Ad

More from Gene Leybzon (20)

PPTX
Generative AI Application Development using LangChain and LangFlow
Gene Leybzon
 
PPTX
Chat GPTs
Gene Leybzon
 
PPTX
Generative AI Use cases for Enterprise - Second Session
Gene Leybzon
 
PPTX
Generative AI Use-cases for Enterprise - First Session
Gene Leybzon
 
PPTX
Non-fungible tokens (nfts)
Gene Leybzon
 
PPTX
Introduction to Solidity and Smart Contract Development (9).pptx
Gene Leybzon
 
PPTX
Ethereum in Enterprise.pptx
Gene Leybzon
 
PPTX
ERC-4907 Rentable NFT Standard.pptx
Gene Leybzon
 
PPTX
Onchain Decentralized Governance 2.pptx
Gene Leybzon
 
PPTX
Onchain Decentralized Governance.pptx
Gene Leybzon
 
PPTX
Web3 File Storage Options
Gene Leybzon
 
PPTX
Web3 Full Stack Development
Gene Leybzon
 
PPTX
Instantly tradeable NFT contracts based on ERC-1155 standard
Gene Leybzon
 
PPTX
Non-fungible tokens. From smart contract code to marketplace
Gene Leybzon
 
PPTX
The Art of non-fungible tokens
Gene Leybzon
 
PPTX
Graph protocol for accessing information about blockchains and d apps
Gene Leybzon
 
PPTX
Substrate Framework
Gene Leybzon
 
PPTX
Chainlink
Gene Leybzon
 
PPTX
OpenZeppelin + Remix + BNB smart chain
Gene Leybzon
 
PPTX
Chainlink, Cosmos, Kusama, Polkadot: Approaches to the Internet of Blockchains
Gene Leybzon
 
Generative AI Application Development using LangChain and LangFlow
Gene Leybzon
 
Chat GPTs
Gene Leybzon
 
Generative AI Use cases for Enterprise - Second Session
Gene Leybzon
 
Generative AI Use-cases for Enterprise - First Session
Gene Leybzon
 
Non-fungible tokens (nfts)
Gene Leybzon
 
Introduction to Solidity and Smart Contract Development (9).pptx
Gene Leybzon
 
Ethereum in Enterprise.pptx
Gene Leybzon
 
ERC-4907 Rentable NFT Standard.pptx
Gene Leybzon
 
Onchain Decentralized Governance 2.pptx
Gene Leybzon
 
Onchain Decentralized Governance.pptx
Gene Leybzon
 
Web3 File Storage Options
Gene Leybzon
 
Web3 Full Stack Development
Gene Leybzon
 
Instantly tradeable NFT contracts based on ERC-1155 standard
Gene Leybzon
 
Non-fungible tokens. From smart contract code to marketplace
Gene Leybzon
 
The Art of non-fungible tokens
Gene Leybzon
 
Graph protocol for accessing information about blockchains and d apps
Gene Leybzon
 
Substrate Framework
Gene Leybzon
 
Chainlink
Gene Leybzon
 
OpenZeppelin + Remix + BNB smart chain
Gene Leybzon
 
Chainlink, Cosmos, Kusama, Polkadot: Approaches to the Internet of Blockchains
Gene Leybzon
 
Ad

Recently uploaded (20)

PDF
Ready Layer One: Intro to the Model Context Protocol
mmckenna1
 
PDF
IObit Driver Booster Pro 12.4.0.585 Crack Free Download
henryc1122g
 
PPTX
From spreadsheets and delays to real-time control
SatishKumar2651
 
PDF
How to Hire AI Developers_ Step-by-Step Guide in 2025.pdf
DianApps Technologies
 
PPTX
Foundations of Marketo Engage - Powering Campaigns with Marketo Personalization
bbedford2
 
PPTX
prodad heroglyph crack 2.0.214.2 Full Free Download
cracked shares
 
PDF
4K Video Downloader Plus Pro Crack for MacOS New Download 2025
bashirkhan333g
 
PPTX
Comprehensive Risk Assessment Module for Smarter Risk Management
EHA Soft Solutions
 
PPTX
Milwaukee Marketo User Group - Summer Road Trip: Mapping and Personalizing Yo...
bbedford2
 
PDF
Is Framer the Future of AI Powered No-Code Development?
Isla Pandora
 
PDF
Salesforce Experience Cloud Consultant.pdf
VALiNTRY360
 
PPTX
Transforming Insights: How Generative AI is Revolutionizing Data Analytics
LetsAI Solutions
 
PDF
ERP Consulting Services and Solutions by Contetra Pvt Ltd
jayjani123
 
PDF
Simplify React app login with asgardeo-sdk
vaibhav289687
 
PPTX
Library_Management_System_PPT111111.pptx
nmtnissancrm
 
PPTX
Smart Doctor Appointment Booking option in odoo.pptx
AxisTechnolabs
 
PPTX
Agentic Automation: Build & Deploy Your First UiPath Agent
klpathrudu
 
PDF
Latest Capcut Pro 5.9.0 Crack Version For PC {Fully 2025
utfefguu
 
PDF
Meet in the Middle: Solving the Low-Latency Challenge for Agentic AI
Alluxio, Inc.
 
PPTX
UI5con_2025_Accessibility_Ever_Evolving_
gerganakremenska1
 
Ready Layer One: Intro to the Model Context Protocol
mmckenna1
 
IObit Driver Booster Pro 12.4.0.585 Crack Free Download
henryc1122g
 
From spreadsheets and delays to real-time control
SatishKumar2651
 
How to Hire AI Developers_ Step-by-Step Guide in 2025.pdf
DianApps Technologies
 
Foundations of Marketo Engage - Powering Campaigns with Marketo Personalization
bbedford2
 
prodad heroglyph crack 2.0.214.2 Full Free Download
cracked shares
 
4K Video Downloader Plus Pro Crack for MacOS New Download 2025
bashirkhan333g
 
Comprehensive Risk Assessment Module for Smarter Risk Management
EHA Soft Solutions
 
Milwaukee Marketo User Group - Summer Road Trip: Mapping and Personalizing Yo...
bbedford2
 
Is Framer the Future of AI Powered No-Code Development?
Isla Pandora
 
Salesforce Experience Cloud Consultant.pdf
VALiNTRY360
 
Transforming Insights: How Generative AI is Revolutionizing Data Analytics
LetsAI Solutions
 
ERP Consulting Services and Solutions by Contetra Pvt Ltd
jayjani123
 
Simplify React app login with asgardeo-sdk
vaibhav289687
 
Library_Management_System_PPT111111.pptx
nmtnissancrm
 
Smart Doctor Appointment Booking option in odoo.pptx
AxisTechnolabs
 
Agentic Automation: Build & Deploy Your First UiPath Agent
klpathrudu
 
Latest Capcut Pro 5.9.0 Crack Version For PC {Fully 2025
utfefguu
 
Meet in the Middle: Solving the Low-Latency Challenge for Agentic AI
Alluxio, Inc.
 
UI5con_2025_Accessibility_Ever_Evolving_
gerganakremenska1
 

Hands on with smart contracts 2. Presentation for the Blockchain Applications and Smart Contracts meetup.

  • 1. BLOCKCHAIN AND SMART CONTRACTS SESSION 2 Hands-on introduction for Software Developers and Architects
  • 2. PLAN FOR TODAY Understand basis Etherium concepts Selenium Language Install Etherium Test Network Install truffle code development environment Create your first contract Compile Test
  • 4. TWO TYPES OF ACCOUNTS Account StorageBalance Code <> Externally Owned Account StorageBalance Account StorageBalance Code <> Contract StorageBalance Code <>
  • 5. 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
  • 6. CALLS AND MESSAGES Contract A Contract B Message Call • Source • Target • Data Payload • Ether • Gas • Return Data Externally owned account Message CallSend Transaction Call
  • 7. 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); • } • }
  • 9. REGISTRARS (ETHEREUM NAME SERVICE, ENS) 1. Send ether to an address in Metamask (soon: MEW, Mist, Bitfinex) 2. Use it inside your own contracts to resolve names of other contracts and addresses 3. Store contract ABIs for easy lookup using the ethereum-ens library 4. Address of a Swarm site Use Cases Registry Regista r Resolve r
  • 10. 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
  • 11. 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 transaction 500 Paid for every transaction Example: 300 CPU cycles = 300 gas units = 0.000006 ETH = $0.00553 (as of 2/20/2018) Cost of Gas as in 2018
  • 12. 2 MINUTE INTRODUCTION TO SOLIDITY Data Types Functions
  • 13. 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;
  • 14. 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;
  • 15. FUNCTIONS Functions Constant Transactional 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; } } }
  • 18. INSTALL TRUFFLE FRAMEWORK •$ sudo npm install -g truffle •$ mkdir solidity-experiments •$ cd solidity-experiments/ •$ truffle init Truffle Framework
  • 19. INSTALL AND START LOCAL TEST NETWORK •$ npm install -g ganache-cli •$ ganache-cli & Etherium test network
  • 20. CONFIGURE TRUFFLE • module.exports = { • networks: { • development: { • host: "localhost", • port: 8545, • network_id: "*" • } • } • } Update truffle.js
  • 21. DEVELOPING SMART CONTRACT WITH TRUFFLE Write Code Create deployment script Migrate/Deploy
  • 22. HELLO WORLD CONTRACT (SOLIDITY CODE) pragma solidity ^0.4.4; contract Hello { function Hello() public { // constructor } function sayHello() public pure returns (string) { //console.log("sayHello() function called..."); return 'Hello World!'; } }
  • 23. DEPLOYMENT SCRIPT var Hello1 = artifacts.require("./Hello.sol"); module.exports = function(deployer) { deployer.deploy(Hello1); };
  • 24. DEPLOY CONTRACT TO THE TEST NETWORK$ truffle console truffle(development)> truffle migrate --reset Using network 'development'. Running migration: 1_initial_migration.js Deploying Migrations... ... 0xb6bbeaaf3649ecb38d548cba96f681682dad9e0225726924fbee3ce3 6eff94e3 Migrations: 0xc08c46796ba0edc0bebbbd0d90868c010055cb0e Saving successful migration to network... ... 0x16fe364b9f2c3e8f07fa1ebd6b84b8ad9b4e750d8698a7e920d824eb d019dd80 Saving artifacts... Running migration: 2_deploy_contracts.js Deploying Hello... ... 0xfe120836b2d7395bd988104feff018fe352f93555f71003bbf1a6467 1cca9ba1 Hello: 0x2b649a87d20ce1ac3b6a0218e911165fa0f095f0 Saving successful migration to network... ... 0x1a09073a3b3f7996f3d63a81a99d8cd09198ad7b467f35f7ddc500a 4291332b9 Saving artifacts... truffle(development)>
  • 25. TEST CONTRACT truffle(development)> var he = Hello.at(Hello.address) Undefined truffle(development)> he.sayHello() 'Hello World!'
  • 26. STAY IN TOUCH Gene Leybzon https://www.linkedin.com/in/leybzon/ https://www.meetup.com/members/90744 20/ https://www.leybzon.com

Editor's Notes

  • #5: Every account has a persistent key-value store mapping 256-bit words to 256-bit words called storage Accounts can be externally owned or contracts
  • #7: Message: This is contract-to-contract. These are not delayed by mining because they are part of the transaction execution. Transaction: Like a message, but originates with an externally owned account. It's always a transaction that gets things started, but multiple messages may be fired off to complete the action. Ethereum also has two modes of execution. These modes are indifferent to the syntax or vernacular in the client that summoned the contract. So, the important things are to know which one is appropriate, and how to select it in your client of choice. sendTransaction: Transaction is sent to the network and verified by miners. Sender gets a transaction hash initially since no results are available until after the transaction is mined. These are potentially state-changing. call: Transaction is executed locally on the user's local machine which alone evaluates the result. These are read-only and fast. They can't change the blockchain in any way because they are never sent to the network. Most languages/platforms don't have this idea of running the code in either "read-only/dry run/practice" mode and "read-write/real world/sticky" mode. (https://ethereum.stackexchange.com/questions/12065/what-is-the-difference-between-a-call-message-call-and-a-message)
  • #9: https://github.com/ethereum/wiki/wiki/Serpent
  • #10: https://github.com/ethereum/ens https://medium.com/the-ethereum-name-service/a-developers-guide-to-ens-concepts-7004eea8a073
  • #12: http://ether.fund/tool/gas-fees https://etherscan.io/chart/gasprice https://ethgasstation.info/calculatorTxV.php
  • #14: https://github.com/ethereum/wiki/wiki/Ethereum-Contract-ABI
  • #15: https://github.com/ethereum/wiki/wiki/Ethereum-Contract-ABI
  • #16: https://ethereum.stackexchange.com/questions/19380/external-vs-public-best-practices
  • #18: Ubuntu Linux Ask for the WiFi guest password
  • #20: https://github.com/trufflesuite/ganache-cli Options: -a or --accounts: Specify the number of accounts to generate at startup. -e or --defaultBalanceEther: Amount of ether to assign each test account. Default is 100. -b or --blocktime: Specify blocktime in seconds for automatic mining. Default is 0 and no auto-mining. -d or --deterministic: Generate deterministic addresses based on a pre-defined mnemonic. -n or --secure: Lock available accounts by default (good for third party transaction signing) -m or --mnemonic: Use a specific HD wallet mnemonic to generate initial addresses. -p or --port: Port number to listen on. Defaults to 8545. -h or --hostname: Hostname to listen on. Defaults to Node's server.listen() default. -s or --seed: Use arbitrary data to generate the HD wallet mnemonic to be used. -g or --gasPrice: Use a custom Gas Price (defaults to 20000000000) -l or --gasLimit: Use a custom Gas Limit (defaults to 90000) -f or --fork: Fork from another currently running Ethereum client at a given block. Input should be the HTTP location and port of the other client, e.g. http://localhost:8545. You can optionally specify the block to fork from using an @sign: http://localhost:8545@1599200. -i or --networkId: Specify the network id the ganache-cli will use to identify itself (defaults to the current time or the network id of the forked blockchain if configured) --db: Specify a path to a directory to save the chain database. If a database already exists, ganache-cli will initialize that chain instead of creating a new one. --debug: Output VM opcodes for debugging --mem: Output ganache-cli memory usage statistics. This replaces normal output. --noVMErrorsOnRPCResponse: Do not transmit transaction failures as RPC errors. Enable this flag for error reporting behaviour which is compatible with other clients such as geth and Parity.
  • #23: http://leybzon.blogspot.com/2018/01/hello-world-from-solidity.html
  • #24: http://leybzon.blogspot.com/2018/01/hello-world-from-solidity.html
  • #25: http://leybzon.blogspot.com/2018/01/hello-world-from-solidity.html
  • #26: http://leybzon.blogspot.com/2018/01/hello-world-from-solidity.html