跳到主要内容

1 篇博文 含有标签「通信实践」

查看所有标签

Hyperlane 深度解析(3):构建跨链通信实践—乒乓球示例

· 阅读需 10 分钟
国子
Author of @AmphitheatreApp / Contributor of @Alux_Network / PMC of @OpenBuildxyz / Compiler Researcher of http://github.com/hummanta / Rustacean 🦀
hyperlane 中文
Hyperlane 中文团队

本文将通过一个实际示例,演示如何通过Hyperlane 协议发送跨链消息 。

你将学习如何:

  • 部署与 Hyperlane Mailbox 兼容的合约
  • 部署可信中继器 ISM (跨链安全模块)
  • 运行一个简单的中继器
  • 发送跨链消息

示例概览

在此示例中,您将在两个不同的链上部署类似的合约。链 A 上的合约将使用 Hyperlane 协议 向链 B 发送一条消息,链 B 上的合约将处理此消息并回复链 A。

Ping Pong Flow

合约主要功能:

  • sendPing:通过调用Hyperlane的方法 来发起跨链消息IMailbox.dispatch
  • enrollRemoteRouter:在继承的Router合约中,注册来自另一条链的合约。
  • setInterchainSecurityModule:设置合同的 ISM。
  • _handle:处理来自邮箱的传入消息(继承的Router合约handle函数调用的内部函数)。

开发环境准备

  1. 创建并导航到新目录:

    mkdir hyperlane-pingpong && cd hyperlane-pingpong
  2. 初始化 Hardhat 项目并安装依赖项:

    npx hardhat init
  3. 添加@hyperlane-xyz/core为依赖项:

    npm install -D @hyperlane-xyz/core