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
予測不能な実行エージェントを安全にサクッと試せるサンドボックス環境の話
sansantech
PRO
1
140
自分で立ててみるLLMサービス
y_sera15
0
160
会社説明資料
persolserverworks
0
9.7k
生成AIを使って「人が」考える技術 ― AI時代の人機共想と実践ノウハウ|UNITT AC2026
ishiirikie
0
580
組み立てて楽しむ AWS Blocks 入門
kmiya84377
0
230
SREでアラート疲れを 解決しよう!
kairim0
1
220
FOSS4Gを活用した自治体業務DXの試み
470715
0
150
実践! SRE × AI - ABEMA における AIOps -
tetsuya28
7
2.8k
More Freedom on the Same Shared GPU Cluster: A Small Team’s Experience with vCluster
nttcom
0
150
ブラウザとサーバーから考えるAI時代のフロントエンド監視
shogo4131
3
780
AIに攻撃される前に、AIに攻撃させる
tsuchikazu
0
170
Jetson Orin Nanoとk3sとローカルLLMで音声文字起こしシステム作ってみた
y_sera15
0
120
Featured
See All Featured
Utilizing Notion as your number one productivity tool
mfonobong
4
610
Paper Plane
katiecoart
PRO
4
54k
WENDY [Excerpt]
tessaabrams
14
40k
Self-Hosted WebAssembly Runtime for Runtime-Neutral Checkpoint/Restore in Edge–Cloud Continuum
chikuwait
0
870
State of Search Keynote: SEO is Dead Long Live SEO
ryanjones
0
310
How To Stay Up To Date on Web Technology
chriscoyier
790
250k
The agentic SEO stack - context over prompts
schlessera
0
970
The SEO Collaboration Effect
kristinabergwall1
1
590
The Psychology of Web Performance [Beyond Tellerrand 2023]
tammyeverts
49
3.6k
Getting science done with accelerated Python computing platforms
jacobtomlinson
2
530
4 Signs Your Business is Dying
shpigford
187
23k
Agile Actions for Facilitating Distributed Teams - ADO2019
mkilby
0
300
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