Message Passing (Writes)
Metalayer allows developers to send arbitrary messages between chains. This is useful for intent settlement, contract coordination, governance execution, and multi-chain applications.
Overview
Metalayer allows developers to send arbitrary messages between chains. Metalayer message passing is implemented as an extension of Hyperlane’s message-passing protocol.
How Messages Work in Metalayer
- A contract on the source chain calls
dispatch
, sending a payload to a contract on the destination chain. - Hyperlane’s relayers transport the message securely.
- The recipient contract processes the message by decoding it.
Example Message Passing
For full developer documentation, see the Cross-Chain dApps section.
This example demonstrates a simple cross-chain messaging system using Metalayer. We’ll create two contracts:
- A sender contract that dispatches messages
- A receiver contract that counts and stores received messages
Hello World Sender
The sender contract needs to:
- Store the router address and destination information
- Calculate gas fees for message delivery
- Format and dispatch messages
Hello World Receiver
The receiver contract must:
- Implement the IMetalayerRecipient interface
- Store the router address and verify message sources
- Track received messages