Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
BBc-1 と Ethereum 演習 II / BBc-1 and Ethereum Exe...
Search
Kenji Saito
PRO
December 16, 2020
Technology
0
63
BBc-1 と Ethereum 演習 II / BBc-1 and Ethereum Exercise II
2020年12月16日(水)、ブロックチェーンハブ主催のブロックチェーンアカデミー「実践!スマートコントラクトプログラミング 」第3回にて使用したスライドです。
Kenji Saito
PRO
December 16, 2020
Tweet
Share
More Decks by Kenji Saito
See All by Kenji Saito
マニフェスト: 人類の知のフロンティアに向けた拡張的足場へ / Manifesto: Toward Expansive Scaffolding for Humanity's Knowledge Frontier
ks91
PRO
0
8
続・スマートコントラクトと分散ファイナンス / Smart Contracts and Decentralized Finance, Continued
ks91
PRO
0
42
スマートコントラクトと分散ファイナンス / Smart Contracts and Decentralized Finance
ks91
PRO
0
63
シン・ブロックチェーン / Truth of Blockchain
ks91
PRO
0
94
パスワード/パスフレーズと認証 / Password, Passphrase and Authentication
ks91
PRO
0
37
git と GitHub / git and GitHub
ks91
PRO
0
36
ソフトウェアの開発と保守 / Software Development and Maintenance
ks91
PRO
0
50
インターネットの特徴 / Features of the Internet
ks91
PRO
0
34
インターネットのガバナンス / Governance of the Internet
ks91
PRO
0
30
Other Decks in Technology
See All in Technology
OSSのSNSツール「Misskey」をさわってみよう(右下ワイプで私のOSCの20年を振り返ります) / 20250705-osc2025-do
akkiesoft
0
170
ビズリーチにおけるリアーキテクティング実践事例 / JJUG CCC 2025 Spring
visional_engineering_and_design
1
120
Getting to Know Your Legacy (System) with AI-Driven Software Archeology (WeAreDevelopers World Congress 2025)
feststelltaste
1
130
生成AI活用の組織格差を解消する 〜ビジネス職のCursor導入が開発効率に与えた好循環〜 / Closing the Organizational Gap in AI Adoption
upamune
7
5.3k
DBのスキルで生き残る技術 - AI時代におけるテーブル設計の勘所
soudai
PRO
50
20k
Lakebaseを使ったAIエージェントを実装してみる
kameitomohiro
0
130
United airlines®️ USA Contact Numbers: Complete 2025 Support Guide
unitedflyhelp
0
310
DatabricksにOLTPデータベース『Lakebase』がやってきた!
inoutk
0
110
20250707-AI活用の個人差を埋めるチームづくり
shnjtk
4
3.9k
LangSmith×Webhook連携で実現するプロンプトドリブンCI/CD
sergicalsix
1
230
マネジメントって難しい、けどおもしろい / Management is tough, but fun! #em_findy
ar_tama
7
1.1k
LangChain Interrupt & LangChain Ambassadors meetingレポート
os1ma
2
310
Featured
See All Featured
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
50
5.5k
Thoughts on Productivity
jonyablonski
69
4.7k
BBQ
matthewcrist
89
9.7k
Balancing Empowerment & Direction
lara
1
430
Become a Pro
speakerdeck
PRO
29
5.4k
How To Stay Up To Date on Web Technology
chriscoyier
790
250k
No one is an island. Learnings from fostering a developers community.
thoeni
21
3.4k
Testing 201, or: Great Expectations
jmmastey
43
7.6k
Save Time (by Creating Custom Rails Generators)
garrettdimon
PRO
31
1.3k
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
26
2.9k
Improving Core Web Vitals using Speculation Rules API
sergeychernyshev
18
970
Imperfection Machines: The Place of Print at Facebook
scottboms
267
13k
Transcript
3 BBc-1 Ethereum II CSO /
[email protected]
— 3 BBc-1
Ethereum II — 2020-12-16 – p.1/37
https://speakerdeck.com/ks91 — 3 BBc-1 Ethereum II — 2020-12-16 – p.2/37
( ) SFC ( ) CSO (Chief Science Officer) 1993
( ) 2006 ( ) SFC 20 P2P (Peer-to-Peer) ( 9 ) 2011 2018 2019 2019 2020 2020 → ( ) — 3 BBc-1 Ethereum II — 2020-12-16 – p.3/37
BBc-1 Ethereum 3 Ethereum — 3 BBc-1 Ethereum II —
2020-12-16 – p.4/37
1. : ERC20 2. : 3. : — 3 BBc-1
Ethereum II — 2020-12-16 – p.5/37
1. : ERC20 $ brownie bake token — 3 BBc-1
Ethereum II — 2020-12-16 – p.6/37
Solidity JavaScript ( , ) (constructor) ( ) ( )
Ether Ethereum — 3 BBc-1 Ethereum II — 2020-12-16 – p.7/37
pragma solidity ˆ0.6.0; /* 0.7.x */ contract Token { (
) : (EVM ) : constructor (...) public { /* */ : } function balanceOf(...) { /* ( ) */ : } : } constructor C (/* */ // ) — 3 BBc-1 Ethereum II — 2020-12-16 – p.8/37
ERC20 ERC (Ethereum Request for Comment) 20 https://github.com/ethereum/EIPs/blob/master/EIPS/eip-20.md contract ERC20
{ function totalSupply() constant returns (uint totalSupply); function balanceOf(address _owner) constant returns (uint balance); function transfer(address _to, uint _value) returns (bool success); function transferFrom(address _from, address _to, uint _value) returns (bool success); function approve(address _spender, uint _value) returns (bool success); function allowance(address _owner, address _spender) constant returns (uint remaining); event Transfer(address indexed _from, address indexed _to, uint _value); event Approval(address indexed _owner, address indexed _spender, uint _value); } name/ , symbol/ , decimals/ approve allowance ERC223 ( ), ERC721 (Non-Fungible) — 3 BBc-1 Ethereum II — 2020-12-16 – p.9/37
ERC20 ERC20 ( ) ⇒ ERC20 ( ERC20 ) ERC20
⇒ — 3 BBc-1 Ethereum II — 2020-12-16 – p.10/37
(fungible) ERC20 → ERC223 (draft) or ERC777 (non-fungible) ERC721 (
) (partially fungible) ERC1410 (draft) (ERC1400 ) — 3 BBc-1 Ethereum II — 2020-12-16 – p.11/37
Token ( ) string public symbol; string public name; uint256
public decimals; uint256 public totalSupply; mapping(address => uint256) balances; . . . name, symbol decimals : 2 100 1.00 mapping balances — 3 BBc-1 Ethereum II — 2020-12-16 – p.12/37
Token ( ) event Transfer(address from, address to, uint256 value);
Token function emit Transfer() ( ) — 3 BBc-1 Ethereum II — 2020-12-16 – p.13/37
Token ( ) constructor( string memory _symbol, string memory _name,
uint256 _decimals, uint256 _totalSupply ) public { symbol = _symbol; name = _name; decimals = _decimals; totalSupply = _totalSupply; balances[msg.sender] = _totalSupply; } msg.sender _totalSupply — 3 BBc-1 Ethereum II — 2020-12-16 – p.14/37
Token balanceOf() function balanceOf(address _owner) public view returns (uint256) {
return balances[_owner]; } — 3 BBc-1 Ethereum II — 2020-12-16 – p.15/37
Token transfer() function transfer(address _to, uint256 _value) public returns (bool)
{ balances[msg.sender] = balances[msg.sender].sub(_value); balances[_to] = balances[_to].add(_value); emit Transfer(msg.sender, _to, _value); return true; } OpenZeppelin https://openzeppelin.org — 3 BBc-1 Ethereum II — 2020-12-16 – p.16/37
2. — 3 BBc-1 Ethereum II — 2020-12-16 – p.17/37
GitHub git clone $ git clone https://github.com/ks91/sample-smart-contracts.git sample-smart-contracts contracts, scripts
tests token Token Solidity 0.5 0.6/0.7 (Token ) Token Solidity 0.5 0.6 Solidity — 3 BBc-1 Ethereum II — 2020-12-16 – p.18/37
(m2 ) 1 1 — 3 BBc-1 Ethereum II —
2020-12-16 – p.19/37
IndivisibleAsset string public _name_; string public _symbol_; uint256 public _quantity_;
address public _owner_; _name_ ( ) _symbol_ _quantity_ (m2 ) _owner_ ‘_’ Solidity . . . — 3 BBc-1 Ethereum II — 2020-12-16 – p.20/37
IndivisibleAsset event Transfer(address indexed from, address indexed to); from to
indexed — 3 BBc-1 Ethereum II — 2020-12-16 – p.21/37
IndivisibleAsset constructor (string name, string symbol, uint256 quantity) public {
_name_ = name; _symbol_ = symbol; _quantity_ = quantity; _owner_ = msg.sender; } — 3 BBc-1 Ethereum II — 2020-12-16 – p.22/37
IndivisibleAsset getOwner() function getOwner() public view returns (address) { return
(_owner_); } — 3 BBc-1 Ethereum II — 2020-12-16 – p.23/37
IndivisibleAsset transfer() function transfer(address to) public returns (bool) { require(_owner_
== msg.sender); _owner_ = to; emit Transfer(msg.sender, to); return true; } require (function ) ( ) $ brownie compile — 3 BBc-1 Ethereum II — 2020-12-16 – p.24/37
scripts/indivisible asset.py from brownie import * def main(): accounts[0].deploy(IndivisibleAsset, "5322
Endo, Fujisawa", "mˆ2", 300) SFC (300m2 ) ( ) — 3 BBc-1 Ethereum II — 2020-12-16 – p.25/37
from brownie import * import pytest def test_owner_and_transfer(IndivisibleAsset): asset =
accounts[0].deploy(IndivisibleAsset, "5322 Endo", "mˆ2", 300) assert asset.getOwner() == accounts[0] asset.transfer(accounts[1], {’from’: accounts[0]}) assert asset.getOwner() == accounts[1] try: asset.transfer(accounts[0], {’from’: accounts[0]}) done = 1 except: done = 0 assert done == 0 accounts[0] accounts[1] — 3 BBc-1 Ethereum II — 2020-12-16 – p.26/37
$ pytest tests/test_indivisible_asset.py — 3 BBc-1 Ethereum II — 2020-12-16
– p.27/37
3. — 3 BBc-1 Ethereum II — 2020-12-16 – p.28/37
transfer settle, retrieve asset, retrieve token 3 — 3 BBc-1
Ethereum II — 2020-12-16 – p.29/37
1. ( ) 2. ( ) 3. ( ) —
3 BBc-1 Ethereum II — 2020-12-16 – p.30/37
OneTimeEscrow settle() function settle() public returns (bool) { require(_token_.balanceOf(address(this)) >=
_price_); /* this */ require(_asset_.getOwner() == address(this)); _token_.transfer(_seller_ , _price_); _asset_.transfer(_buyer_); emit Settled(); /* */ return true; } settle() transfer ( / ) $ brownie compile — 3 BBc-1 Ethereum II — 2020-12-16 – p.31/37
(1) from brownie import * import pytest def test_deploy_and_settle(Token, IndivisibleAsset,
OneTimeEscrow): asset = accounts[0].deploy(IndivisibleAsset, "5322 Endo", "mˆ2", 300) token = accounts[0].deploy(Token, "Test Token", "TEST", 18, "1000 ether") — 3 BBc-1 Ethereum II — 2020-12-16 – p.32/37
(2) token.transfer(accounts[1], 300, {’from’: accounts[0]}) escrow = accounts[0].deploy(OneTimeEscrow, token, accounts[1],
asset, accounts[0], 300) accounts[0] accounts[1] 300 300 TX accounts[1] accounts[0] 300 bake Token 300 ETH wei — 3 BBc-1 Ethereum II — 2020-12-16 – p.33/37
(3) token.transfer(escrow, 300, {’from’: accounts[1]}) asset.transfer(escrow, {’from’: accounts[0]}) assert token.balanceOf(accounts[0])
== 999999999999999999700 assert token.balanceOf(accounts[1]) == 0 assert token.balanceOf(escrow) == 300 assert asset.getOwner() == escrow accounts[1] ( ) 300 accounts[0] ( ) — 3 BBc-1 Ethereum II — 2020-12-16 – p.34/37
(4) escrow.settle({’from’: accounts[0]}) assert token.balanceOf(accounts[0]) == 1000000000000000000000 assert token.balanceOf(accounts[1]) ==
0 assert token.balanceOf(escrow) == 0 assert asset.getOwner() == accounts[1] settle() accounts[0] OK — 3 BBc-1 Ethereum II — 2020-12-16 – p.35/37
$ pytest tests/test_one_time_escrow.py : settle() — 3 BBc-1 Ethereum II
— 2020-12-16 – p.36/37
4 BBc-1 Ethereum III : — 3 BBc-1 Ethereum II
— 2020-12-16 – p.37/37