Unlocking Chain Abstraction on Berachain

As the Web3 industry continues to evolve, the need for seamless interaction between blockchains is more critical than ever. This is where Chain Abstraction comes in. Chain Abstraction aims to simplify the complexity of interacting with multiple blockchains, allowing users to seamlessly interact with dApps without worrying about the underlying technicalities. And this is what Henez is working on.

Berachain, a new and highly-anticipated blockchain, is making waves with its revolutionary approach to liquidity and performance. However, the need for Berachain to tap into multi-chain liquidity becomes crucial for its success in the highly competitive DeFi landscape.

This is where Berachain, Henez, and Hyperlane decide to come together. In this article, we will explore how Henez and Hyperlane can unlock Chain Abstraction on Berachain, providing a step-by-step guide on executing this integration.

Introduction to Berachain

Berachain is a high-performance Layer 1 (L1) blockchain fully compatible with the Ethereum Virtual Machine (EVM). It stands out due to its innovative Proof-of-Liquidity (PoL) consensus mechanism, which aligns security with liquidity. This unique approach rewards liquidity providers with soul-bound reward tokens, directly integrating DeFi applications and protocols into the chain to enhance both liquidity and performance.

Unlike Ethereum, Berachain’s focus on liquidity brings a novel perspective to the blockchain space. Its design enables developers to build and integrate decentralized applications (dApps) seamlessly, particularly within the DeFi ecosystem.

Berachain's Key Features

  1. Modular Design & Interoperability:

    • Berachain is built with a modular architecture, providing flexibility and seamless interoperability in building decentralized applications, especially in the DeFi space.
  2. Tri-Token Model:

    • Berachain operates on a tri-token system with BERA, BGT, and HONEY tokens, which support governance, incentives, and stablecoin operations. This tri-token model enhances the platform’s ability to drive lending, borrowing, and trading operations.
  3. BeaconKit:

    • Berachain also introduces BeaconKit, which extends the Tendermint consensus algorithm to any EVM execution environment, advancing the blockchain modularity landscape. This allows developers to easily build decentralized exchanges (DEXs), lending platforms, and more—all while maintaining compatibility with Ethereum’s ERC standards.

Introduction to Henez

Henez Chain is a high-performance coordination rollup built on top of Arbitrum and Celestia. It enables fast and secure state synchronization and message transfers across both EVM L1/L2 and non-EVM networks, making it an ideal testbed for experimenting with cross-chain communication.

Introduction to Hyperlane

Hyperlane is a cross-chain messaging protocol that enables communication between different blockchain networks. This protocol allows decentralized applications to send messages and data across multiple chains, facilitating seamless interoperability.

Hyperlane offers customizable consensus mechanisms (e.g., proof-of-stake, multisig) for securing cross-chain communications, along with fraud-proof validation via Watchtowers to ensure the integrity of messages. This gives developers powerful tools to build cross-chain applications that can securely interact with Hyperlane’s Inbox and Outbox contracts.

Building a Simple Messaging Contract

Prerequisites

Before diving into building cross-chain messaging, ensure you have the following:

  • Node.js (v20+): Install Node.js and npm following this guide: Node.js Installation.

  • IDEs: Use VScode or your preferred IDE.

  • $ETH and $BERA: You'll need ETH for gas on Henez Testnet and BERA on Berachain bArtio for the demo.

Clone the Repository

git clone https://github.com/henez-foundation/henez-hyperlane-contract-quickstart
$ cd henez-hyperlane-contract-quickstart

Install Dependencies

Before running any commands, rename .env.example to .env and update the DEPLOYER_PRIVATE_KEY.

$ cp .env.example .env
$ yarn install
$ yarn compile

Overview of the CrosschainMessager Contract

The CrosschainMessager Solidity contract enables cross-chain communication using Hyperlane’s messaging protocol. It includes functions for sending messages between blockchain networks and handling incoming messages from other chains.

Core Functions:

  • sendString: Sends messages across chains.

  • handle: Receives and processes incoming messages.

Example Usage:

  1. sendString sends a message from one network to another.

  2. The message is dispatched via Mailbox on the originating chain.

  3. Hyperlane Validator picks up and validates the message.

  4. Hyperlane Relayer relays the message to the destination chain.

  5. On the destination chain, the handle function processes the message.

// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.9;


import "@hyperlane-xyz/core/contracts/interfaces/IMailbox.sol";


contract CrosschainMessager {
   bytes32 public lastSender;
   string public lastMessage;
   IMailbox mailbox;


   event SentMessage(uint32 destinationDomain, bytes32 recipient, string message);
   event ReceivedMessage(uint32 origin, bytes32 sender, bytes message);


   constructor(address _mailbox) {
       mailbox = IMailbox(_mailbox);
   }


   // This function is called by the mailbox when a message is dispatched to this contract
   function handle(uint32 _origin, bytes32 _sender, bytes calldata _message) external {
       lastSender = _sender;
       lastMessage = string(_message);
       emit ReceivedMessage(_origin, _sender, _message);
   }


   // This function sends a message from source chain to the destination chain
   // The message is dispatched to the recipient on the destination chain
   function sendString(uint32 _destinationDomain, bytes32 _recipient, string calldata _message) external {
       mailbox.dispatch(_destinationDomain, _recipient, bytes(_message));
       emit SentMessage(_destinationDomain, _recipient, _message);
   }
}

For more advanced implementations, check out Hyperlane's implementation guide.

Testing and Deployment

Before deploying your contracts, run tests to ensure everything is working correctly:

$ yarn test

Deploy Contracts on Henez and Berachain

First, make sure you have $BERA on Berachain bArtio and $ETH on Henez Testnet in our wallet to cover transaction fees before proceeding to the deployment steps.

Deploy on Henez Testnet

The purpose is to send messages from Berachain bArtio (testnet) to Henez Chain (testnet) and vice versa.

The following Hardhat commands use Hardhat “tasks”, more documentation can be found here.

Now we are going to deploy and run scripts to see how cross-chain messages of Hyperlane work between Henez Testnet and Berachain bArtio

Deploy the Hyperlane Message Receiver and Sender on Henez testnet:

git clone https://github.com/henez-foundation/henez-hyperlane-contract-quickstart
cd henez-hyperlane-contract-quickstart

Deploy on Berachain bArtio Deploy the Hyperlane Message Receiver and Sender on Berachain bArtio:

$ yarn hardhat deployCrosschainMessager --network berabartio

Send messages

Sending messages between Henez Testnet and Bera bArtio can be done by doing the following:

Berachain bArtio to Henez Testnet

# `--message` is the message you wish to send
$ yarn hardhat sendMessage --network berabartio --target heneztestnet --message "Hi from Bera bArtio"

After sending the message, the task listens for new events emitted on the target chain to catch the correct dispatched message.

   // wait for delivery
   const messageId = getMessageIdFromTxReceipt(sentMessageReceipt);
   await waitForMessageIsDelivered(messageId, message, targetChainConfig);

Following is an example output from this task:

📡 "Hi from Bera bArtio" message sent from berabartio to heneztestnet
w/ tx hash 0x56f7d1ccb7be7fff3696363fdb4391059eb07fe123083200bf02decec2912a12 on berabartio
Waiting for MessageId: 0x4490e1625ddefd5f138b2398857ff78aa0876d1bc8084e7c6984efd462db2f8b to be delivered to Henez Testnet
Continue waiting for message
✅ Received message: Hi from Bera bArtio
At tx hash 0x1203739bf4cae488dda3c4e6cbe9cd1aa0b474554105be96af224d5f91dbfb86 on Henez Testnet

Henez Testnet to Berachain bArtio

Likewise, we can send a message in the opposite direction from Henez to Berachain using our deployed contracts:

# `--message` is the message you wish to send
$ yarn hardhat sendMessage --network heneztestnet --target berabartio --message "Hello from Henez Testnet"

After sending the message, the task keeps listening for new events emitted on the target chain to catch the correct dispatched message.

   // wait for delivery
   const messageId = getMessageIdFromTxReceipt(sentMessageReceipt);
   await waitForMessageIsDelivered(messageId, message, targetChainConfig);

Following is an example output from this task:

📡 "Hello from Henez Testnet" message sent from heneztestnet to berabartio
w/ tx hash 0x096d6ae443ad88c4195c19844fc203073656b00b7e1cd294adf829fdf2fe96d7 on heneztestnet
Waiting for MessageId: 0x54d5c9a8b871db69e03a098f23beff4501e8aefb4457c91ea60a623ac6bdb830 to be delivered to Bera Bartio
Continue waiting for message
Continue waiting for message
Continue waiting for message
✅ Received message: Hello from Henez Testnet
At tx hash 0x1913161fa6b6f74c1f75e3ebb7e1b0496b2f94d27016ac5afa3597525360ccbe on Bera Bartio

The full code can be found HERE

Conclusion

In conclusion, this project showcases the powerful capabilities of cross-chain messaging using Hyperlane, enabling seamless communication between different blockchain networks. By leveraging the unique features of Berachain and Henez Testnet, developers can build robust decentralized applications that benefit from enhanced liquidity, interoperability, and performance.

By following the steps outlined in this guide, you can deploy and test smart contracts that send and receive messages between Berachain and Henez Testnet, demonstrating the practical application of cross-chain communication. This project serves as a valuable resource for developers looking to explore and make contract calls with cross-chain messages, bridging assets, etc.

For more information and to access the full code, visit the GitHub repository.

Join Henez on: WebsiteDiscordTelegramTwitterDoc

Subscribe to Henez
Receive the latest updates directly to your inbox.
Mint this entry as an NFT to add it to your collection.
Verification
This entry has been permanently stored onchain and signed by its creator.