SlideShare a Scribd company logo
Smart contracts on Ethereum
Getting started
DappsMedia Tomoaki Sato
June 2015
Main source: https://github.com/ethereum/wiki/wiki/Ethereum-Development-Tutorial
~From blockchain installation to make tokenContract ~
What are smart contracts on Ethereum blockchain?
1Source: https://github.com/ethereum/wiki/wiki/White-Paper
Original idea derived from Nick Szabo’s paper in1997.
http://szabo.best.vwh.net/smart_contracts_idea.html
and going to be live by Stateful blockchain with Ethereum virtual machine
What kind of application needs smart contracts ?
2Source: Source
1.Vending machine
2.Asset automated transfer system
• Token Systems
• Financial derivatives
• Identity and Reputation Systems
• Decentralized File Storage
• Decentralized Autonomous
Organizations
• See also
https://docs.google.com/spreads
heets/u/1/d/1VdRMFENPzjL2V-
vZhcc_aa5-
ysf243t5vXlxC2b054g/edit
After blockchain age
Smart contract 4 purposes
3
Smart contract
1. Maintain a data
store contract.
2. Forwarding
contract which
has access policy,
and some
conditions to
send messages.
3. Ongoing
contract such as
escrow,
crowdfunding.
4.Library type
contract which
provides
functions to other
contracts.
Process objectives
Ethereum contracts objectives
Source: https://github.com/ethereum/wiki/wiki/Ethereum-Development-Tutorial
1.Maintain a data store contract
4
Most simple type can be used by Embark (more about the later)
Source: http://jorisbontje.github.io/sleth/#/
# app/contracts/simple_storage.sol
contract SimpleStorage {
uint storedData;
function set(uint x) {
storedData = x * x * x;
}
function get() constant returns (uint retVal)
{
return storedData;
}
}
2.Forwarding contract
5
Sleth is the decentralized slot machine application using forwarding type smart contract.
Currently I can not find the forwarding type contract which can be run on testnet. If you know please comment on.
Source: https://github.com/ethereum/wiki/wiki/Ethereum-Development-Tutorial
When Bob wants to finalize the bet, the following
steps happen:
1. A transaction is sent, triggering a message
from Bob's EOA to Bob's forwarding contract.
2. Bob's forwarding contract sends the hash of
the message and the Lamport signature to a
contract which functions as a Lamport
signature verification library.
3. The Lamport signature verification library sees
that Bob wants a SHA256-based Lamport sig,
so it calls the SHA256 library many times as
needed to verify the signature.
4. Once the Lamport signature verification library
returns 1, signifying that the signature has
been verified, it sends a message to the
contract representing the bet.
5. The bet contract checks the contract providing
the San Francisco temperature to see what the
temperature is.
3.Ongoing contract
6Source: https://github.com/WeiFund/WeiFund/blob/master/WeiFund.sol
Most smart contracts are ongoing type contracts, such as crowdfunding is ongoing contract.
// WeiFund System
// Start, donate, payout and refund crowdfunding campaigns
// @authors:
// Nick Dodson <thenickdodson@gmail.com>
// If goal is not reached and campaign is expired, contributers can get the
refunded individually
// If goal is reached by alloted time, contributions can still be made
contract WeiFundConfig
{
function onContribute(uint cid, address addr, uint amount){}
function onRefund(uint cid, address addr, uint amount){}
function onPayout(uint cid, uint amount){}
}
contract WeiFund
{
struct User
{
uint numCampaigns;
mapping(uint => uint) campaigns;
}
struct Funder
{
address addr;
uint amount;
}
...
4. Library contract
7Source: https://github.com/ethereum/wiki/wiki/Ethereum-Development-Tutorial
Smart contract which provides utility functions.
In the case below, Lamport sig verifier contract is Library type contracts.
The contract will provide a set of function
Structuring every type of smart contract
8
You can make structure by combining different contracts
Source:https://github.com/ethereum/wiki/wiki/Ethereum-Development-Tutorial
LET’S ENJOY ETHEREUM
Next
9
Our goal today
10
Download blockchain, writing smart contracts, publish contract on blockchain, send message to
contracts.
Source: http://jorisbontje.github.io/sleth/#/ http://ethereum.gitbooks.io/frontier-guide/content/contract_coin.html
http://meteor-dapp-cosmo.meteor.com/
Cool!
1. Install Ethereum blockchain 2.writing smart contract
3.Publish contract on blockchain 4.Send message to contracts &
check the result
tokenInstance.getBalance.call(eth.accounts[1])
tokenInstance.sendToken.sendTransaction(et
h.accounts[1], 100, {from: eth.accounts[0]})
1. Install Ethereum blockchain
11
3 ways to install...
Source: http://jorisbontje.github.io/sleth/#/
1. Live Testnet chain https://stats.ethdev.com/
2. Private chain
3. Private chain with framework (Embark framework)
https://github.com/iurimatias/embark-framework
Cool!
1. Install Ethereum blockchain
12Source: http://jorisbontje.github.io/sleth/#/
1. Live Testnet chain we will install this chain. https://stats.ethdev.com/
Cool!
CPP
O △ ☓
1. Install Ethereum blockchain
13Source:
1.Live Testnet chain we will install this chain. https://stats.ethdev.com/
June, 2015
Go-Ethereum = Geth !
1. installation of geth
https://github.com/ethereum/go-ethereum/releases/tag/v0.9.20
2. geth account new
http://ethereum.gitbooks.io/frontier-guide/content/creating_accounts.html
3. Do mining & should wait until the Blocknumber on stats (roughly 4 ~6 hours )
https://stats.ethdev.com/
1. Install Ethereum blockchain
14
2.Private chain is private blockchain just for you. No network, your own blockchain.
Source:https://github.com/ethereum/go-ethereum/wiki/Setting-up-private-network-or-local-cluster
Currently Ethereum using blockchain,
You can run multiple chains locally to do this,
1. Each instance has separate data dir
2. Each instance runs on a different port ( both eth and rpc. )
3. The instances know about each other
You can run multiple chains locally
1st chain
// create dir for blockchain
$ mkdir /tmp/eth/60/01
// run private chain
$ geth –datadir=“/tmp/eth/60/01” –
verbosity 6 –port 30301 –rpcport 8101
console 2>> /tmp/eth/60/01.log
// mining start
$ admin.miner.start()
You can run multiple chains locally
2nd chain but for my env doesn’t work.
// create dir for blockchain
$ mkdir /tmp/eth/61/01
// run private chain
$ geth –datadir=“/tmp/eth/61/01” –
verbosity 6 –port 30302 –rpcport 8102
console 2>> /tmp/eth/61/01.log
// mining start
$ admin.miner.start()
1. Install Ethereum blockchain
15
3. Embark Framework for Ethereum DApps. https://iurimatias.github.io/embark-framework/
Source: https://iurimatias.github.io/embark-framework/
I feel
1. Easy to upload contracts you write to private blockchain
2. If you don’t know about How to use
3. Fast demo – Simple storage application using private chain is buildin demo.
$ npm install -g embark-framework grunt-cli
$ embark demo
$ cd embark_demo
$ embark blockchain
$ embark run
2. Write smart contract after $ geth console
16
1. Write Token contract you can publish your own token. After $ geth console
### coin contract from console
var tokenSource = 'contract token { mapping (address => uint) balances; function token() { balances[msg.sender]
= 10000; } function sendToken(address receiver, uint amount) returns(bool sufficient) { if
(balances[msg.sender] < amount) return false; balances[msg.sender] -= amount; balances[receiver] +=
amount; return true; } function getBalance(address account) returns(uint balance){ return
balances[account]; } }'
var tokenCompiled = eth.compile.solidity(tokenSource).token
var tokenAddress = eth.sendTransaction({data: tokenCompiled.code, from: eth.accounts[0], gas:1000000});
admin.miner.start()
admin.miner.stop()
eth.getCode(tokenAddress)
tokenContract = eth.contract(tokenCompiled.info.abiDefinition)
tokenInstance = tokenContract.at(tokenAddress);
> tokenInstance
{
address: '0xf95ff51f532bd6821b98f312e876e1e2213f3e36',
sendToken: [Function],
getBalance: [Function]
}
tokenInstance.getBalance.call(eth.accounts[0])
tokenInstance.sendToken.sendTransaction(eth.accounts[1], 100, {from: eth.accounts[0]})
admin.miner.start()
admin.miner.stop()
tokenInstance.getBalance.call(eth.accounts[0])
> tokenInstance.getBalance.call(eth.accounts[0])
'9900'
3.Publish contract
17
This phrase is uploading the contract onto blockchain.
### coin contract from console
var tokenSource = 'contract token { mapping (address => uint) balances; function token() { balances[msg.sender]
= 10000; } function sendToken(address receiver, uint amount) returns(bool sufficient) { if
(balances[msg.sender] < amount) return false; balances[msg.sender] -= amount; balances[receiver] +=
amount; return true; } function getBalance(address account) returns(uint balance){ return
balances[account]; } }'
var tokenCompiled = eth.compile.solidity(tokenSource).token
var tokenAddress = eth.sendTransaction({data: tokenCompiled.code, from:
eth.accounts[0], gas:1000000});
admin.miner.start()
admin.miner.stop()
eth.getCode(tokenAddress)
tokenContract = eth.contract(tokenCompiled.info.abiDefinition)
tokenInstance = tokenContract.at(tokenAddress);
> tokenInstance
{
address: '0xf95ff51f532bd6821b98f312e876e1e2213f3e36',
sendToken: [Function],
getBalance: [Function]
}
tokenInstance.getBalance.call(eth.accounts[0])
tokenInstance.sendToken.sendTransaction(eth.accounts[1], 100, {from: eth.accounts[0]})
admin.miner.start()
admin.miner.stop()
tokenInstance.getBalance.call(eth.accounts[0])
> tokenInstance.getBalance.call(eth.accounts[0])
'9900'
4.Send message to the contract and check the result
18
This phrase is sending message to the contract on blockchain.
### coin contract from console
var tokenSource = 'contract token { mapping (address => uint) balances; function token() { balances[msg.sender]
= 10000; } function sendToken(address receiver, uint amount) returns(bool sufficient) { if
(balances[msg.sender] < amount) return false; balances[msg.sender] -= amount; balances[receiver] +=
amount; return true; } function getBalance(address account) returns(uint balance){ return
balances[account]; } }'
var tokenCompiled = eth.compile.solidity(tokenSource).token
var tokenAddress = eth.sendTransaction({data: tokenCompiled.code, from: eth.accounts[0], gas:1000000});
admin.miner.start()
admin.miner.stop()
eth.getCode(tokenAddress)
tokenContract = eth.contract(tokenCompiled.info.abiDefinition)
tokenInstance = tokenContract.at(tokenAddress);
> tokenInstance
{
address: '0xf95ff51f532bd6821b98f312e876e1e2213f3e36',
sendToken: [Function],
getBalance: [Function]
}
tokenInstance.getBalance.call(eth.accounts[0])
tokenInstance.sendToken.sendTransaction(eth.accounts[1], 100, {from:
eth.accounts[0]})
admin.miner.start()
admin.miner.stop()
tokenInstance.getBalance.call(eth.accounts[0])
> tokenInstance.getBalance.call(eth.accounts[0])
'9900'
Miscellaneous
19
Ethereum frontier guide
Solidty online compiler
https://chriseth.github.io/cpp-ethereum/
Geth(go-ethereum)
https://github.com/ethereum/go-ethereum/releases/tag/v0.9.20
State of the DApps spreadsheet
https://docs.google.com/spreadsheets/d/1VdRMFENPzjL2V-vZhcc_aa5-
ysf243t5vXlxC2b054g/edit#gid=0
Ethereum forum
https://forum.ethereum.org/categories/services-and-decentralized-applications
Solidity presentation
https://www.youtube.com/watch?v=DIqGDNPO5YM
http://ethereum.gitbooks.io/frontier-guide/content/creating_accounts.html
20
Decentralization is just beginning.
We hope you start to be involved in!
Do you have interested in the DAppsMedia also ?
If you have, contract us from here!

More Related Content

PDF
Ethereum Mining How To
PDF
Ethereum Blockchain explained
PDF
Ethereum VM and DSLs for Smart Contracts (updated on May 12th 2015)
PPTX
Introduction to Ethereum
PPTX
Intro to smart contract on blockchain en
PDF
Ethereum-Cryptocurrency (All about Ethereum)
PPTX
Ethereum Intro
PPTX
Ethereum Smart Contract Tutorial
Ethereum Mining How To
Ethereum Blockchain explained
Ethereum VM and DSLs for Smart Contracts (updated on May 12th 2015)
Introduction to Ethereum
Intro to smart contract on blockchain en
Ethereum-Cryptocurrency (All about Ethereum)
Ethereum Intro
Ethereum Smart Contract Tutorial

What's hot (20)

PPTX
Ethereum Tutorial - Ethereum Explained | What is Ethereum? | Ethereum Explain...
PPT
Ethereum introduction
PPTX
Ethereum
PPTX
Bitcoin, Ethereum, Smart Contract & Blockchain
PPTX
The Blockchain and JavaScript
PDF
Introduction to Ethereum
PDF
Building Apps with Ethereum Smart Contract
PDF
BCHGraz - Meetup #8 - Intro & Ethereum
PPTX
Blockchain, Ethereum and ConsenSys
PPTX
Eclipsecon Europe: Blockchain, Ethereum and Business Applications
PPTX
Ethereum Devcon1 Report (summary writing)
PDF
The Ethereum Experience
PPTX
Ethereum Blockchain with Smart contract and ERC20
PDF
gething started - ethereum & using the geth golang client
PDF
Every thing bitcoin in baby language
PDF
Bitcoin and Ethereum
PPTX
Smart contractjp smartcontract_about
PDF
Blockchain Programming
PDF
Bitcoin in a Nutshell
PDF
create your own cryptocurrency
Ethereum Tutorial - Ethereum Explained | What is Ethereum? | Ethereum Explain...
Ethereum introduction
Ethereum
Bitcoin, Ethereum, Smart Contract & Blockchain
The Blockchain and JavaScript
Introduction to Ethereum
Building Apps with Ethereum Smart Contract
BCHGraz - Meetup #8 - Intro & Ethereum
Blockchain, Ethereum and ConsenSys
Eclipsecon Europe: Blockchain, Ethereum and Business Applications
Ethereum Devcon1 Report (summary writing)
The Ethereum Experience
Ethereum Blockchain with Smart contract and ERC20
gething started - ethereum & using the geth golang client
Every thing bitcoin in baby language
Bitcoin and Ethereum
Smart contractjp smartcontract_about
Blockchain Programming
Bitcoin in a Nutshell
create your own cryptocurrency
Ad

Viewers also liked (18)

PPTX
The Ethereum Geth Client
PPTX
Technological Unemployment and the Robo-Economy
ODP
Dapps for Web Developers Aberdeen Techmeetup
PDF
日本のIT市場のトピックス
PDF
Ethereum @ descon 2016
PDF
Etherem ~ agvm
PPTX
Vision for a health blockchain
ODP
Introduction to Idea
PDF
"Performance Analysis of In-Network Caching in Content-Centric Advanced Meter...
PPTX
Solidity intro
PDF
Etherisc Versicherung neu erfinden
PPTX
The Ethereum ÐApp IDE: Mix
PPTX
Learning Solidity
PDF
Ingredients for creating dapps
PPT
PDF
Chatbots et assistants virtuels : l'automatisation du poste de travail
PDF
Ethereum Madrid - Blockchain for dummies
PDF
Ethereum Madrid - Cambio de paradigma en el sector energético
The Ethereum Geth Client
Technological Unemployment and the Robo-Economy
Dapps for Web Developers Aberdeen Techmeetup
日本のIT市場のトピックス
Ethereum @ descon 2016
Etherem ~ agvm
Vision for a health blockchain
Introduction to Idea
"Performance Analysis of In-Network Caching in Content-Centric Advanced Meter...
Solidity intro
Etherisc Versicherung neu erfinden
The Ethereum ÐApp IDE: Mix
Learning Solidity
Ingredients for creating dapps
Chatbots et assistants virtuels : l'automatisation du poste de travail
Ethereum Madrid - Blockchain for dummies
Ethereum Madrid - Cambio de paradigma en el sector energético
Ad

Similar to Dappsmedia smartcontract _write_smartcontracts_on_console_ethereum (20)

PPTX
Blockchain, Ethereum and Business Applications
PPTX
Kriptovaluták, hashbányászat és okoscicák
PDF
Ethereum bxl
PDF
Blockchain School 2019 - Security of Smart Contracts.pdf
PDF
Blockchain Chapter #4.pdf
PDF
Ethereum Solidity Fundamentals
PDF
This presentation detail concepts of cryptocurrency
PDF
Blockchain
PPTX
Multi-Signature Crypto-Wallets: Nakov at Blockchain Berlin 2018
PPTX
Blockchain for Developers
PPTX
Understanding blockchain
PPTX
EthereumBlockchainMarch3 (1).pptx
PPTX
Ethereum Block Chain
PPTX
bitcoin_presentation
PDF
BlockChain Public
PPTX
Bitcoin
PPTX
Explain Ethereum smart contract hacking like i am a five
PPTX
Zoltán Balázs - Ethereum Smart Contract Hacking Explained like I’m Five
PPTX
Building a NFT Marketplace DApp
PDF
Building Java and Android apps on the blockchain
Blockchain, Ethereum and Business Applications
Kriptovaluták, hashbányászat és okoscicák
Ethereum bxl
Blockchain School 2019 - Security of Smart Contracts.pdf
Blockchain Chapter #4.pdf
Ethereum Solidity Fundamentals
This presentation detail concepts of cryptocurrency
Blockchain
Multi-Signature Crypto-Wallets: Nakov at Blockchain Berlin 2018
Blockchain for Developers
Understanding blockchain
EthereumBlockchainMarch3 (1).pptx
Ethereum Block Chain
bitcoin_presentation
BlockChain Public
Bitcoin
Explain Ethereum smart contract hacking like i am a five
Zoltán Balázs - Ethereum Smart Contract Hacking Explained like I’m Five
Building a NFT Marketplace DApp
Building Java and Android apps on the blockchain

More from Tomoaki Sato (7)

PDF
DAO, Starbase - 4th Blockchain research lab at Digital Hollywood University
PPTX
Restribute ~ Wealth re-distirbution by blockchain hardfork ~
PPTX
デジタルハリウッド大学院 ブロックチェーン研究会第三回 2016年8月25日
PPTX
約束としてのスマートコントラクト (Smart contract as a way of promise) 
PPTX
Localfacts smartcontractjp
PPTX
State Of Smart Contract Platforms from Smart Contract JP
PPTX
Smart Contractjp 1st section about
DAO, Starbase - 4th Blockchain research lab at Digital Hollywood University
Restribute ~ Wealth re-distirbution by blockchain hardfork ~
デジタルハリウッド大学院 ブロックチェーン研究会第三回 2016年8月25日
約束としてのスマートコントラクト (Smart contract as a way of promise) 
Localfacts smartcontractjp
State Of Smart Contract Platforms from Smart Contract JP
Smart Contractjp 1st section about

Recently uploaded (20)

PPT
Teaching material agriculture food technology
PPTX
MYSQL Presentation for SQL database connectivity
PDF
Empathic Computing: Creating Shared Understanding
PDF
Network Security Unit 5.pdf for BCA BBA.
PPTX
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PPTX
Cloud computing and distributed systems.
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PDF
cuic standard and advanced reporting.pdf
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PDF
Electronic commerce courselecture one. Pdf
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
Modernizing your data center with Dell and AMD
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PDF
Review of recent advances in non-invasive hemoglobin estimation
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
Teaching material agriculture food technology
MYSQL Presentation for SQL database connectivity
Empathic Computing: Creating Shared Understanding
Network Security Unit 5.pdf for BCA BBA.
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Cloud computing and distributed systems.
The Rise and Fall of 3GPP – Time for a Sabbatical?
cuic standard and advanced reporting.pdf
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
Electronic commerce courselecture one. Pdf
“AI and Expert System Decision Support & Business Intelligence Systems”
Diabetes mellitus diagnosis method based random forest with bat algorithm
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Modernizing your data center with Dell and AMD
NewMind AI Weekly Chronicles - August'25 Week I
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Review of recent advances in non-invasive hemoglobin estimation
Mobile App Security Testing_ A Comprehensive Guide.pdf

Dappsmedia smartcontract _write_smartcontracts_on_console_ethereum

  • 1. Smart contracts on Ethereum Getting started DappsMedia Tomoaki Sato June 2015 Main source: https://github.com/ethereum/wiki/wiki/Ethereum-Development-Tutorial ~From blockchain installation to make tokenContract ~
  • 2. What are smart contracts on Ethereum blockchain? 1Source: https://github.com/ethereum/wiki/wiki/White-Paper Original idea derived from Nick Szabo’s paper in1997. http://szabo.best.vwh.net/smart_contracts_idea.html and going to be live by Stateful blockchain with Ethereum virtual machine
  • 3. What kind of application needs smart contracts ? 2Source: Source 1.Vending machine 2.Asset automated transfer system • Token Systems • Financial derivatives • Identity and Reputation Systems • Decentralized File Storage • Decentralized Autonomous Organizations • See also https://docs.google.com/spreads heets/u/1/d/1VdRMFENPzjL2V- vZhcc_aa5- ysf243t5vXlxC2b054g/edit After blockchain age
  • 4. Smart contract 4 purposes 3 Smart contract 1. Maintain a data store contract. 2. Forwarding contract which has access policy, and some conditions to send messages. 3. Ongoing contract such as escrow, crowdfunding. 4.Library type contract which provides functions to other contracts. Process objectives Ethereum contracts objectives Source: https://github.com/ethereum/wiki/wiki/Ethereum-Development-Tutorial
  • 5. 1.Maintain a data store contract 4 Most simple type can be used by Embark (more about the later) Source: http://jorisbontje.github.io/sleth/#/ # app/contracts/simple_storage.sol contract SimpleStorage { uint storedData; function set(uint x) { storedData = x * x * x; } function get() constant returns (uint retVal) { return storedData; } }
  • 6. 2.Forwarding contract 5 Sleth is the decentralized slot machine application using forwarding type smart contract. Currently I can not find the forwarding type contract which can be run on testnet. If you know please comment on. Source: https://github.com/ethereum/wiki/wiki/Ethereum-Development-Tutorial When Bob wants to finalize the bet, the following steps happen: 1. A transaction is sent, triggering a message from Bob's EOA to Bob's forwarding contract. 2. Bob's forwarding contract sends the hash of the message and the Lamport signature to a contract which functions as a Lamport signature verification library. 3. The Lamport signature verification library sees that Bob wants a SHA256-based Lamport sig, so it calls the SHA256 library many times as needed to verify the signature. 4. Once the Lamport signature verification library returns 1, signifying that the signature has been verified, it sends a message to the contract representing the bet. 5. The bet contract checks the contract providing the San Francisco temperature to see what the temperature is.
  • 7. 3.Ongoing contract 6Source: https://github.com/WeiFund/WeiFund/blob/master/WeiFund.sol Most smart contracts are ongoing type contracts, such as crowdfunding is ongoing contract. // WeiFund System // Start, donate, payout and refund crowdfunding campaigns // @authors: // Nick Dodson <thenickdodson@gmail.com> // If goal is not reached and campaign is expired, contributers can get the refunded individually // If goal is reached by alloted time, contributions can still be made contract WeiFundConfig { function onContribute(uint cid, address addr, uint amount){} function onRefund(uint cid, address addr, uint amount){} function onPayout(uint cid, uint amount){} } contract WeiFund { struct User { uint numCampaigns; mapping(uint => uint) campaigns; } struct Funder { address addr; uint amount; } ...
  • 8. 4. Library contract 7Source: https://github.com/ethereum/wiki/wiki/Ethereum-Development-Tutorial Smart contract which provides utility functions. In the case below, Lamport sig verifier contract is Library type contracts. The contract will provide a set of function
  • 9. Structuring every type of smart contract 8 You can make structure by combining different contracts Source:https://github.com/ethereum/wiki/wiki/Ethereum-Development-Tutorial
  • 11. Our goal today 10 Download blockchain, writing smart contracts, publish contract on blockchain, send message to contracts. Source: http://jorisbontje.github.io/sleth/#/ http://ethereum.gitbooks.io/frontier-guide/content/contract_coin.html http://meteor-dapp-cosmo.meteor.com/ Cool! 1. Install Ethereum blockchain 2.writing smart contract 3.Publish contract on blockchain 4.Send message to contracts & check the result tokenInstance.getBalance.call(eth.accounts[1]) tokenInstance.sendToken.sendTransaction(et h.accounts[1], 100, {from: eth.accounts[0]})
  • 12. 1. Install Ethereum blockchain 11 3 ways to install... Source: http://jorisbontje.github.io/sleth/#/ 1. Live Testnet chain https://stats.ethdev.com/ 2. Private chain 3. Private chain with framework (Embark framework) https://github.com/iurimatias/embark-framework Cool!
  • 13. 1. Install Ethereum blockchain 12Source: http://jorisbontje.github.io/sleth/#/ 1. Live Testnet chain we will install this chain. https://stats.ethdev.com/ Cool! CPP O △ ☓
  • 14. 1. Install Ethereum blockchain 13Source: 1.Live Testnet chain we will install this chain. https://stats.ethdev.com/ June, 2015 Go-Ethereum = Geth ! 1. installation of geth https://github.com/ethereum/go-ethereum/releases/tag/v0.9.20 2. geth account new http://ethereum.gitbooks.io/frontier-guide/content/creating_accounts.html 3. Do mining & should wait until the Blocknumber on stats (roughly 4 ~6 hours ) https://stats.ethdev.com/
  • 15. 1. Install Ethereum blockchain 14 2.Private chain is private blockchain just for you. No network, your own blockchain. Source:https://github.com/ethereum/go-ethereum/wiki/Setting-up-private-network-or-local-cluster Currently Ethereum using blockchain, You can run multiple chains locally to do this, 1. Each instance has separate data dir 2. Each instance runs on a different port ( both eth and rpc. ) 3. The instances know about each other You can run multiple chains locally 1st chain // create dir for blockchain $ mkdir /tmp/eth/60/01 // run private chain $ geth –datadir=“/tmp/eth/60/01” – verbosity 6 –port 30301 –rpcport 8101 console 2>> /tmp/eth/60/01.log // mining start $ admin.miner.start() You can run multiple chains locally 2nd chain but for my env doesn’t work. // create dir for blockchain $ mkdir /tmp/eth/61/01 // run private chain $ geth –datadir=“/tmp/eth/61/01” – verbosity 6 –port 30302 –rpcport 8102 console 2>> /tmp/eth/61/01.log // mining start $ admin.miner.start()
  • 16. 1. Install Ethereum blockchain 15 3. Embark Framework for Ethereum DApps. https://iurimatias.github.io/embark-framework/ Source: https://iurimatias.github.io/embark-framework/ I feel 1. Easy to upload contracts you write to private blockchain 2. If you don’t know about How to use 3. Fast demo – Simple storage application using private chain is buildin demo. $ npm install -g embark-framework grunt-cli $ embark demo $ cd embark_demo $ embark blockchain $ embark run
  • 17. 2. Write smart contract after $ geth console 16 1. Write Token contract you can publish your own token. After $ geth console ### coin contract from console var tokenSource = 'contract token { mapping (address => uint) balances; function token() { balances[msg.sender] = 10000; } function sendToken(address receiver, uint amount) returns(bool sufficient) { if (balances[msg.sender] < amount) return false; balances[msg.sender] -= amount; balances[receiver] += amount; return true; } function getBalance(address account) returns(uint balance){ return balances[account]; } }' var tokenCompiled = eth.compile.solidity(tokenSource).token var tokenAddress = eth.sendTransaction({data: tokenCompiled.code, from: eth.accounts[0], gas:1000000}); admin.miner.start() admin.miner.stop() eth.getCode(tokenAddress) tokenContract = eth.contract(tokenCompiled.info.abiDefinition) tokenInstance = tokenContract.at(tokenAddress); > tokenInstance { address: '0xf95ff51f532bd6821b98f312e876e1e2213f3e36', sendToken: [Function], getBalance: [Function] } tokenInstance.getBalance.call(eth.accounts[0]) tokenInstance.sendToken.sendTransaction(eth.accounts[1], 100, {from: eth.accounts[0]}) admin.miner.start() admin.miner.stop() tokenInstance.getBalance.call(eth.accounts[0]) > tokenInstance.getBalance.call(eth.accounts[0]) '9900'
  • 18. 3.Publish contract 17 This phrase is uploading the contract onto blockchain. ### coin contract from console var tokenSource = 'contract token { mapping (address => uint) balances; function token() { balances[msg.sender] = 10000; } function sendToken(address receiver, uint amount) returns(bool sufficient) { if (balances[msg.sender] < amount) return false; balances[msg.sender] -= amount; balances[receiver] += amount; return true; } function getBalance(address account) returns(uint balance){ return balances[account]; } }' var tokenCompiled = eth.compile.solidity(tokenSource).token var tokenAddress = eth.sendTransaction({data: tokenCompiled.code, from: eth.accounts[0], gas:1000000}); admin.miner.start() admin.miner.stop() eth.getCode(tokenAddress) tokenContract = eth.contract(tokenCompiled.info.abiDefinition) tokenInstance = tokenContract.at(tokenAddress); > tokenInstance { address: '0xf95ff51f532bd6821b98f312e876e1e2213f3e36', sendToken: [Function], getBalance: [Function] } tokenInstance.getBalance.call(eth.accounts[0]) tokenInstance.sendToken.sendTransaction(eth.accounts[1], 100, {from: eth.accounts[0]}) admin.miner.start() admin.miner.stop() tokenInstance.getBalance.call(eth.accounts[0]) > tokenInstance.getBalance.call(eth.accounts[0]) '9900'
  • 19. 4.Send message to the contract and check the result 18 This phrase is sending message to the contract on blockchain. ### coin contract from console var tokenSource = 'contract token { mapping (address => uint) balances; function token() { balances[msg.sender] = 10000; } function sendToken(address receiver, uint amount) returns(bool sufficient) { if (balances[msg.sender] < amount) return false; balances[msg.sender] -= amount; balances[receiver] += amount; return true; } function getBalance(address account) returns(uint balance){ return balances[account]; } }' var tokenCompiled = eth.compile.solidity(tokenSource).token var tokenAddress = eth.sendTransaction({data: tokenCompiled.code, from: eth.accounts[0], gas:1000000}); admin.miner.start() admin.miner.stop() eth.getCode(tokenAddress) tokenContract = eth.contract(tokenCompiled.info.abiDefinition) tokenInstance = tokenContract.at(tokenAddress); > tokenInstance { address: '0xf95ff51f532bd6821b98f312e876e1e2213f3e36', sendToken: [Function], getBalance: [Function] } tokenInstance.getBalance.call(eth.accounts[0]) tokenInstance.sendToken.sendTransaction(eth.accounts[1], 100, {from: eth.accounts[0]}) admin.miner.start() admin.miner.stop() tokenInstance.getBalance.call(eth.accounts[0]) > tokenInstance.getBalance.call(eth.accounts[0]) '9900'
  • 20. Miscellaneous 19 Ethereum frontier guide Solidty online compiler https://chriseth.github.io/cpp-ethereum/ Geth(go-ethereum) https://github.com/ethereum/go-ethereum/releases/tag/v0.9.20 State of the DApps spreadsheet https://docs.google.com/spreadsheets/d/1VdRMFENPzjL2V-vZhcc_aa5- ysf243t5vXlxC2b054g/edit#gid=0 Ethereum forum https://forum.ethereum.org/categories/services-and-decentralized-applications Solidity presentation https://www.youtube.com/watch?v=DIqGDNPO5YM http://ethereum.gitbooks.io/frontier-guide/content/creating_accounts.html
  • 21. 20 Decentralization is just beginning. We hope you start to be involved in! Do you have interested in the DAppsMedia also ? If you have, contract us from here!