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
Dapps開発におけるSoliidityのはまりどころ
Search
Sponsored
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
yudetamago
March 16, 2018
Technology
3
2.4k
Dapps開発におけるSoliidityのはまりどころ
yudetamago
March 16, 2018
Tweet
Share
More Decks by yudetamago
See All by yudetamago
ブロックチェーンとIndexer
yudetamago
0
960
Unityでブロックチェーンアプリを作る
yudetamago
0
1.8k
DApps開発特有の_ハマりポイントご紹介.pdf
yudetamago
1
1.4k
スマートコントラクトの監査について
yudetamago
2
620
DApps開発事例 ~CryptoCrystal概要編~
yudetamago
3
340
Gasを誰が払うのか問題について
yudetamago
5
4.6k
Solidityの複数コントラク ト連携を色々試してる話
yudetamago
1
2.3k
Other Decks in Technology
See All in Technology
VLAモデル構築のための AIロボット向け模倣学習キット
kmatsuiugo
0
260
楽しく学ぼう!ネットワーク入門
shotashiratori
1
480
今のWordPress の制作手法ってなにがあんねん?(改) / What’s the Deal with WordPress Development These Days?
tbshiki
0
510
わからなくて良いなら、わからなきゃだめなの?
kotaoue
1
370
GCASアップデート(202601-202603)
techniczna
0
220
脳内メモリ、思ったより揮発性だった
koutorino
0
380
Yahoo!ショッピングのレコメンデーション・システムにおけるML実践の一例
lycorptech_jp
PRO
1
230
1GB RAMのラズピッピで何ができるのか試してみよう / 20260319-rpijam-1gb-rpi-whats-possible
akkiesoft
0
500
決済サービスを支えるElastic Cloud - Elastic Cloudの導入と推進、決済サービスのObservability
suzukij
2
660
The_Evolution_of_Bits_AI_SRE.pdf
nulabinc
PRO
0
240
Go 1.26 Genericsにおける再帰的型制約 / Recursive Type Constraints in Go 1.26 Generics
ryokotmng
0
130
ReactのdangerouslySetInnerHTMLは“dangerously”だから危険 / Security.any #09 卒業したいセキュリティLT
flatt_security
0
320
Featured
See All Featured
Imperfection Machines: The Place of Print at Facebook
scottboms
269
14k
ReactJS: Keep Simple. Everything can be a component!
pedronauck
666
130k
StorybookのUI Testing Handbookを読んだ
zakiyama
31
6.6k
jQuery: Nuts, Bolts and Bling
dougneiner
65
8.4k
Rails Girls Zürich Keynote
gr2m
96
14k
Designing Powerful Visuals for Engaging Learning
tmiket
0
290
AI: The stuff that nobody shows you
jnunemaker
PRO
3
450
Understanding Cognitive Biases in Performance Measurement
bluesmoon
32
2.8k
The Psychology of Web Performance [Beyond Tellerrand 2023]
tammyeverts
49
3.3k
Navigating the moral maze — ethical principles for Al-driven product design
skipperchong
2
290
Stop Working from a Prison Cell
hatefulcrawdad
274
21k
No one is an island. Learnings from fostering a developers community.
thoeni
21
3.6k
Transcript
DApps開発における Solidityのはまりどころ blockchain.tokyo #6 LT 2018-03-16 ゆで卵 1
⾃⼰紹介 名前: ゆで卵 Twitter: @takayukib Github: yudetamago 所属: フリーランス •
主にインフラ(AWS, GCP)・サーバサイド(Rails)の⼈ • ブロックチェーン界隈に来たのはわりと最近 • CryptoCrystalの中の⼈ (余談:先⽇まで渋⾕の緑の会社にいました) 2
DAppsとは?(おさらい) • Decentralized Applications(⾮中央集権型アプリケーション) • ちゃんとした定義としてはこちら。 • https://github.com/DavidJohnstonCEO/DecentralizedApplications • Ethereumで⾔えば…
• コードは全てコントラクトとして公開されている(=管理者が秘密に しているわけではない)。 • アプリケーションのデータもコントラクトを通してブロックチェーン 上に記録されている(=管理者しかアクセス出来ないサーバなどに保 存されているわけではない)。 3
Truffle スマートコントラクトの開発・テスト・デプロイ・フロントエン ドとの統合⽀援フレームワーク • コントラクトの単体テスト • プライベートネットの構築 • プライベートネットへのコントラクトのデプロイ https://github.com/trufflesuite/truffle
4
⾊々前置きしたのですが、 このスライドではほとんど Solidityの話しかしません。 5
Solidity周りのはまりどころ •⼩数を含む計算 •他コントラクト呼び出し時のmsg.sender •変数の初期値 •structのreturn 6
⼩数を含む計算 • Solidityにはまだ⼩数を表す型がないので、ちょっと⼯夫する 必要あり。 • GithubのIssueにはかなり前から挙げられていて、現在実装中 の模様。 • https://github.com/ethereum/solidity/issues/409 •
https://github.com/ethereum/solidity/pull/3389 7
⼩数を含む計算 https://ethereum.stackexchange.com/questions/18870/is-there-a-good-way-to-calculate-a-ratio-in- solidity-since-there-is-no-float-do 例えばパーセントの計算をしたい場合は、以下のような計算をする。 8 percent(101, 450, 3) => 224
// 22.4%
他コントラクト呼び出し時のmsg.sender • コントラクト呼び出し元のアドレスはmsg.senderで取れる。 • ただし、あるコントラクト内から別のコントラクトのメソッ ドを呼び出した場合は、コントラクト⾃体のアドレスになる。 ContractA ContractB Account msg.sender
msg.sender Address: 0xa88a49a814a04.... Address: 0xf222e7a6a6255.... Address: 0xa88a49a814a04c.... ContractB内で元のコントラクトを実⾏した⼈を知るには? 9
他コントラクト呼び出し時のmsg.sender • トランザクションに署名した⼈のアドレスが⼊るであろうと想 定されている tx.origin という変数が⽤意されている。 • tx.originはセキュリティ上の問題があるので、絶対に使っては いけない。 •
参考: https://consensys.github.io/smart-contract-best- practices/recommendations/#avoid-using-txorigin →メソッドを呼び出す時に引数にmsg.senderを渡す 10
他コントラクト呼び出し時のmsg.sender 11
変数の初期値 Solidityにはnullのような概念がないので、定義した変数は0、空 ⽂字、falseといった値で初期化されている。 https://ethereum.stackexchange.com/questions/40559/what-are-the-initial-zero-values-for- different-data-types-in-solidity 12
変数の初期値 keyが存在するかなどのチェックは0(空⽂字、false等)かどう かで⾏う。 (この辺りはGo⾔語のintやstringの感覚に近いかもしれない) 13
structのreturn • Solidityではまだstructを(外部に)returnすることが出来ないの で、要素を並べて返す必要あり。 14 https://ethereum.stackexchange.com/questions/36229/invalid-solidity-type-tuple
今後やるかもしれないこと • ローカルだけではなくて、社内共⽤のプライベートネット • DAppsと、コントラクトだけだと扱うのが難しい情報を配信す るバックエンドサーバーとのE2Eテスト環境 • e.g. 画像配信サーバ、キャッシュサーバ 15
参考⽂献 • Ethereum Smart Contract Best Practices • https://consensys.github.io/smart-contract-best-practices/ •
How does Ethereum work, anyway? • https://medium.com/@preethikasireddy/how-does-ethereum-work- anyway-22d1df506369 16