blockchain:truffleを使ったスマートコントラクト開発
文書の過去の版を表示しています。
目次
Truffleを使ったスマートコントラクト開発
Truffleとは
必要なソフトウエア
Truffle は npm を使ってインストールしますので、事前に npm をインストールしてください。
インストール
> npm install -g truffle
初期化
> mkdir my_project > cd my_project > truffle init Starting init... ================ > Copying project files to C:\Users\shinobu\NoNameSeminer\ethereum\my_project Init successful, sweet! Try our scaffold commands to get started: $ truffle create contract YourContractName # scaffold a contract $ truffle create test YourTestName # scaffold a test http://trufflesuite.com/docs
生成されたファイルを確認してみます。
> tree /f ボリューム シリアル番号は EEAF-D230 です C:. │ truffle-config.js │ ├─contracts │ Migrations.sol │ ├─migrations │ 1_initial_migration.js │ └─test .gitkeep
TODO: 各ファイルとディレクトリの説明。
- truffle-config.js
- contracts
- migrations
- test
設定
truffle-config.js を開いて、コメントを削除し以下のように変更してください。
- *Ganache に接続する場合の設定です。
- *port番号は 8545 から 7545 に変更しています。
networks: { // Useful for testing. The `development` name is special - truffle uses it by default // if it's defined here and no other network is specified at the command line. // You should run a client (like ganache-cli, geth or parity) in a separate terminal // tab if you use this network and you must also set the `host`, `port` and `network_id` // options below to some value. // development: { host: "127.0.0.1", // Localhost (default: none) port: 7545, // Standard Ethereum port (default: none) network_id: "*", // Any network (default: none) },
Ganacheとの連携
Ganache を起動し「NEW WORKSPACE」をクリックします。
「ADD PROJECT」をクリックし、先ほど作成した「truffle-config.js」を選択します。
これで Ganache と Truffle の連携設定は完了です。「SAVE WORKSPACE」をクリックしてください。
Truffle コンソール
> truffle console truffle(development)>
スマートコントラクト
生成
truffle(development)> truffle create contract Counter truffle(development)>
実装
コンパイル
マイグレーション
実行
blockchain/truffleを使ったスマートコントラクト開発.1651034745.txt.gz · 最終更新: 2022/04/27 04:45 by dot