SlideShare a Scribd company logo
1 of 30
在 Kotlin/Android 使用
Ethereum Smart Contract
馮彥文 tempofeng@gmail.com
http://m.me/tempofeng
https://medium.com/@tempofeng
Agenda
• Ethereum 乙太幣,Smart Contract 智慧合約,Solidity
• 不信任的環境下的好處
• EtherSpace
• A Retrofit-like Ethereum client for Android, Java, and Kotlin
Ethereum 乙太幣
Smart Contract 智慧合約
Solidity
什麼是 Blockchain 區塊鏈?
Blockchain 區塊鏈
• 去中心化的分散式資料庫
• 運行在不被信任的 node 節點上
• 每個節點皆儲存且驗證資料的正確性來獲得獎勵
• 已經存入的資料不可更改
• 用戶/錢包
• private key
• public address
• 所有對 Blockchain 的操作都會簽章
什麼是 Ethereum 乙太幣?
• 可以執行程式(智慧合約)的區塊鏈系統
• 節點(礦工)驗證程式與交易的正確性
• 第二大的虛擬貨幣經濟體
• 最多人使用的智慧合約區塊鏈
• 每次執行智慧合約需要付費給節點(礦工),稱為
gas
Ethereum 與 Blockchain
呼叫 Smart
Contract
節點執行 Smart
Contract
什麼是 Smart Contract 智慧合約?
• 智慧合約在 Ethereum 不是合約,是一段程式
• 在不信任的節點上的 EVM 執行,所有資訊都是公開的
• 執行結果的 log 會被合併進 Block 區塊
• 合約不可更改
• 只有 Address,沒有 Private Key
• 使用 Solidity 為程式語言
什麼是 Solidity?
• 以太幣的智慧合約語言
• 類似 Javascript
• Type-Safe
• 物件導向
• 執行在 EVM 之上
Solidity 範例
Solidity 範例
Solidity 範例
什麼是 Ethereum Virtual Machine (EVM)?
• Ethereum Smart Contract 的執行環境
• Sandbox 環境,沒辦法存取外界資訊,如時間,網路,...
AWS Lambda 與 EVM 比較
AWS Lambda EVM
執行環境 Java, Javascript, … Solidity
執行速度 快 超級慢(每秒 20 筆)
Scalability 根據流量擴充 單執行緒般
信任 可信任的環境(Amazon) 在不信任的環境
不信任的環境下的好處
不信任的環境下的好處?
• Ethereum 是不信任的環境,完全公開的資料,資料不可修改
• 反而造成程式與資料可以被信任
• 參與者可以達到共識
什麼環境是參與者互相敵對不信任?
• 毒品
• 對方是否為臥底?
• 轉帳是否為假錢?
• 賭博
• Random number 怎麼產生?
• 莊家是否有特別照顧某一方?
在信任的環境下,智慧合約可以用在哪裡?
• 虛擬貨幣
• 交易所
• 中心化 vs 去中心化
• Programmable Money
• 選擇權
• 投票
• 新組織 Decentralized autonomous organization
• Incentive
在信任的環境下,智慧合約可以用在哪裡?
• 供需關係
• 礦工 vs 使用者 vs ...
• filecoin: https://filecoin.io/
• 資料保存
• 收集品
• 遊戲角色
• cryptokitties: https://cryptokitties.co
在信任的環境下,智慧合約可以用在哪裡?
• Hybrid Application
• On-chain vs Off-chain
• 追求最小程度信任
EtherSpace
如何在 Java 環境下呼叫 Ethereum Smart Contract?
• Web3j
• https://github.com/web3j/web3j
• Codegen
• solidity → java file
• EtherSpace
• https://github.com/Wraecca/etherspace-java
• Retrofit style
• 推薦使用!
如何使用 EtherSpace?
如何使用 EtherSpace?
如何使用 EtherSpace?
EtherSpace 的 Smart Contract 設定
• Annotation
• @Call
• 不會變更 Smart Contract 內容的 Transaction 的呼叫
• 與一般 RPC 相同,速度快
• @Send
• 會變更 Smart Contract 內容的呼叫
• @Gas
• 設定交易所需的 Gas
EtherSpace 的 Smart Contract 設定
• Solidity ⟷ Java Data Types
• https://github.com/Wraecca/etherspace-java/wiki/Smart-Contract-Interface
EtherSpace 範例
• Java
• https://github.com/Wraecca/etherspace-java/tree/master/etherspace-java-
example
• Android
• https://github.com/Wraecca/etherspace-java/tree/master/etherspace-
android-example
EtherSpace 使用情境
• Server-side
• 使用固定的 Private Key 呼叫 Smart Contracts
• Android
• 提供用戶錢包功能
• DApp 開發不應該承受這個風險
• 錢包與 DApp 分離(MetaMask 方式)
• Future Work!
Thank You!

More Related Content

Similar to 在 Kotlin/Android 使用 Ethereum Smart Contract

投資還是投機?帶你入門虛擬貨幣與區塊鏈
投資還是投機?帶你入門虛擬貨幣與區塊鏈投資還是投機?帶你入門虛擬貨幣與區塊鏈
投資還是投機?帶你入門虛擬貨幣與區塊鏈Yao-Wei Ou
 
Ethereum Smart Contract Development
Ethereum Smart Contract DevelopmentEthereum Smart Contract Development
Ethereum Smart Contract DevelopmentTitan gene
 
Blockchain Development Presentation part-2
Blockchain Development Presentation part-2Blockchain Development Presentation part-2
Blockchain Development Presentation part-2Clement Hsieh
 
Blockchain Tutorial for Lawyers
Blockchain Tutorial for LawyersBlockchain Tutorial for Lawyers
Blockchain Tutorial for LawyersBlokcert
 
Build the Blockchain as service (BaaS) Using Ethereum on Kubernetes
Build the Blockchain as service (BaaS) Using Ethereum on KubernetesBuild the Blockchain as service (BaaS) Using Ethereum on Kubernetes
Build the Blockchain as service (BaaS) Using Ethereum on Kubernetesinwin stack
 
blockchain&cryptocurrency
blockchain&cryptocurrencyblockchain&cryptocurrency
blockchain&cryptocurrencySean Liu
 
Blockchain introduction for sharing
Blockchain introduction for sharingBlockchain introduction for sharing
Blockchain introduction for sharingLman Chu
 
Blockchain 2.0 : Smart Contract 的美麗與哀愁
Blockchain 2.0 : Smart Contract 的美麗與哀愁Blockchain 2.0 : Smart Contract 的美麗與哀愁
Blockchain 2.0 : Smart Contract 的美麗與哀愁Tom Yang
 
線上區塊鏈投票.pdf
線上區塊鏈投票.pdf線上區塊鏈投票.pdf
線上區塊鏈投票.pdfBrownWood28
 
blockchain course (chinese)
blockchain course (chinese)blockchain course (chinese)
blockchain course (chinese)Moving Up Mobile
 
智能合約結合區塊鏈簡介
智能合約結合區塊鏈簡介智能合約結合區塊鏈簡介
智能合約結合區塊鏈簡介Nicholas Lin
 
Introduction bytom architecture 2018
Introduction bytom architecture 2018Introduction bytom architecture 2018
Introduction bytom architecture 2018Guofeng Wang
 
imtoken官网imtoken钱包imtoken冷钱包APP下载.pdf
imtoken官网imtoken钱包imtoken冷钱包APP下载.pdfimtoken官网imtoken钱包imtoken冷钱包APP下载.pdf
imtoken官网imtoken钱包imtoken冷钱包APP下载.pdfimtoken social
 
Blockchain 101 & 201
Blockchain 101 & 201Blockchain 101 & 201
Blockchain 101 & 201Benson Sun
 
201004 virtual data room advantages (chinese) (1)
201004 virtual data room advantages (chinese) (1)201004 virtual data room advantages (chinese) (1)
201004 virtual data room advantages (chinese) (1)EthosData
 

Similar to 在 Kotlin/Android 使用 Ethereum Smart Contract (16)

投資還是投機?帶你入門虛擬貨幣與區塊鏈
投資還是投機?帶你入門虛擬貨幣與區塊鏈投資還是投機?帶你入門虛擬貨幣與區塊鏈
投資還是投機?帶你入門虛擬貨幣與區塊鏈
 
Ethereum Smart Contract Development
Ethereum Smart Contract DevelopmentEthereum Smart Contract Development
Ethereum Smart Contract Development
 
Blockchain Development Presentation part-2
Blockchain Development Presentation part-2Blockchain Development Presentation part-2
Blockchain Development Presentation part-2
 
Blockchain Tutorial for Lawyers
Blockchain Tutorial for LawyersBlockchain Tutorial for Lawyers
Blockchain Tutorial for Lawyers
 
Build the Blockchain as service (BaaS) Using Ethereum on Kubernetes
Build the Blockchain as service (BaaS) Using Ethereum on KubernetesBuild the Blockchain as service (BaaS) Using Ethereum on Kubernetes
Build the Blockchain as service (BaaS) Using Ethereum on Kubernetes
 
blockchain&cryptocurrency
blockchain&cryptocurrencyblockchain&cryptocurrency
blockchain&cryptocurrency
 
Blockchain introduction for sharing
Blockchain introduction for sharingBlockchain introduction for sharing
Blockchain introduction for sharing
 
Blockchain 2.0 : Smart Contract 的美麗與哀愁
Blockchain 2.0 : Smart Contract 的美麗與哀愁Blockchain 2.0 : Smart Contract 的美麗與哀愁
Blockchain 2.0 : Smart Contract 的美麗與哀愁
 
線上區塊鏈投票.pdf
線上區塊鏈投票.pdf線上區塊鏈投票.pdf
線上區塊鏈投票.pdf
 
blockchain course (chinese)
blockchain course (chinese)blockchain course (chinese)
blockchain course (chinese)
 
智能合約結合區塊鏈簡介
智能合約結合區塊鏈簡介智能合約結合區塊鏈簡介
智能合約結合區塊鏈簡介
 
Introduction bytom architecture 2018
Introduction bytom architecture 2018Introduction bytom architecture 2018
Introduction bytom architecture 2018
 
imtoken官网imtoken钱包imtoken冷钱包APP下载.pdf
imtoken官网imtoken钱包imtoken冷钱包APP下载.pdfimtoken官网imtoken钱包imtoken冷钱包APP下载.pdf
imtoken官网imtoken钱包imtoken冷钱包APP下载.pdf
 
Intro to TrueBit
Intro to TrueBitIntro to TrueBit
Intro to TrueBit
 
Blockchain 101 & 201
Blockchain 101 & 201Blockchain 101 & 201
Blockchain 101 & 201
 
201004 virtual data room advantages (chinese) (1)
201004 virtual data room advantages (chinese) (1)201004 virtual data room advantages (chinese) (1)
201004 virtual data room advantages (chinese) (1)
 

More from Yenwen Feng

Lambda local - A local server for developing AWS Lambda function in Java
Lambda local - A local server for developing AWS Lambda function in JavaLambda local - A local server for developing AWS Lambda function in Java
Lambda local - A local server for developing AWS Lambda function in JavaYenwen Feng
 
Product Market Fit
Product Market FitProduct Market Fit
Product Market FitYenwen Feng
 
Introduction to Growth
Introduction to GrowthIntroduction to Growth
Introduction to GrowthYenwen Feng
 
消費性 APP 的募資經驗分享
消費性 APP 的募資經驗分享消費性 APP 的募資經驗分享
消費性 APP 的募資經驗分享Yenwen Feng
 
Thoughts behind Cubie Messenger
Thoughts behind Cubie MessengerThoughts behind Cubie Messenger
Thoughts behind Cubie MessengerYenwen Feng
 
Facebook flash api and social game development
Facebook flash api and social game developmentFacebook flash api and social game development
Facebook flash api and social game developmentYenwen Feng
 
Our experience to start a startup
Our experience to start a startupOur experience to start a startup
Our experience to start a startupYenwen Feng
 
GWT: Our Experiences
GWT: Our ExperiencesGWT: Our Experiences
GWT: Our ExperiencesYenwen Feng
 
Entrepreneurship3
Entrepreneurship3Entrepreneurship3
Entrepreneurship3Yenwen Feng
 
Intro to Google Gadgets
Intro to Google GadgetsIntro to Google Gadgets
Intro to Google GadgetsYenwen Feng
 
Suggestions for Building Websites
Suggestions for Building WebsitesSuggestions for Building Websites
Suggestions for Building WebsitesYenwen Feng
 
Ajax by Examples 2
Ajax by Examples 2Ajax by Examples 2
Ajax by Examples 2Yenwen Feng
 

More from Yenwen Feng (15)

Lambda local - A local server for developing AWS Lambda function in Java
Lambda local - A local server for developing AWS Lambda function in JavaLambda local - A local server for developing AWS Lambda function in Java
Lambda local - A local server for developing AWS Lambda function in Java
 
Product Market Fit
Product Market FitProduct Market Fit
Product Market Fit
 
Introduction to Growth
Introduction to GrowthIntroduction to Growth
Introduction to Growth
 
Growth
GrowthGrowth
Growth
 
Growth
GrowthGrowth
Growth
 
消費性 APP 的募資經驗分享
消費性 APP 的募資經驗分享消費性 APP 的募資經驗分享
消費性 APP 的募資經驗分享
 
Thoughts behind Cubie Messenger
Thoughts behind Cubie MessengerThoughts behind Cubie Messenger
Thoughts behind Cubie Messenger
 
Facebook flash api and social game development
Facebook flash api and social game developmentFacebook flash api and social game development
Facebook flash api and social game development
 
Our experience to start a startup
Our experience to start a startupOur experience to start a startup
Our experience to start a startup
 
GWT: Our Experiences
GWT: Our ExperiencesGWT: Our Experiences
GWT: Our Experiences
 
Entrepreneurship3
Entrepreneurship3Entrepreneurship3
Entrepreneurship3
 
Intro to Google Gadgets
Intro to Google GadgetsIntro to Google Gadgets
Intro to Google Gadgets
 
Suggestions for Building Websites
Suggestions for Building WebsitesSuggestions for Building Websites
Suggestions for Building Websites
 
Ajax by Examples 2
Ajax by Examples 2Ajax by Examples 2
Ajax by Examples 2
 
Hibernate Cache
Hibernate CacheHibernate Cache
Hibernate Cache
 

在 Kotlin/Android 使用 Ethereum Smart Contract