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 Exercise II
Search
Kenji Saito
PRO
September 28, 2022
Technology
0
110
BBc-1 と Ethereum 演習 II / BBc-1 and Ethereum Exercise II
2022年9月28日(水)、ブロックチェーンハブ主催のブロックチェーンアカデミーにて使用したスライドです。
Kenji Saito
PRO
September 28, 2022
Tweet
Share
More Decks by Kenji Saito
See All by Kenji Saito
ワールドカフェI /チューターを改良する / World Café I and Improving the Tutors
ks91
PRO
0
120
LLM とプロンプトエンジニアリング/チューターをビルドする / LLM and Prompt Engineering and Building Tutors
ks91
PRO
0
250
講師自己紹介 / Lecturer's Self-Introduction
ks91
PRO
0
82
講師研究紹介 / Lecturer's Research Introduction
ks91
PRO
0
67
Discord とビルダー&チャットボットの使い方 / How to use Discord and Builder & Chatbots
ks91
PRO
0
160
研究って何だっけ / What's Research?
ks91
PRO
0
27
ブロックチェーンと分散ファイナンス概論 / Introduction to Blockchain and Decentralized Finance
ks91
PRO
0
18
招き猫コマロ— ネットワーク贈答経済のエージェント / Manekineko Komaro - Network Gift Economy Agent
ks91
PRO
0
17
Implementation of Blockchain Ecosystems
ks91
PRO
0
12
Other Decks in Technology
See All in Technology
データベース02: データベースの概念
trycycle
0
160
私が trocco を推す理由
__allllllllez__
1
250
複雑な構成要素を持つUIとの向き合い方 〜新・支出グラフでの実例〜 / B43 TECH TALK
nakamuuu
0
140
KubeCon EU 2024 Recap “Kubernetes Policy Time Machine: Where to Next?”
ryysud
0
220
生成AIの変革の時代に、直近1年で直面した課題とその解決策
ktc_wada
0
310
JSON攻略法.pdf
miyakemito
8
5.1k
Compose Compiler Metricsを使った実践的なコードレビュー
tomorrowkey
1
220
Cloud Native Java with Spring Boot (CNCF Aarhus, April 2024)
thomasvitale
1
170
レガシーをぶっ壊せ。AEONで始めるDevRelの話 / Qiita Night 2024-2-22
aeonpeople
3
1.3k
LLM開発・活用の舞台裏@2024.04.25
yushin_n
1
350
現代CSSフレームワークの内部実装とその仕組み
poteboy
7
3.6k
[新卒向け研修資料] テスト文字列に「うんこ」と入れるな(2024年版)
infiniteloop_inc
4
16k
Featured
See All Featured
A Tale of Four Properties
chriscoyier
151
22k
Building Adaptive Systems
keathley
31
1.9k
Making Projects Easy
brettharned
108
5.5k
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
40
4.4k
Debugging Ruby Performance
tmm1
70
11k
[RailsConf 2023] Rails as a piece of cake
palkan
23
4k
VelocityConf: Rendering Performance Case Studies
addyosmani
320
23k
Done Done
chrislema
178
15k
YesSQL, Process and Tooling at Scale
rocio
164
13k
Understanding Cognitive Biases in Performance Measurement
bluesmoon
7
1k
Being A Developer After 40
akosma
57
580k
Helping Users Find Their Own Way: Creating Modern Search Experiences
danielanewman
20
1.9k
Transcript
3 BBc-1 Ethereum II CSO /
[email protected]
— 3 BBc-1
Ethereum II — 2022-09-28 – p.1/37
https://speakerdeck.com/ks91 — 3 BBc-1 Ethereum II — 2022-09-28 – p.2/37
( ) SFC ( ) CSO (Chief Science Officer) 1993
( ) 2006 ( ) SFC 22 P2P (Peer-to-Peer) 2011 ( ) 2018 2019 VR 2021.7 VR 2021.8 “ALL THESE WORLDS ARE YOURS” VR 2021.9 & VR 2021.12 VR 2022.3 VR 2022.8 → ( ) — 3 BBc-1 Ethereum II — 2022-09-28 – p.3/37
BBc-1 Ethereum 3 Ethereum — 3 BBc-1 Ethereum II —
2022-09-28 – p.4/37
1. : ERC-20 2. : 3. : — 3 BBc-1
Ethereum II — 2022-09-28 – p.5/37
1. : ERC-20 $ brownie bake token — 3 BBc-1
Ethereum II — 2022-09-28 – p.6/37
Solidity JavaScript ( , ) (constructor) ( ) ( )
Ether Ethereum — 3 BBc-1 Ethereum II — 2022-09-28 – 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 — 2022-09-28 – p.8/37
ERC-20 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 ERC-777 ( ) — 3 BBc-1 Ethereum II — 2022-09-28 – p.9/37
ERC-20 ERC-20 ( ) ⇒ ERC-20 ( ERC-20 ) ERC-20
⇒ — 3 BBc-1 Ethereum II — 2022-09-28 – p.10/37
(fungible) ERC-20 → ERC-223 (draft) or ERC-777 ( )( )
(non-fungible) ERC-721 ( ) ERC-1155 ( ) ERC-3525 (SLOT ) — 3 BBc-1 Ethereum II — 2022-09-28 – 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 — 2022-09-28 – p.12/37
Token ( ) event Transfer(address from, address to, uint256 value);
Token function emit Transfer() ( ) — 3 BBc-1 Ethereum II — 2022-09-28 – 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 — 2022-09-28 – p.14/37
Token balanceOf() function balanceOf(address _owner) public view returns (uint256) {
return balances[_owner]; } — 3 BBc-1 Ethereum II — 2022-09-28 – p.15/37
Token transfer() function transfer(address _to, uint256 _value) public returns (bool)
{ require(balances[msg.sender] >= _value, "Insufficient balance"); balances[msg.sender] = balances[msg.sender].sub(_value); balances[_to] = balances[_to].add(_value); emit Transfer(msg.sender, _to, _value); return true; } require (function ) ( ↑ ) OpenZeppelin https://openzeppelin.org — 3 BBc-1 Ethereum II — 2022-09-28 – p.16/37
2. — 3 BBc-1 Ethereum II — 2022-09-28 – 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 — 2022-09-28 – p.18/37
(m2 ) 1 1 — 3 BBc-1 Ethereum II —
2022-09-28 – 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 — 2022-09-28 – p.20/37
IndivisibleAsset event Transfer(address indexed from, address indexed to); from to
indexed — 3 BBc-1 Ethereum II — 2022-09-28 – 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 — 2022-09-28 – p.22/37
IndivisibleAsset getOwner() function getOwner() public view returns (address) { return
(_owner_); } — 3 BBc-1 Ethereum II — 2022-09-28 – 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 — 2022-09-28 – 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 — 2022-09-28 – 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 — 2022-09-28 – p.26/37
$ pytest tests/test_indivisible_asset.py — 3 BBc-1 Ethereum II — 2022-09-28
– p.27/37
3. — 3 BBc-1 Ethereum II — 2022-09-28 – p.28/37
transfer settle, retrieve asset, retrieve token 3 — 3 BBc-1
Ethereum II — 2022-09-28 – p.29/37
1. ( ) 2. ( ) 3. ( ) —
3 BBc-1 Ethereum II — 2022-09-28 – 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 — 2022-09-28 – 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 — 2022-09-28 – 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 — 2022-09-28 – 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 — 2022-09-28 – 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 — 2022-09-28 – p.35/37
$ pytest tests/test_one_time_escrow.py : settle() — 3 BBc-1 Ethereum II
— 2022-09-28 – p.36/37
4 BBc-1 Ethereum III (1): NFT (2): DAO — 3
BBc-1 Ethereum II — 2022-09-28 – p.37/37