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 / Practicing BBc-1 and E...
Search
Kenji Saito
PRO
May 27, 2020
Technology
0
80
BBc-1 と Ethereum 演習 II / Practicing BBc-1 and Ethereum II
2020年5月27日(水)、ブロックチェーンハブ主催のブロックチェーンアカデミー「実践!スマートコントラクトプログラミング 」第3回にて使用したスライドです。
Kenji Saito
PRO
May 27, 2020
Tweet
Share
More Decks by Kenji Saito
See All by Kenji Saito
アカデミーキャンプ 2025冬「考えるのは奴らだ」 / Academy Camp 2025 Winter - Live and Let Think DAY 3
ks91
PRO
0
14
アカデミーキャンプ 2025冬「考えるのは奴らだ」 / Academy Camp 2025 Winter - Live and Let Think DAY 2
ks91
PRO
0
22
アカデミーキャンプ 2025冬「考えるのは奴らだ」 / Academy Camp 2025 Winter - Live and Let Think DAY 1
ks91
PRO
1
41
インクルーシブな社会へ / Toward an Inclusive Society
ks91
PRO
0
5
P 値と有意差/分散分析 / P-value, Significant Difference and Analysis of Variance
ks91
PRO
0
39
関連2群のt検定/独立2群のt検定 / Related 2-group t-test and independent 2-group t-test
ks91
PRO
0
55
A Guide to Paper Writing Support with Generative AI - A Joint Zemi
ks91
PRO
0
15
正規分布と簡単な統計理論/t分布と信頼区間 / Normal distribution, simple statistical theory, t-distribution and confidence intervals
ks91
PRO
0
44
じわじわ迫ってきている自動化社会 (その先にメタ・ネイチャー) / The Slowly Approaching Automated Society (and its beyond: Meta-Nature)
ks91
PRO
0
12
Other Decks in Technology
See All in Technology
rootful・rootless・privilegedコンテナの違い/rootful_rootless_privileged_container_difference
moz_sec_
0
110
株式会社ログラス − エンジニア向け会社説明資料 / Loglass Comapany Deck for Engineer
loglass2019
3
33k
Zero Data Loss Autonomous Recovery Service サービス概要
oracle4engineer
PRO
1
5k
深層学習と3Dキャプチャ・3Dモデル生成(土木学会応用力学委員会 応用数理・AIセミナー)
pfn
PRO
0
410
ハイテク休憩
sat
PRO
2
190
20241228 - 成為最強魔法使!AI 實時生成比賽的策略 @ 2024 SD AI 年會
dpys
0
340
知っててうれしい HTTP Cookie を使ったセッション管理について
greendrop
1
110
.NET 9 のパフォーマンス改善
nenonaninu
0
2.2k
Google Cloud で始める Cloud Run 〜AWSとの比較と実例デモで解説〜
risatube
PRO
0
140
組織に自動テストを書く文化を根付かせる戦略(2024冬版) / Building Automated Test Culture 2024 Winter Edition
twada
PRO
26
7.1k
Denoで作るチーム開発生産性向上のためのCLIツール
sansantech
PRO
0
140
OCI技術資料 : ファイル・ストレージ 概要
ocise
3
12k
Featured
See All Featured
The MySQL Ecosystem @ GitHub 2015
samlambert
250
12k
The Cost Of JavaScript in 2023
addyosmani
46
7.2k
Product Roadmaps are Hard
iamctodd
PRO
50
11k
A Tale of Four Properties
chriscoyier
157
23k
Distributed Sagas: A Protocol for Coordinating Microservices
caitiem20
330
21k
Rails Girls Zürich Keynote
gr2m
94
13k
Chrome DevTools: State of the Union 2024 - Debugging React & Beyond
addyosmani
3
230
How to Create Impact in a Changing Tech Landscape [PerfNow 2023]
tammyeverts
49
2.2k
The Cult of Friendly URLs
andyhume
78
6.1k
I Don’t Have Time: Getting Over the Fear to Launch Your Podcast
jcasabona
29
2k
Put a Button on it: Removing Barriers to Going Fast.
kastner
59
3.6k
ピンチをチャンスに:未来をつくるプロダクトロードマップ #pmconf2020
aki_iinuma
112
50k
Transcript
3 BBc-1 Ethereum II CSO /
[email protected]
— 3 BBc-1
Ethereum II — 2020-05-27 – p.1/37
https://speakerdeck.com/ks91 — 3 BBc-1 Ethereum II — 2020-05-27 – p.2/37
( ) SFC / ( ) CSO (Chief Science Officer)
1993 ( ) 2006 ( ) SFC 19 P2P (Peer-to-Peer) ( 9 ) 2011 2018 2019 2019 2020 “STAY HOME, ENJOY LIFE” (in Zoom) → ( ) — 3 BBc-1 Ethereum II — 2020-05-27 – p.3/37
BBc-1 Ethereum 3 Ethereum — 3 BBc-1 Ethereum II —
2020-05-27 – p.4/37
1. : ERC20 2. : 3. : — 3 BBc-1
Ethereum II — 2020-05-27 – p.5/37
1. : ERC20 $ brownie bake token — 3 BBc-1
Ethereum II — 2020-05-27 – p.6/37
Solidity JavaScript ( , ) (constructor) ( ) ( )
Ether Ethereum — 3 BBc-1 Ethereum II — 2020-05-27 – p.7/37
pragma solidity ˆ0.5.0; contract Token { ( ) : (EVM
) : constructor (...) public { /* */ : } function balanceOf(...) { /* ( ) */ : } : } constructor C (/* */ // ) — 3 BBc-1 Ethereum II — 2020-05-27 – 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-05-27 – p.9/37
ERC20 ERC20 ( ) ⇒ ERC20 ( ERC20 ) ERC20
⇒ — 3 BBc-1 Ethereum II — 2020-05-27 – p.10/37
(fungible) ERC20 → ERC223 (draft) or ERC777 (non-fungible) ERC721 (
) (partially fungible) ERC1410 (draft) (ERC1400 ) — 3 BBc-1 Ethereum II — 2020-05-27 – 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-05-27 – p.12/37
Token ( ) event Transfer(address from, address to, uint256 value);
Token function emit Transfer() ( ) — 3 BBc-1 Ethereum II — 2020-05-27 – 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-05-27 – p.14/37
Token balanceOf() function balanceOf(address _owner) public view returns (uint256) {
return balances[_owner]; } — 3 BBc-1 Ethereum II — 2020-05-27 – 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-05-27 – p.16/37
2. — 3 BBc-1 Ethereum II — 2020-05-27 – p.17/37
GitHub git clone $ git clone https://github.com/ks91/sample-smart-contracts.git sample-smart-contracts contracts, scripts
tests token Token — 3 BBc-1 Ethereum II — 2020-05-27 – p.18/37
(m2 ) 1 1 — 3 BBc-1 Ethereum II —
2020-05-27 – 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-05-27 – p.20/37
IndivisibleAsset event Transfer(address indexed from, address indexed to); from to
indexed — 3 BBc-1 Ethereum II — 2020-05-27 – 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-05-27 – p.22/37
IndivisibleAsset getOwner() function getOwner() public view returns (address) { return
(_owner_); } — 3 BBc-1 Ethereum II — 2020-05-27 – 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-05-27 – 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-05-27 – 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-05-27 – p.26/37
$ pytest tests/test_indivisible_asset.py — 3 BBc-1 Ethereum II — 2020-05-27
– p.27/37
3. — 3 BBc-1 Ethereum II — 2020-05-27 – p.28/37
transfer settle, retrieve asset, retrieve token 3 — 3 BBc-1
Ethereum II — 2020-05-27 – p.29/37
1. ( ) 2. ( ) 3. ( ) —
3 BBc-1 Ethereum II — 2020-05-27 – 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-05-27 – 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-05-27 – 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-05-27 – 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-05-27 – 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-05-27 – p.35/37
$ pytest tests/test_one_time_escrow.py : settle() — 3 BBc-1 Ethereum II
— 2020-05-27 – p.36/37
4 BBc-1 Ethereum III : — 3 BBc-1 Ethereum II
— 2020-05-27 – p.37/37