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 Exerc...
Search
Kenji Saito
PRO
May 26, 2021
Technology
0
43
BBc-1 とEthereum 演習II / BBc-1 and Ethereum Exercise II
2021年5月26日(水)、ブロックチェーンハブ主催のブロックチェーンアカデミー「実践!スマートコントラクトプログラミング 」第3回にて使用したスライドです。
Kenji Saito
PRO
May 26, 2021
Tweet
Share
More Decks by Kenji Saito
See All by Kenji Saito
デジタルトランスフォーメーションと民主主義 / Digital Transformation and Democracy
ks91
PRO
0
5
We Never Took the Kobayashi Maru Test Until Now. What Do You Think of Our Solutions? — Journeys of the Mind Through a No-Win Game
ks91
PRO
0
17
思いつきが武器になる:研究というゲームを始めよう / Ideas Are Your Equipments : Let the Game of Research Begin!
ks91
PRO
0
75
ロボットを雰囲気(ヴァイブ)でプログラミングするこどもたち / Children Vibe-Programming Robots
ks91
PRO
0
22
アカデミーキャンプ 2025 SuuuuuuMMeR「燃えろ!!ロボコン」 / Academy Camp 2025 SuuuuuuMMeR "Burn the Spirit, Robocon!!" DAY 3
ks91
PRO
0
31
アカデミーキャンプ 2025 SuuuuuuMMeR「燃えろ!!ロボコン」 / Academy Camp 2025 SuuuuuuMMeR "Burn the Spirit, Robocon!!" DAY 2
ks91
PRO
0
34
アカデミーキャンプ 2025 SuuuuuuMMeR「燃えろ!!ロボコン」 / Academy Camp 2025 SuuuuuuMMeR "Burn the Spirit, Robocon!!" DAY 1
ks91
PRO
0
160
未来へのフォワードキャスト / Forward Cast to the Future
ks91
PRO
0
88
発表と総括 / Presentations and Summary
ks91
PRO
0
62
Other Decks in Technology
See All in Technology
💡Ruby 川辺で灯すPicoRubyからの光
bash0c7
0
120
【初心者向け】ローカルLLMの色々な動かし方まとめ
aratako
7
3.5k
新規プロダクトでプロトタイプから正式リリースまでNext.jsで開発したリアル
kawanoriku0
1
120
OCI Oracle Database Services新機能アップデート(2025/06-2025/08)
oracle4engineer
PRO
0
150
2025年夏 コーディングエージェントを統べる者
nwiizo
0
170
CDK CLIで使ってたあの機能、CDK Toolkit Libraryではどうやるの?
smt7174
4
180
サラリーマンの小遣いで作るtoCサービス - Cloudflare Workersでスケールする開発戦略
shinaps
2
450
AI時代を生き抜くエンジニアキャリアの築き方 (AI-Native 時代、エンジニアという道は 「最大の挑戦の場」となる) / Building an Engineering Career to Thrive in the Age of AI (In the AI-Native Era, the Path of Engineering Becomes the Ultimate Arena of Challenge)
jeongjaesoon
0
160
初めてAWSを使うときのセキュリティ覚書〜初心者支部編〜
cmusudakeisuke
1
260
COVESA VSSによる車両データモデルの標準化とAWS IoT FleetWiseの活用
osawa
1
290
フルカイテン株式会社 エンジニア向け採用資料
fullkaiten
0
8.7k
未経験者・初心者に贈る!40分でわかるAndroidアプリ開発の今と大事なポイント
operando
5
640
Featured
See All Featured
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
12
1.1k
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
234
17k
Context Engineering - Making Every Token Count
addyosmani
3
47
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
162
15k
Six Lessons from altMBA
skipperchong
28
4k
The Cost Of JavaScript in 2023
addyosmani
53
8.9k
Designing Dashboards & Data Visualisations in Web Apps
destraynor
231
53k
Keith and Marios Guide to Fast Websites
keithpitt
411
22k
Code Review Best Practice
trishagee
70
19k
Rails Girls Zürich Keynote
gr2m
95
14k
Put a Button on it: Removing Barriers to Going Fast.
kastner
60
4k
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
26
3k
Transcript
3 BBc-1 Ethereum II CSO /
[email protected]
— 3 BBc-1
Ethereum II — 2021-05-26 – p.1/37
https://speakerdeck.com/ks91 — 3 BBc-1 Ethereum II — 2021-05-26 – p.2/37
( ) SFC ( ) CSO (Chief Science Officer) 1993
( ) 2006 ( ) SFC 20 P2P (Peer-to-Peer) ( 2019 9 ) 2011 2018 2019 2021 VR 2021.5 ( ) → ( ) — 3 BBc-1 Ethereum II — 2021-05-26 – p.3/37
BBc-1 Ethereum 3 Ethereum — 3 BBc-1 Ethereum II —
2021-05-26 – p.4/37
1. : ERC20 2. : 3. : — 3 BBc-1
Ethereum II — 2021-05-26 – p.5/37
1. : ERC20 $ brownie bake token — 3 BBc-1
Ethereum II — 2021-05-26 – p.6/37
Solidity JavaScript ( , ) (constructor) ( ) ( )
Ether Ethereum — 3 BBc-1 Ethereum II — 2021-05-26 – p.7/37
pragma solidity ˆ0.6.0; /* 0.8.x */ contract Token { (
) : (EVM ) : constructor (...) public { /* */ : } function balanceOf(...) { /* ( ) */ : } : } constructor C (/* */ // ) — 3 BBc-1 Ethereum II — 2021-05-26 – 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 — 2021-05-26 – p.9/37
ERC20 ERC20 ( ) ⇒ ERC20 ( ERC20 ) ERC20
⇒ — 3 BBc-1 Ethereum II — 2021-05-26 – p.10/37
(fungible) ERC20 → ERC223 (draft) or ERC777 (non-fungible) ERC721 (
) (partially fungible) ERC1410 (draft) (ERC1400 ) — 3 BBc-1 Ethereum II — 2021-05-26 – 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 — 2021-05-26 – p.12/37
Token ( ) event Transfer(address from, address to, uint256 value);
Token function emit Transfer() ( ) — 3 BBc-1 Ethereum II — 2021-05-26 – 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 — 2021-05-26 – p.14/37
Token balanceOf() function balanceOf(address _owner) public view returns (uint256) {
return balances[_owner]; } — 3 BBc-1 Ethereum II — 2021-05-26 – 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 — 2021-05-26 – p.16/37
2. — 3 BBc-1 Ethereum II — 2021-05-26 – 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 — 2021-05-26 – p.18/37
(m2 ) 1 1 — 3 BBc-1 Ethereum II —
2021-05-26 – 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 — 2021-05-26 – p.20/37
IndivisibleAsset event Transfer(address indexed from, address indexed to); from to
indexed — 3 BBc-1 Ethereum II — 2021-05-26 – 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 — 2021-05-26 – p.22/37
IndivisibleAsset getOwner() function getOwner() public view returns (address) { return
(_owner_); } — 3 BBc-1 Ethereum II — 2021-05-26 – 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 — 2021-05-26 – 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 — 2021-05-26 – 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 — 2021-05-26 – p.26/37
$ pytest tests/test_indivisible_asset.py — 3 BBc-1 Ethereum II — 2021-05-26
– p.27/37
3. — 3 BBc-1 Ethereum II — 2021-05-26 – p.28/37
transfer settle, retrieve asset, retrieve token 3 — 3 BBc-1
Ethereum II — 2021-05-26 – p.29/37
1. ( ) 2. ( ) 3. ( ) —
3 BBc-1 Ethereum II — 2021-05-26 – 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 — 2021-05-26 – 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 — 2021-05-26 – 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 — 2021-05-26 – 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 — 2021-05-26 – 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 — 2021-05-26 – p.35/37
$ pytest tests/test_one_time_escrow.py : settle() — 3 BBc-1 Ethereum II
— 2021-05-26 – p.36/37
4 BBc-1 Ethereum III : — 3 BBc-1 Ethereum II
— 2021-05-26 – p.37/37