概要
この章では、ICM(Interchain Messaging:ブロックチェーン間メッセージング)のMessenger/Registryコントラクトを操作していきます。 Messengerコントラクトは他のL1 Blockchainとメッセージをやり取りし、Registryコントラクトは他のL1 BlockchainやMessengerコントラクトの管理を行います。
avalanche icm [subcommand] [flags]ICM の deploy
指定したL1 BlockchainにICM MessengerコントラクトとICM Registryコントラクトをデプロイします。 ローカルネットワークの場合は、あわせてC-Chainにもデプロイされます。 以下のコマンドを実行してください。
avalanche icm deployデプロイを行うネットワークの選択を求められるので、「Local Network」を選択してください。
? On what Network do you want to deploy the ICM Messenger?:
▸ Local Network
Devnet
Fuji Testnet
Mainnetデプロイを行うL1 Blockchainの選択を求められるので、「Blockchain chain1」を選択してください。
? Which Blockchain would you like to deploy ICM to?:
C-Chain
▸ Blockchain chain1
Customデプロイを行う時に使用するアカウントの指定を求められるので、「Use the private key of the Genesis Allocated address...」か「Get private key from an existing stored key...」のどちらかを選択してください。
? Which private key do you want to use to deploy ICM?:
▸ Use the private key of the Genesis Allocated address 0x8db97C7cEcE249c2b98bDC0226Cc4C2A57BF52FC
Get private key from an existing stored key (created from avalanche key create or avalanche key import)
CustomL1 Blockchain作成時に既にデプロイされているため、以下のように表示されます。
ICM Messenger has already been deployed to chain1
ICM Messenger has already been deployed to c-chain以下のようにいくつかオプションがあるので1つずつ簡単に説明します。
--blockchain string deploy ICM into the given CLI blockchain
--blockchain-id string deploy ICM into the given blockchain ID/Alias
--c-chain deploy ICM into C-Chain
--cchain-key string key to be used to pay fees to deploy ICM to C-Chain
--cluster string operate on the given cluster
--deploy-messenger deploy ICM Messenger (default true)
--deploy-registry deploy ICM Registry (default true)
--devnet operate on a devnet network
--endpoint string use the given endpoint for network operations
--force-registry-deploy deploy ICM Registry even if Messenger has already been deployed
-f, --fuji testnet operate on fuji (alias to testnet
--genesis-key use genesis allocated key to fund ICM deploy
--include-cchain deploy ICM also to C-Chain
--key string CLI stored key to use to fund ICM deploy
-l, --local operate on a local network
-m, --mainnet operate on mainnet
--messenger-contract-address-path string path to a messenger contract address file
--messenger-deployer-address-path string path to a messenger deployer address file
--messenger-deployer-tx-path string path to a messenger deployer tx file
--private-key string private key to use to fund ICM deploy
--registry-bytecode-path string path to a registry bytecode file
--rpc-url string use the given RPC URL to connect to the subnet
-t, --testnet fuji operate on testnet (alias to fuji)
--version string version to deploy (default "latest")--blockchain stringAvalanche CLIで管理しているL1 Blockchainの名前を指定して、そのL1 BlockchainにICMコントラクトをデプロイします(例:chain1)。--blockchain-id stringブロックチェーンID/エイリアス(CB58 など)を指定してICMコントラクトをデプロイします。--c-chainC-ChainにのみICMコントラクトをデプロイします。 ローカルでL1 Blockchainと並行デプロイしたい場合は--include-cchainを使います。--cchain-key stringC-Chain側デプロイの手数料支払いに使うキー名(Avalanche CLI保管)を指定します。--cluster string操作対象のクラスタ名を指定します(Avalanche CLIで命名したノード集合)。--deploy-messenger(デフォルト: true) ICM Messengerコントラクトをデプロイします。 不要なら--deploy-messenger=falseと指定します。--deploy-registry(デフォルト: true) ICM Registryコントラクトをデプロイします。 不要なら--deploy-registry=falseと指定します。--devnetDevnet上で処理を実行します。--endpoint stringネットワーク操作に使うエンドポイント(Avalanche CLI制御用の接続先URL)を指定します。--force-registry-deployすでにMessengerコントラクトがデプロイ済みでも、Registryコントラクトを強制デプロイします。 再デプロイや再初期化が必要なときに使用します。-f, --fujiFuji上で処理を実行します。--testnetのエイリアスです。--genesis-keyL1 Blockchain作成時に生成された鍵を使用してICMコントラクトのデプロイを行います。--include-cchain指定したL1 Blockchainに加えてC-ChainにもICMコントラクトをデプロイします。--key stringAvalanche CLIに保存済みのキー名を、ICMコントラクトのデプロイに使用します。-l, --localローカルネットワーク上で処理を実行します。-m, --mainnetMainnet上で処理を実行します。--messenger-contract-address-path stringMessengerコントラクトアドレスを書き出す/読み込むファイルパスを指定します。--messenger-deployer-address-path stringMessengerコントラクトのデプロイヤーアドレス(デプロイ元EOAなど)を記録するファイルパスを指定します。--messenger-deployer-tx-path stringMessengerコントラクトデプロイ時のトランザクション情報を記録するファイルパスを指定します。--private-key string秘密鍵を指定し、ICMコントラクトのデプロイを行います。--registry-bytecode-path stringRegistryコントラクトのバイトコードを外部ファイルから読み込む場合のパスを指定します。--rpc-url string対象サブネット(L1 Blockchain)に接続するためのRPC URLを直接指定します(例:http://127.0.0.1:8545)。-t, --testnetTestnet上で処理を実行します。--fujiのエイリアスです。--version string(デフォルト:"latest") デプロイするICMコントラクトのバージョンを指定します。
チェーン間でメッセージの送付
2つのブロックチェーン間でICMメッセージを送信して受信完了まで待機します。 以下のコマンドを実行してください。
avalanche icm sendMsg <送付元chain name> <送信先chain name> "<Message>" --local- 例
avalanche icm sendMsg chain1 chain2 "Hello" --localトランザクションのガス代を負担するアドレスの選択を求められるので、「Use the private key of the Genesis Allocated address...」か「Get private key from an existing stored key...」を選択してください。
? Which private key do you want to use to pay for fees at source blockchain?:
Use the private key of the Genesis Allocated address 0x8db97C7cEcE249c2b98bDC0226Cc4C2A57BF52FC
▸ Get private key from an existing stored key (created from avalanche key create or avalanche key import)
Custom「Get private key from an existing stored key...」を選択した場合は、「ewoq」を選択してください。
? Which stored key should be used pay for fees at source blockchain?:
sample-key
▸ ewoq
cli-awm-relayer
cli-teleporter-deployer以下のように表示されていれば実行成功です。
Delivering message "Hello" from source blockchain "chain1" (w7ThnGXmC4ZtUDZE7Wv5bDFzsgnZa4c48Y2EBGJNdUs88Bheo)
Waiting for message to be delivered to destination blockchain "chain2" (SMXGPr8rzQJiFDbiuKbARMNmYBpw6bLDwYPk55s4Z9PpqXWQG)
Message successfully delivered!以下のようにいくつかオプションがあるので1つずつ簡単に説明します。
--cluster string operate on the given cluster
--dest-rpc string use the given destination blockchain rpc endpoint
--destination-address string deliver the message to the given contract destination address
--devnet operate on a devnet network
--endpoint string use the given endpoint for network operations
-f, --fuji testnet operate on fuji (alias to testnet
--genesis-key use genesis allocated key as message originator and to pay source blockchain fees
--hex-encoded given message is hex encoded
--key string CLI stored key to use as message originator and to pay source blockchain fees
-l, --local operate on a local network
-m, --mainnet operate on mainnet
--private-key string private key to use as message originator and to pay source blockchain fees
--source-rpc string use the given source blockchain rpc endpoint
-t, --testnet fuji operate on testnet (alias to fuji)--cluster string対象のクラスタ名(Avalanche CLIで命名したノード群)を指定します。--dest-rpc string宛先ブロックチェーンのRPCエンドポイント(ノードのHTTP/HTTPS URL)を指定します。--destination-address string宛先コントラクトアドレスを指定します。メッセージはこのアドレスに送付されます。--devnetDevnetを対象に処理を実行します。--endpoint stringAvalanche CLIのネットワーク操作に使う制御用エンドポイントURLを指定します。-f, --fujiFujiを対象に処理を実行します(--testnetのエイリアス)。--genesis-keyメッセージ送信者(originator)と送信元L1 Blockchainの手数料支払いに、ローカルに保存されているL1 Blockchain作成時に生成されている鍵を使用します。--hex-encoded渡すメッセージが16進(hex)エンコードされた文字列であることを示します。--key stringAvalanche CLIに保存済みの鍵名を、メッセージ送信者(originator)と送信元L1 Blockchainの手数料支払いに使用します。-l, --localローカルネットワークを対象に処理を実行します。-m, --mainnetMainnetを対象に処理を実行します。--private-key string秘密鍵を直接指定し、メッセージ送信者(originator)と送信元L1 Blockchainの手数料支払いに使用します。--source-rpc string送信元L1 BlockchainのRPCエンドポイント(ノードURL)を指定します。-t, --testnetTestnetを対象に処理を実行します(--fujiのエイリアス)。