1
ArcBlock Technical Learning Series
Introduction to Ethereum Smart Contract
2
Introduction to Ethereum Smart Contract
Shijun 20180927
Big Picture
3
Agenda
What is Smart
Contract?
How to write Smart
Contract?
Smart Contract
Tooling?
4
Smart Contract Best
Practice?
Before Dive Into Smart Contract
Core Concepts of Blockchain
6
Ethereum Network = Distributed Network
7
What Is Smart Contract?
What is Smart Contract? (Conceptual)
9
source: https://github.com/Overtorment/awesome-smart-contracts
What is Smart Contract? (Technical)
10
source: https://solidity.readthedocs.io/en/v0.4.24/introduction-to-smart-contracts.html
Contract = Account Controlled By Immutable Code
Contract Account vs. User Account
11
12
3
From Contract Source to Contract Account?
12
Contract Source & Contract Account
13
How To Write Smart Contract?
Solidity Programming Language
๏ Contract oriented, influenced by C++/JS/Python
๏ Statically typed, support inheritance
๏ Source file has .sol extension
๏ Compile to bytecode and run in EVM
๏ Javascript similar syntax (not that similar)
15
Solidity 101: Primitive Types
16
Solidity 101: Reference Types
17
Solidity 101: Functions
18
Assertions Modifiers
Function Call vs. Transaction
19
Solidity 101: Global Variables/Fns
20
block util fns
Demo1
Smart Contract Hello World (Remix: Bytecode + ABI)
21
Smart Contract Tooling?
Code Editor
23
Remix VSCode + Node.js
• Rapid contract prototyping
• Testing with existing instance
• Deploy to any valid network
• Mange code using Git
• Save compile/deploy to file
• Automate things
+
Debug/Inspection
๏ Block Explorer
• etherscan.io
• rinkeby.etherscan.io
• ropsten.etherscan.io
• kovan.etherscan.io
๏ Remix
• Debugger mode
• Transaction Log
24
Testnet/Nodes
๏ Ethereum official testnet (real latency)
• rinkeby
• ropsten
• kovan
๏ In memory testnet (low latency)
• ganache-cli
• remix javascript vm
๏ Infura.io nodes
• require registration
25
Funding for Testing
26
Faucet Builtin Unlocked
• Rinkeby Faucet
• Ropsten Faucet
• Kovan Faucet
• Ganache-cli
• Remix in memory node
Transaction Sign/Send
27
GUI SDK
• Metamask • Javascript: web3.js
• Java: web3j
• Swift: web3.swift
Framework: truffle
28
Demo2
Creating ABT Token Using Remix + Metamask + Rinkeby
29
Smart Contract Best Practice?
Considerations need to write good Contract
๏ Security
• Overflow, using SafeMath library
• Identity check and assertion, using function modifiers
๏ Performance
• Design storage carefully
• Avoid computation intensive contract code: loops
๏ Engineering
• Do automated tests
• Make code modular
31
Demo3
Security practices in ArcBlock Token
32
Where To Go From Here?
Smart Contract + DApp = Awesome
๏ What is DApp?
• End-user app that interacts with contract
• An interface that read/render/update contract data
• Can be in form of Web/Native/Desktop App
• Can be SPA with only blockchain backend
34
Resources From Community
๏ Official documentation
• Solidity
• web3.js 1.x
๏ Awesome series
• BlockchainLabsNZ/awesome-solidity
• cjgdev/awesome-smart-contracts
• JoinColony/awesome-web3
• fivedogit/solidity-baby-steps
35
Resources From Me
๏ Contract + DApp Examples
• Lottery App: wangshijun/ethereum-lottery-dapp
• ICO DApp (Nuxt.js): wangshijun/ethereum-dapp-nuxt
• ICO DApp (Next.js): wangshijun/ethereum-contract-workflow
๏ 掘金小册
• 《从 0 到 1 构建基于以太坊智能合约的 ICO DApp》
36
七折优惠码:shijunvip
Get your hands dirty and build something! 😆
Q&A
38

Introduction to Ethereum Smart Contracts