Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
Dapps開発におけるSoliidityのはまりどころ
Search
yudetamago
March 16, 2018
Technology
2.4k
3
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Dapps開発におけるSoliidityのはまりどころ
yudetamago
March 16, 2018
More Decks by yudetamago
See All by yudetamago
ブロックチェーンとIndexer
yudetamago
0
990
Unityでブロックチェーンアプリを作る
yudetamago
0
1.9k
DApps開発特有の_ハマりポイントご紹介.pdf
yudetamago
1
1.5k
スマートコントラクトの監査について
yudetamago
2
650
DApps開発事例 ~CryptoCrystal概要編~
yudetamago
3
350
Gasを誰が払うのか問題について
yudetamago
5
4.7k
Solidityの複数コントラク ト連携を色々試してる話
yudetamago
1
2.4k
Other Decks in Technology
See All in Technology
LLM機能を自作して分かるSnowflake Cortex AIの強み
nayuts
0
350
SDDの運用にめげずに向き合った話
sansantech
PRO
1
140
生成AIと進める探索的データ分析(2026.10.03 第122回Tokyo.R勉強会)
tatamiya
2
1.5k
ファミコンでPHPを動かす / PHP on the Famicom side b
tomzoh
0
140
AI駆動開発の時代になったのでトヨタ生産方式から見直す
terurou
7
5.7k
OSC2026on_the-world-is-waiting-for-your-voice.pdf
naruoga
0
370
実践! SRE × AI - ABEMA における AIOps -
tetsuya28
7
2.8k
会社説明資料
persolserverworks
0
9.7k
メルペイ 会計システム概要と歴史
mewuto
0
200
AI 時代の Azure エンジニアリング ~ 私たちは何を磨き、何を任せるのか ~
chack411
1
580
Jetson Orin Nanoとk3sとローカルLLMで音声文字起こしシステム作ってみた
y_sera15
0
120
全人類(ほぼ)AWS Organizations の上でAWSを利用している、その世界を知る話
htan
1
130
Featured
See All Featured
How to optimise 3,500 product descriptions for ecommerce in one day using ChatGPT
katarinadahlin
PRO
3
3.9k
Leading Effective Engineering Teams in the AI Era
addyosmani
9
2.7k
Design of three-dimensional binary manipulators for pick-and-place task avoiding obstacles (IECON2024)
konakalab
0
610
Practical Orchestrator
shlominoach
192
12k
エンジニアに許された特別な時間の終わり
watany
109
250k
Are puppies a ranking factor?
jonoalderson
2
4k
Neural Spatial Audio Processing for Sound Field Analysis and Control
skoyamalab
0
550
How to train your dragon (web standard)
notwaldorf
96
6.9k
Conquering PDFs: document understanding beyond plain text
inesmontani
PRO
4
3.2k
JAMstack: Web Apps at Ludicrous Speed - All Things Open 2022
reverentgeek
1
630
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
28
3.7k
Building Adaptive Systems
keathley
44
3.2k
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