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
IOST ハンズオン
Search
YutaSugimura
September 01, 2019
Programming
0
250
IOST ハンズオン
YutaSugimura
September 01, 2019
Tweet
Share
More Decks by YutaSugimura
See All by YutaSugimura
Uniswapについて調べてみた
yutasugimura
0
330
Other Decks in Programming
See All in Programming
スクラムガイドのスプリントレトロスペクティブを改めて読みかえしてみた / Re-reading the Sprint Retrospective Section in the Scrum Guide
mackey0225
3
410
サイコロで理解する統計的仮説検定の考え方
tatamiya
4
920
OpenAPIを中心に考えるAPI開発入門 / Introduction to API Development with a Focus on OpenAPI
seike460
PRO
2
170
Semantic search with Django and pgvector
pauloxnet
0
240
ADRを一年運用してみた/adr_after_a_year
hanhan1978
7
2.4k
⼤規模⾔語モデルの拡張(RAG)が 終わったかも知れない件について
nearme_tech
23
15k
SwiftUIで使いやすいToastの作り方 / How to build a Toast system which is easy to use in SwiftUI
lovee
3
140
Java 22 Overview
kishida
1
180
R言語の環境構築と基礎 Tokyo.R 112
bob3bob3
0
260
単体テストを書かない技術 #phpcon_odawara
o0h
PRO
26
8.2k
Site Reliability Engineering for GMO
pyama86
8
1k
Amazon SQSコンシューマー疎結合への旅 - 出張! #DevelopersIO IT技術ブログの中の人が語る勉強会 #3
quiver
0
260
Featured
See All Featured
Designing the Hi-DPI Web
ddemaree
276
33k
Designing with Data
zakiwarfel
96
4.8k
The Straight Up "How To Draw Better" Workshop
denniskardys
227
130k
Code Review Best Practice
trishagee
55
15k
From Idea to $5000 a Month in 5 Months
shpigford
377
45k
Building Adaptive Systems
keathley
31
1.9k
The Pragmatic Product Professional
lauravandoore
25
5.8k
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
501
140k
Build The Right Thing And Hit Your Dates
maggiecrowley
24
2k
Easily Structure & Communicate Ideas using Wireframe
afnizarnur
187
16k
Large-scale JavaScript Application Architecture
addyosmani
504
110k
Fontdeck: Realign not Redesign
paulrobertlloyd
76
4.9k
Transcript
javaScriptでブロックチェーンを学ぶ!名古屋編
IOSTでスマートコントラクトを作成する
iGasͱIRam iGas: トランザクションの時に発⽣する⼿数料 iRam: ブロックチェーンに書き込む際に必要な⼿数料 購⼊することで取得可能。 余った分のiRamは売ったり送ったりすることが可能 IOSTをdepositすることで取得することが可能
テストネットのアカウントを作成する アカウントの作成 https://testnet.explorer.iost.io/applyIOST Generate KeyPair for meをクリックして Account PubKeyを発⾏する
アカウントの作成 完了するとPrivateKeyが表⽰される Private Keyをコピーしてどこかにメモしておく *紛失すると2度と復元することはできません
https://chrome.google.com/webstore/detail/iwallet/kncchdigobghenbbaddojjnnaogfppfj iWalletのインストール chromeに追加する
iWalletのアカウント作成 chromeの右上に アイコンが表⽰されているのでクリックして 起動する passwordの⼊⼒し、 Import Accountをクリック
アカウント追加 先ほど作成した アカウントのPrivateKeyを貼り付け Submitをクリックする
アカウント確認 アカウントが正常にimportできているか確認する これでアカウント作成は完了
IDEについて
IDE https://chainide.com/ 今回はIDEを使ってコントラクトの作成、実⾏を⾏う ChainIDEを使⽤
IDE デフォルトが中国語. 設定から英語に変換可能 もともと3つの異なるコントラクトが⽤意されているので、 簡単に試すことが可能 iwalletのアカウントと連携しているため、簡単にデプロイ、実⾏が可能
IDE β版のため不具合が多いので気をつけることが多い ・ウォレットを起動した状態で、IDEを開く, 開いたらアカウントを変更しない ・更新すると書き込んだコードが消えることがある ・compileし直しても更新されない ・ページ更新するとデプロイしたコードが消える
iRamの準備1 アカウントインポート後,iRamを購⼊していく コントラクトのデプロイ時、 ブロックチェーンにデータを保存するため必要 Purchase Amountに購⼊する⾦額を指定する
iRamの準備2 Submitクリックするとこの画⾯になる SuccessfullyなればOK
今回はIRC20tokenを作成する
トークンについて IOSTではFungible Tokenを作成するための規格が⽤意されている https://developers.iost.io/docs/en/3-smart-contract/Token.html 今回は最低限の機能のみで作成 create, issue, transfer, balanceOf, supply,
totalSupply のみ使⽤ Iost.tokenのインターフェース Iost.tokenという組み込みシステムコントラクトを使⽤
実際にトークンを作成する
New file 左上のプラスマークをクリックしてtokenというファイルを作成 新規ファイルの作成
Contract1 name: トークンのシンボル fullName: トークンの名前 decimal: 少数点以下の桁数 totalSupply: 最⼤発⾏枚数 admin:
このコントラクトのオーナー(先ほど作ったアカウント名) お好きな設定に変更する (a-z, 0-9, _)のみ
Contract2 Class, init関数の作成 1. Tokenというクラスを作成する 初期デプロイ時に実⾏される関数 それ以降は実⾏されない 2. initという関数を作成する
Contract3 トークンの作成 IOST Blockchain API https://developers.iost.io/docs/en/3-smart-contract/IOST-Blockchain-API.html init内部にデプロイ時に 実⾏される関数を書いていく IRC20にあったcreateを使って トークンを作成する
Blockchain.callWithAuth(“token.iost”, “create”, [args]) create(tokenSymbol, issuer, totalSupply, configJson) // string, string, number, json blockchainは元々⽤意されているAPI 詳しくは⬇ ೝূΛ͏Ҿ͖ͰίϯτϥΫτΛݺͼग़͠
Contract4 トークンの発⾏する関数作成 1. ⼆つの内部関数を作成する _amount:扱うトークンの量を計算する関数 _checkToken: トークンのシンボルがあっているか確認する関数
Contract5 _checkToken, _amountを使⽤ トークンの発⾏する関数作成 2. blockchain.callWithAuthを使ってissueを実⾏ issue(tokenSymbol, to, amountStr) //string,
string, string https://developers.iost.io/docs/en/3-smart-contract/IOST-Blockchain-API.html IOST Blockchain API: https://developers.iost.io/docs/en/3-smart-contract/Token.html IRC20:
Contract6 _checkToken, _amount 送⾦を⾏う為の関数作成 blockchain.callWithAuthを使ってtransferを実⾏ transfer(tokenSymbol, from, to, amountStr, memo)
//string, string, string, string, string https://developers.iost.io/docs/en/3-smart-contract/IOST-Blockchain-API.html IOST Blockchain API: https://developers.iost.io/docs/en/3-smart-contract/Token.html IRC20:
Contract7 _call関数を作成
Contract8 _call, _checkTokenを使⽤ 残⾼確認する関数を作成 IRC20 balanceOf balanceOf(tokenSymbol, from) //string, string
https://developers.iost.io/docs/en/3-smart-contract/IOST-Blockchain-API.html IOST Blockchain API: https://developers.iost.io/docs/en/3-smart-contract/Token.html IRC20:
Contract9 _call, _checkTokenを使⽤ 現在の発⾏量を確認する関数を作成 IRC20 supply supply(tokenSymbol) //string https://developers.iost.io/docs/en/3-smart-contract/IOST-Blockchain-API.html IOST
Blockchain API: https://developers.iost.io/docs/en/3-smart-contract/Token.html IRC20:
Contract10 https://developers.iost.io/docs/en/3-smart-contract/IOST-Blockchain-API.html IOST Blockchain API: _call, _checkTokenを使⽤ 最⼤発⾏数を確認する関数の作成 IRC20 totalSupply
totalSupply(tokenSymbol) //string https://developers.iost.io/docs/en/3-smart-contract/Token.html IRC20:
Contract11 Tokenをエクスポート これでコントラクト完成
Deploy1 token.jsをコンパイルしてABIを作成する コンパイルが成功するとfunctionが表⽰される
Deploy2 token.jsとtoken.js.abiを選択して デプロイする Gas RatioとGas Limitはこのままで確定をクリック
Deploy3 デプロイが成功すると 失敗する場合はnameが被っている可能性がほとんど 今回の設定
Deploy4 成功するとフォームが出現する 今回はこれを使って実際にコントラクトを動かしていく
function1 現在の残⾼を確認する balanceOfを選択 実⾏をクリック 引数1: トークンのシンボル(name) 引数2: 確認するアカウント 現在0であることを確認
function2 トークンを発⾏する Issueを選択 実⾏をクリック 引数1: トークンのシンボル(name) 引数2: 付与するアカウント succeededならOK 引数3:
発⾏枚数
function3 再度残⾼確認 発⾏枚数が追加されていればOK
iwallet1 Add Tokenをクリック トークン名を⼊⼒してAddをクリック iwalletから残⾼確認や送⾦可能 iwalletにトークンをインポート
Happy Hacking!!