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
Ethereum 実習 / Practicing Ethereum
Search
Kenji Saito
PRO
October 31, 2018
Technology
0
110
Ethereum 実習 / Practicing Ethereum
2018年10月31日(水)、ブロックチェーンハブ主催で開催されたブロックチェーンアカデミー「【ハンズオン】スマートコントラクトプログラミング(2) イーサリアム実習」にて使用したスライドです。
Kenji Saito
PRO
October 31, 2018
Tweet
Share
More Decks by Kenji Saito
See All by Kenji Saito
関連2群のt検定/独立2群のt検定 / Related 2-group t-test and independent 2-group t-test
ks91
PRO
0
24
A Guide to Paper Writing Support with Generative AI - A Joint Zemi
ks91
PRO
0
6
正規分布と簡単な統計理論/t分布と信頼区間 / Normal distribution, simple statistical theory, t-distribution and confidence intervals
ks91
PRO
0
38
じわじわ迫ってきている自動化社会 (その先にメタ・ネイチャー) / The Slowly Approaching Automated Society (and its beyond: Meta-Nature)
ks91
PRO
0
6
起こりうる誤った推論/平均・分散・標準偏差・自由度 / Possible false inferences, means, variances, standard deviations and degrees of freedom
ks91
PRO
0
55
LaTeX と Overleaf によるショートペーパー作成 / Short paper writing with LaTeX and Overleaf
ks91
PRO
0
18
R を用いた検定(補講) (1) — Welch 検定 / Tests using R (supplementary) (1) - Welch test
ks91
PRO
0
11
R を用いた検定(補講) (2) — カイ二乗検定 / Tests using R (supplementary) (2) - Chi-squared test
ks91
PRO
0
12
R を用いた分析(補講) (1) — 重回帰分析 / Analysis using R (supplementary) (1) - Multiple regression analysis
ks91
PRO
0
10
Other Decks in Technology
See All in Technology
複雑性の高いオブジェクト編集に向き合う: プラガブルなReactフォーム設計
righttouch
PRO
0
110
PHPからGoへのマイグレーション for DMMアフィリエイト
yabakokobayashi
1
170
バクラクのドキュメント解析技術と実データにおける課題 / layerx-ccc-winter-2024
shimacos
2
1.1k
UI State設計とテスト方針
rmakiyama
2
550
生成AIをより賢く エンジニアのための RAG入門 - Oracle AI Jam Session #20
kutsushitaneko
4
220
宇宙ベンチャーにおける最近の情シス取り組みについて
axelmizu
0
110
権威ドキュメントで振り返る2024 #年忘れセキュリティ2024
hirotomotaguchi
2
740
re:Invent をおうちで楽しんでみた ~CloudWatch のオブザーバビリティ機能がスゴい!/ Enjoyed AWS re:Invent from Home and CloudWatch Observability Feature is Amazing!
yuj1osm
0
120
多領域インシデントマネジメントへの挑戦:ハードウェアとソフトウェアの融合が生む課題/Challenge to multidisciplinary incident management: Issues created by the fusion of hardware and software
bitkey
PRO
2
100
新機能VPCリソースエンドポイント機能検証から得られた考察
duelist2020jp
0
220
コンテナセキュリティのためのLandlock入門
nullpo_head
2
320
フロントエンド設計にモブ設計を導入してみた / 20241212_cloudsign_TechFrontMeetup
bengo4com
0
1.9k
Featured
See All Featured
KATA
mclloyd
29
14k
Helping Users Find Their Own Way: Creating Modern Search Experiences
danielanewman
29
2.3k
Into the Great Unknown - MozCon
thekraken
33
1.5k
Building Adaptive Systems
keathley
38
2.3k
Fashionably flexible responsive web design (full day workshop)
malarkey
405
66k
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
507
140k
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
2
290
Fontdeck: Realign not Redesign
paulrobertlloyd
82
5.3k
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
232
17k
Rebuilding a faster, lazier Slack
samanthasiow
79
8.7k
Documentation Writing (for coders)
carmenintech
66
4.5k
Designing Experiences People Love
moore
138
23k
Transcript
(2) CSO / SFC ( https://speakerdeck.com/ks91 )
[email protected]
— (2)
— 2018-10-31 – p.1/37
1. 2. 3. 4. 5. — (2) — 2018-10-31 –
p.2/37
1. : ERC20 2. : 3. : — (2) —
2018-10-31 – p.3/37
1. : ERC20 ERC20 — (2) — 2018-10-31 – p.4/37
BcH-smart-contract-programming.zip solidity 0.4.21 contracts tests ( ) — (2) —
2018-10-31 – p.5/37
Solidity JavaScript ( , ) (constructor) ( ) ( )
Ether — (2) — 2018-10-31 – p.6/37
pragma solidity ˆ0.4.24; contract MyToken { ( ) : (EVM
) : constructor (...) public { /* */ : } function MyToken(...) { /* ( ) */ : } : } constructor C (/* */ // ) — (2) — 2018-10-31 – p.7/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) — (2) — 2018-10-31 – p.8/37
MyToken string public _name; string public _symbol; uint8 public _decimals;
mapping (address => uint256) public _balanceOf; uint256 _totalSupply; _name, _symbol _decimals : 2 100 1.00 mapping _balanceOf ‘_’ Solidity . . . — (2) — 2018-10-31 – p.9/37
MyToken event Transfer(address indexed from, address indexed to, uint256 value);
indexed (3 ) MyToken function Transfer() — (2) — 2018-10-31 – p.10/37
MyToken constructor (uint256 supply, string name, string symbol, uint8 decimals)
public { if (supply == 0) { supply = 1000000; /* supply 1,000,000 */ } _totalSupply = supply; _balanceOf[msg.sender] = supply; _name = name; _symbol = symbol; _decimals = decimals; } msg.sender supply — (2) — 2018-10-31 – p.11/37
MyToken balanceOf() function balanceOf(address tokenOwner) external view returns (uint256) {
return _balanceOf[tokenOwner]; } — (2) — 2018-10-31 – p.12/37
MyToken transfer() function transfer(address to, uint256 value) external returns (bool)
{ require(value <= _balanceOf[msg.sender]); /* */ require(_balanceOf[to] + value >= _balanceOf[to]); /* */ _balanceOf[msg.sender] -= value; _balanceOf[to] += value; Transfer(msg.sender, to, value); return true; } require (function ) OpenZeppelin https://openzeppelin.org — (2) — 2018-10-31 – p.13/37
(1) import pytest @pytest.fixture() def token_contract(chain): TokenFactory = chain.provider.get_contract_factory(’MyToken’) deploy_txid
= TokenFactory.deploy(args=[ 0, "BcH Coin", "BcH", 0, ]) contract_address = chain.wait.for_contract_address(deploy_txid) return TokenFactory(address=contract_address) populus — (2) — 2018-10-31 – p.14/37
(2) def test_my_token(token_contract, chain): account0 = chain.web3.eth.accounts[0] account1 = chain.web3.eth.accounts[1]
assert token_contract.call().balanceOf(account0) == 1000000 assert token_contract.call().balanceOf(account1) == 0 txid = token_contract.transact().transfer(account1, 10) chain.wait.for_receipt(txid) assert token_contract.call().balanceOf(account0) == 999990 assert token_contract.call().balanceOf(account1) == 10 account0 coinbase account1 account0 account1 10BcH — (2) — 2018-10-31 – p.15/37
$ py.test -k test_my_token.py — (2) — 2018-10-31 – p.16/37
2. — (2) — 2018-10-31 – p.17/37
(m2 ) 1 1 — (2) — 2018-10-31 – p.18/37
IndivisibleAsset string public _name; string public _symbol; uint256 public _quantity;
address public _owner; _name ( ) _symbol _quantity (m2 ) _owner — (2) — 2018-10-31 – p.19/37
IndivisibleAsset event Transfer(address indexed from, address indexed to); from to
— (2) — 2018-10-31 – p.20/37
IndivisibleAsset constructor (string name, string symbol, uint256 quantity) public {
_name = name; _symbol = symbol; _quantity = quantity; _owner = msg.sender; } — (2) — 2018-10-31 – p.21/37
IndivisibleAsset getOwner() function getOwner() external view returns (address) { return
(_owner); } — (2) — 2018-10-31 – p.22/37
IndivisibleAsset transfer() function transfer(address to) external returns (bool) { require(_owner
== msg.sender); _owner = to; Transfer(msg.sender, to); return true; } ( / ) $ populus compile — (2) — 2018-10-31 – p.23/37
(1) import pytest @pytest.fixture() def asset_contract(chain): AssetFactory = chain.provider.get_contract_factory(’IndivisibleAsset’) deploy_txid
= AssetFactory.deploy(args=[ "5322 Endo, Fujisawa", "mˆ2", 300, ]) contract_address = chain.wait.for_contract_address(deploy_txid) return AssetFactory(address=contract_address) SFC (300m2 ) — (2) — 2018-10-31 – p.24/37
(2) def test_indivisible_assset(asset_contract, chain): account0 = chain.web3.eth.accounts[0] account1 = chain.web3.eth.accounts[1]
assert asset_contract.call().getOwner() == account0 txid = asset_contract.transact().transfer(account1) chain.wait.for_receipt(txid) assert asset_contract.call().getOwner() == account1 account0 account1 — (2) — 2018-10-31 – p.25/37
$ py.test -k test_indivisible_asset.py — (2) — 2018-10-31 – p.26/37
3. — (2) — 2018-10-31 – p.27/37
transfer settle, retrieve asset, retrieve token 3 — (2) —
2018-10-31 – p.28/37
1. ( ) 2. ( ) 3. ( ) —
(2) — 2018-10-31 – p.29/37
OneTimeEscrow settle() function settle() public returns (bool) { require(_token.balanceOf(this) >=
_price); /* this */ require(_asset.getOwner() == address(this)); _token.transfer(_seller , _price); _asset.transfer(_buyer); Settled(); /* */ return true; } settle() transfer ( / ) $ populus compile solidity 0.4.21 — (2) — 2018-10-31 – p.30/37
(1) import pytest @pytest.fixture() def token_contract(chain): . . . @pytest.fixture()
def asset_contract(chain): . . . — (2) — 2018-10-31 – p.31/37
(2) def test_one_time_escrow(token_contract, asset_contract, chain): account0 = chain.web3.eth.accounts[0] account1 =
chain.web3.eth.accounts[1] txid = chain.web3.eth.sendTransaction({ ’from’: account0, ’to’: account1, ’value’: chain.web3.toWei(1, "ether") }) chain.wait.for_receipt(txid) txid = token_contract.transact().transfer(account1, 300) chain.wait.for_receipt(txid) account0 account1 1Ether 300BcH 300BcH TX — (2) — 2018-10-31 – p.32/37
(3) EscrowFactory = chain.provider.get_contract_factory(’OneTimeEscrow’) txid = EscrowFactory.deploy(args=[ token_contract.address, account1, asset_contract.address,
account0, 300, ]) contract_address = chain.wait.for_contract_address(txid) EscrowFactory.address = contract_address; account1 account0 300BcH — (2) — 2018-10-31 – p.33/37
(4) txid = token_contract.transact({ ’from’: account1 }).transfer(contract_address, 300) chain.wait.for_receipt(txid) txid
= asset_contract.transact().transfer(contract_address) chain.wait.for_receipt(txid) assert token_contract.call().balanceOf(account0) == 999700 assert token_contract.call().balanceOf(account1) == 0 assert token_contract.call().balanceOf(contract_address) == 300 assert asset_contract.call().getOwner() == contract_address account1 300BcH account0 — (2) — 2018-10-31 – p.34/37
(5) txid = EscrowFactory.transact().settle(); chain.wait.for_receipt(txid) assert token_contract.call().balanceOf(account0) == 1000000 assert
token_contract.call().balanceOf(account1) == 0 assert token_contract.call().balanceOf(contract_address) == 0 assert asset_contract.call().getOwner() == account1 settle() — (2) — 2018-10-31 – p.35/37
$ py.test -k test_one_time_escrow.py : settle() — (2) — 2018-10-31
– p.36/37
BBc-1 1. BBc-1 2. BBc-1 3. 4. Ethereum ( )
— (2) — 2018-10-31 – p.37/37