LoginSignup
9
5

More than 5 years have passed since last update.

Truffleチートシート

Last updated at Posted at 2018-06-28

Note:記事は執筆時点(2018年6月)の内容です。技術の進歩が早く、今後陳腐化する可能性もあるのでご留意ください。

【Shell】

雛形作成

$ truffle init

// 実行結果(例)
Downloading...
Unpacking...
Setting up...
Unbox successful. Sweet!

Commands:

  Compile:        truffle compile
  Migrate:        truffle migrate
  Test contracts: truffle test

コンパイル

$ truffle compile

ローカルでの実行

$ truffle develop

// 実行結果(例)
Truffle Develop started at http://127.0.0.1:9545/

Accounts:
(0) 0x627306090abab3a6e1400e9345bc60c78a8bef57
(1) 0xf17f52151ebef6c7334fad080c5704d77216b732
(2) 0xc5fdf4076b8f3a5357c5e395ab970b5b54098fef
(3) 0x821aea9a577a9b44299b9c15c88cf3087f3b5544
(4) 0x0d1d4e623d10f9fba5db95830f7d3839406c6af2
(5) 0x2932b7a2355d6fecc4b5c0b6bd44cc31df247a2e
(6) 0x2191ef87e392377ec08e7c08eb105ef5448eced5
(7) 0x0f4f2ac550a1b4e2280d04c21cea7ebd822934b5
(8) 0x6330a553fc93768f612722bb8c2ec78ac90b3bbc
(9) 0x5aeda56215b167893e80b4fe645ba6d5bab767de

Private Keys:
(0) c87...
(1) ae6...
(2) 0db...
(3) c88...
(4) 388...
(5) 659...
(6) 82d...
(7) aa3...
(8) 0f6...
(9) 8d5...

Mnemonic: candy ...

マイグレーション(デプロイ):ローカル環境

# truffle develop実行後、truffle consoleにて以下コマンド実行
truffle(develop)> migrate

// 実行結果(例)
Using network 'develop'.

Running migration: 1_initial_migration.js
  Replacing Migrations...
  ... 0x63fb52c38e0c0a6ffb49344b27f96222178399bae48b7bffe5cb1c4b9d808bd9
  Migrations: 0x8cdaf0cd259887258bc13a92c0a6da92698644c0
Saving successful migration to network...
  ... 0xd7bc86d31bee32fa3988f1c1eabce403a1b5d570340a3a9cdba53a472ee8c956
Saving artifacts...
Running migration: 2_deploy_tooricoin.js
  Deploying TooriCoin...
  ... 0x7b30330b3c0f4f3c9ed0b90761be5ae7da706ea7ddb054bcf27eb854adf31d57
  TooriCoin: 0x345ca3e014aaf5dca488057592ee47305d9b3e10
Saving successful migration to network...
  ... 0xf36163615f41ef7ed8f4a8f192149a0bf633fe1a2398ce001bf44c43dc7bdda0
Saving artifacts...

マイグレーション(デプロイ):リモート環境

$ truffle migrate --network <network-name>

// 実行結果(例)
Using network 'ropsten'.

Running migration: 1_initial_migration.js
  Replacing Migrations...
  ... 0x31d669c4a9fe19c46d3c840a374610abdbca562b261e35a602ec025f1be44a5b
  Migrations: 0x88ad97728b2e9116917b1c8a228c7edbc0480019
Saving successful migration to network...
  ... 0xb2a224957bf7b832c8e5738d3788ee897690be3ac9b2bb4dd34002214991be5c
Saving artifacts...
Running migration: 2_deploy_tooricoin.js
  Deploying TooriCoin...
  ... 0xd3d66c21e22dee0db01a910b3d81115af4e4e544744d7f1f45693f139f2e1be5
  TooriCoin: 0x7b6e3ca032f7140ddd85e1639a6b34de51e8fc3a
Saving successful migration to network...
  ... 0x07004adf1bfaca4bae8e4afa2cd080a47546f556a5486e9ee5809cd4b59c1c91
Saving artifacts...

Note:リモートの場合、事前にtruffle.jsに接続先のProviderを設定しておく必要がある。に対応するProviderを定義する。

Note:デプロイをすべての手順でやり直したい場合は、"--reset"オプションを追加する
$ truffle migrate --reset

コンソールの実行

// ローカル環境
$ truffle develop

// リモート環境
$ truffle console --network <network-name>

Note:リモートの場合、事前にtruffle.jsに接続先のProviderを設定しておく必要がある。に対応するProviderを定義する。

【Truffle Console】

インスタンス化

truffle(develop)> contract = MyToken.at("<your-token-address>")

// 実行結果(例)
[{...}] contractが表示される長いので省略

Note: <your-token-address>には、migrateコマンドを実行した際に表示されたものをセットする。
例)TooriCoin: 0x345ca3e014aaf5dca488057592ee47305d9b3e10

トークンの名称確認

truffle(develop)> contract.name()

// 実行結果(例)
'MyToken'

トークンの総発行量確認

truffle(develop)> contract.totalSupply()

// 実行結果(例)
BigNumber { s: 1, e: 22, c: [ 500000000 ] }

Note: BigNumber形式で返される

アドレス一覧

truffle(develop)> web3.eth.accounts

// 実行結果(例)
[ '0x627306090abab3a6e1400e9345bc60c78a8bef57',
  '0xf17f52151ebef6c7334fad080c5704d77216b732',
  '0xc5fdf4076b8f3a5357c5e395ab970b5b54098fef',
  '0x821aea9a577a9b44299b9c15c88cf3087f3b5544',
  '0x0d1d4e623d10f9fba5db95830f7d3839406c6af2',
  '0x2932b7a2355d6fecc4b5c0b6bd44cc31df247a2e',
  '0x2191ef87e392377ec08e7c08eb105ef5448eced5',
  '0x0f4f2ac550a1b4e2280d04c21cea7ebd822934b5',
  '0x6330a553fc93768f612722bb8c2ec78ac90b3bbc',
  '0x5aeda56215b167893e80b4fe645ba6d5bab767de' ]

残高確認

truffle(develop)> contract.balanceOf(web3.eth.accounts[0])

// 実行結果(例)
BigNumber { s: 1, e: 22, c: [ 500000000 ] }

Note: web3.eth.accounts[i]のiにindexを指定

9
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
9
5