概要

ローカルでL1 Blockchainを作成して、作成したL1 Blockchainの情報を確認していきます。 注意が必要なのが、あくまでこの章では「L1 Blockchainの雛形」を作成をするだけです。 実際にローカルでL1 Blockchainとして稼働させるためには、デプロイをする必要があります。 この章では「L1 Blockchainの設計図」を作成して、デプロイのステップでその設計図をもとに実際にL1 Blockchainを立ち上げるようなイメージです。

L1作成

まずは、以下のコマンドを実行してしてください。 「chain name」には作成するL1 Blockchainの名前を入れてください。

bash
avalanche blockchain create <chain name>
  • 例
bash
avalanche blockchain create chain1

そうするといくつか質問されるので順番に選択していってください。

Virtual Machineの選択

Which Virtual Machine would you like to use?

Virtual Machineはどうするか聞かれているので、「Subnet-EVM」を選択してください。 「Subnet-EVM」はEVM互換のVMです。 EVMとは、Ethereum Virtual Machineの略称であり、Solidityなどで記述されたスマートコントラクトを実行することができます。 EVM互換とは、このEthereum Virtual Machineと互換性があるということであり、EVM同様スマートコントラクトを実行することができます。

bash
? Which Virtual Machine would you like to use?: 
  ▸ Subnet-EVM
    Custom VM
    Explain the difference

バリデータマネージャーの選択

Which validator management type would you like to use in your blockchain?

どのバリデータマネージャーにするか聞かれているので、「Proof Of Authority」を選択してください。 「Proof Of Authority」は、特定の選ばれたバリデータがブロックの生成と検証を行います。 そのため、ローカルで作成したL1 Blockchainのブロック生成には最適です。

bash
? Which validator management type would you like to use in your blockchain?: 
  ▸ Proof Of Authority
    Proof Of Stake
    Explain the difference

ValidatorManagerコントラクトの操作権限

Which address do you want to enable as controller of ValidatorManager contract?

ValidatorManagerコントラクトの操作権限を持つアドレスをどれにするか聞かれています。 ValidatorManagerコントラクトは、作成したL1 Blockchainに参加するバリデータ(検証者)を追加・削除・管理する役割を持ちます。 Avalanche CLI側でアドレスを生成、もしくは既に生成されている場合それを再利用することができるので、「Get address from an existing stored key (created from avalanche key create or avalanche key import)」を選択してください。

bash
? Which address do you want to enable as controller of ValidatorManager contract?: 
  ▸ Get address from an existing stored key (created from avalanche key create or avalanche key import)
    Custom

鍵の選択

Which stored key should be used enable as controller of ValidatorManager contract?

次に以下のような質問をされます。 これは、既に保存済みの鍵が存在するため、どの鍵を使用するか聞かれています。

bash
? Which stored key should be used enable as controller of ValidatorManager contract?: 
  ▸ ewoq
    cli-awm-relayer
    cli-teleporter-deployer

選択肢について簡単に説明します。

  • ewoq AvalancheGo に最初から定義されている「デフォルトキー」です。 「EWOQ」は 「Eminence Wallet Of Quorum」の略で、テスト用に使える便利な鍵ですが、秘密鍵が公開されているため誰でもアクセス可能です。 そのため「Do not use EWOQ key in a testnet or production setup」と警告されており、本番やテストネットでは使用してはいけません。 あくまで ローカル開発や学習用の簡易デモのための鍵です。
  • cli-awm-relayer Avalanche Warp Messaging(AWM)のリレーヤー用に作られた鍵です。 CLI内で「warp messaging をデプロイ/管理するための専用アカウント」として保存されています。 バリデータ管理用のコントローラーに指定することも可能ですが、本来はAWM関連の処理に用いる想定です。
  • cli-teleporter-deployer Avalanche Teleporter(クロスチェーン通信機構)のデプロイ用に作成された鍵です。 Teleporterコントラクトのデプロイや管理に使う想定のアカウントです。 バリデータ管理とは目的が異なりますが、必要であればコントローラーに指定することも可能です。

今回は「ewoq」を選択してください。

もし自身で管理するEOAアドレスを使用したい場合は、「Custom」を選択してください。 そうすると以下のように管理者アドレスの入力が求められうので入力してください。

bash
Enter address (C-Chain address):

ブロックチェーンの設定

Do you want to use default values for the Blockchain configuration?

ブロックチェーンの設定(バリデータ数、ネットワークパラメータ、セキュリティ要件など)に、用意されたデフォルトの設定を使用するか聞かれているので、「I want to use defaults for a test environment」を選択してください。

bash
? Do you want to use default values for the Blockchain configuration?: 
  ▸ I want to use defaults for a test environment
    I want to use defaults for a production environment
    I don't want to use default values
    Explain the difference

各選択肢について簡単に説明します。

  • I want to use defaults for a test environment テスト用の簡易設定を使う設定です。 セキュリティは低く(例えば少数のバリデータでも動作可)で、すぐにチェーンを立ち上げて挙動確認や開発を始められます。 主にローカル環境や短期の実験用に使用されます。
  • I want to use defaults for a production environment 本番運用に適した標準設定です。 セキュリティは高く(十分なバリデータ数、安定的なパラメータ)、トークン経済設計やステーキングを前提にしていることが多いです。 実際にSubnetや独自L1を公開する場合はこれを選択してください。
  • I don't want to use default values デフォルトの設定は使わず、自分で全ての設定を細かく指定する方法です。 バリデータの初期セットやガス料金、チェーンID、セキュリティパラメータなどを自由に設定することができます。 独自にL1 Blockchainをカスタマイズしたいときに役立ちます。
  • Explain the difference 上記の3つの違いについて説明を表示してくれます。

「Explain the difference」では以下のような説明が出力されます。

bash
Blockchain configuration default values:
- Use latest Subnet-EVM release
- Allocate 1 million tokens to:
   - a newly created key (production)
   - ewoq - 0x8db97C7cEcE249c2b98bDC0226Cc4C2A57BF52FC (test)
- Supply of the native token will be hard-capped
- Set gas fee config as low throughput (12 mil gas per block)
- Use constant gas prices
- Disable further adjustments in transaction fee configuration
- Transaction fees are burned
- Enable interoperation with other blockchains
- Allow any user to deploy smart contracts, send transactions, and interact with your blockchain.

チェーンID

Chain ID

作成するL1 BlockchainのチェーンIDの入力が求められます。 「1」や「111」、「1234」など好きな数字を入れてください。 既に他にL1 Blockchainを作成している場合は、そのチェーンIDは使用できないので他のチェーンIDを使用してください。

bash
✗ Chain ID:

トークンシンボル

Token Symbol

作成するL1 Blockchainのネイティブトークンのトークンシンボル名の入力が求められています。 「TEST」や「L1TK」、「TK01」など好きなシンボル名を入れてください。

bash
✗ Token Symbol:

ここまで選択できたら、以下のように「Successfully created blockchain configuration」と出力されるので、これでローカルでL1 Blockchainの設計図の作成ができました。

bash
prefunding address 0x8db97C7cEcE249c2b98bDC0226Cc4C2A57BF52FC with balance 1000000000000000000000000
File /Users/<username>/.avalanche-cli/subnets/chain1/chain.json successfully written
✓ Successfully created blockchain configuration
Run 'avalanche blockchain describe' to view all created addresses and what their roles are

出力されている内容を確認します。

bash
prefunding address 0x8db97C7cEcE249c2b98bDC0226Cc4C2A57BF52FC with balance 1000000000000000000000000

これは、0x8db97C7cEcE249c2b98bDC0226Cc4C2A57BF52FCというアドレスに、ネイティブトークンを1000000000000000000000000発行したことを示しています。 ネイティブトークンはガス代として使用できるため、このトークンを他のアドレスなどに送付して使用します。

bash
File /Users/<username>/.avalanche-cli/subnets/chain1/chain.json successfully written

作成したL1 Blockchainの設定ファイルが/Users/<username>/.avalanche-cli/subnets/chain1/chain.jsonに保存されていることを示しています。

実際にchain.jsonを見てみると以下のようになっています。

bash
{
  "log-level": "debug",
  "database-type": "leveldb",
  "eth-apis": [
    "eth",
    "eth-filter",
    "net",
    "admin",
    "web3",
    "internal-eth",
    "internal-blockchain",
    "internal-transaction",
    "internal-debug",
    "internal-account",
    "internal-personal",
    "debug",
    "debug-tracer",
    "debug-file-tracer",
    "debug-handler"
  ]
}

createのオプション

bash
avalanche blockchain create [subcommand] [flags]

新しいL1 Blockchainのgenesisファイル(初期設定)を生成するコマンド。 チェーン名やVMの種類(Subnet-EVM / カスタム)、トークン仕様、検証ルール(PoA/PoS)などを順に設定できます。 Subnet-EVMだけでなく、独自のVMを指定することも可能です。

bash
--custom                            use a custom VM template
--custom-vm-branch string           custom vm branch or commit
--custom-vm-build-script string     custom vm build-script
--custom-vm-path string             file path of custom vm to use
--custom-vm-repo-url string         custom vm repository url
--debug                             enable blockchain debugging (default true)
--evm                               use the Subnet-EVM as the base template
--evm-chain-id uint                 chain ID to use with Subnet-EVM
--evm-defaults                      deprecation notice: use '--production-defaults'
--evm-token string                  token symbol to use with Subnet-EVM
--external-gas-token                use a gas token from another blockchain
-f, --force                         overwrite the existing configuration if one exists
--from-github-repo                  generate custom VM binary from github repository
--genesis string                    file path of genesis to use
-h, --help                          help for create
--icm                               interoperate with other blockchains using ICM
--icm-registry-at-genesis           setup ICM registry smart contract on genesis [experimental]
--latest                            use latest Subnet-EVM released version, takes precedence over --vm-version
--pre-release                       use latest Subnet-EVM pre-released version, takes precedence over --vm-version
--production-defaults               use default production settings for your blockchain
--proof-of-authority                use proof of authority(PoA) for validator management
--proof-of-stake                    use proof of stake(PoS) for validator management
--proxy-contract-owner string       EVM address that controls ProxyAdmin for TransparentProxy of ValidatorManager contract
--reward-basis-points uint          (PoS only) reward basis points for PoS Reward Calculator (default 100)
--sovereign                         set to false if creating non-sovereign blockchain (default true)
--teleporter                        interoperate with other blockchains using ICM
--test-defaults                     use default test settings for your blockchain
--validator-manager-owner string    EVM address that controls Validator Manager Owner
--vm string                         file path of custom vm to use. alias to custom-vm-path
--vm-version string                 version of Subnet-EVM template to use
--warp                              generate a vm with warp support (needed for ICM) (default true)
--config string                     config file (default is $HOME/.avalanche-cli/config.json)
--log-level string                  log level for the application (default "ERROR")
--skip-update-check                 skip check for new versions
  • --custom カスタムVMテンプレートを利用します。
  • --custom-vm-branch <string> カスタムVMをGitHub等から取得する場合のブランチ名またはコミットIDを指定します。
  • --custom-vm-build-script <string> カスタムVMをビルドするスクリプトのパスを指定します。
  • --custom-vm-path <string> 利用するカスタムVMバイナリのファイルパス。
  • --custom-vm-repo-url <string> カスタムVMを取得するリポジトリのURL。
  • --debug ブロックチェーンのデバッグモードを有効化します(デフォルト: true)。
  • --evm Subnet-EVMをベーステンプレートとして利用します。
  • --evm-chain-id <uint> Subnet-EVMを使う場合の ChainID を指定します。
  • --evm-defaults 非推奨。 Subnet-EVM 用のデフォルト設定を使って genesis を生成します。 代わりに --production-defaults の使用が推奨されています。
  • --evm-token <string> Subnet-EVMで利用するトークンのシンボルを指定します。
  • --external-gas-token 他のブロックチェーンのトークンをガス代として利用できるようにします。
  • -f, --force 既に同じL1 Blockchain名の設定が存在している場合でも上書きします。
  • --from-github-repo GitHubリポジトリからカスタムVMバイナリを生成します。
  • --genesis <string> 任意のgenesisファイルを読み込んで利用します。
  • --icm ICM(Interchain Messaging, クロスチェーン通信)を有効化します。
  • --icm-registry-at-genesis ICM Registryスマートコントラクトをgenesisに配置します(実験的)。
  • --latest Subnet-EVMの最新版を利用します。 --vm-version より優先されます。
  • --pre-release Subnet-EVMの最新プレリリース版を利用します。 --vm-version より優先されます。
  • --production-defaults 本番環境用の推奨デフォルト設定を利用します。
  • --proof-of-authority Proof of Authority (PoA)を検証ルールとして選択します。
  • --proof-of-stake Proof of Stake (PoS)を検証ルールとして選択します。
  • --proxy-contract-owner <string> TransparentProxy(ValidatorManager コントラクトの ProxyAdmin)を管理するEVM アドレスを指定します。
  • --reward-basis-points <uint> (PoS専用)報酬計算のベースポイントを設定します。 デフォルトは 100。
  • --sovereign サブネットをソブリン(独立)チェーンとして扱うかを指定します。 デフォルトは true。
  • --teleporter Teleporterを利用してICM通信を有効化します。
  • --test-defaults テスト環境向けの推奨デフォルト設定を利用します。
  • --validator-manager-owner <string> ValidatorManagerコントラクトを管理するEVMアドレスを指定します。
  • --vm <string> カスタムVMを利用する場合のファイルパス。 --custom-vm-path の別名。
  • --vm-version <string> Subnet-EVMテンプレートのバージョンを指定します。
  • --warp Warpメッセージングを有効化します(ICMに必要)。 デフォルトは true。
  • --skip-update-check Avalanche CLIのアップデートチェックをスキップします。