Receive
Receive an inbound message from any Hyperlane supported network.
Developers must implement the handle() ABI in order to receive interchain messages.

Interface

interface IMessageRecipient {
function handle(
uint32 _origin,
bytes32 _sender,
bytes calldata _messageBody
) external;
}
_origin the Domain ID of the source chain, IDs found here.
_sender the address of the message sender on the source chain, it must match or the message will revert.
_messageBody the message being passed.

Access Control

To ensure only valid interchain messages are accepted, it is important to require that msg.sender is a known Hyperlane Inbox.
Developers can reference deployed Inbox addresses and corresponding domain identifiers in the docs. An example of Inbox access control implemented on avalanche for restricting inbound messages from ethereum is provided below.
uint32 constant ethereumDomain = 0x657468;
address constant ethereumInbox = 0x0E3239277501d215e17a4d31c487F86a425E110B;
// for access control on handle implementations
modifier onlyEthereumInbox(uint32 origin) {
require(origin == ethereumDomain && msg.sender == ethereumInbox);
_;
}
A generalized message access control layer is provided in the AbacusConnectionManager library, and Abacus Works has deployed and maintained these registries on all supported networks.
Note: Abacus is the former name of the Hyperlane protocol. The ACM will soon be renamed.

Encoding

Hyperlane message senders are left-padded to bytes32 for compatibility with virtual machines that are addressed differently.
The following utility is provided in the TypeCasts library for convenience.
// alignment preserving cast
function bytes32ToAddress(bytes32 _buf) internal pure returns (address) {
return address(uint160(uint256(_buf)));
}

Example Usage

An example handle() implementation for receiving messages from Ethereum on Avalanche is provided below.
event Received(address sender, bytes message);
function handle(
uint32 _origin,
bytes32 _sender,
bytes memory _message
) external onlyEthereumInbox(_origin) {
address sender = bytes32ToAddress(_sender);
emit Received(sender, _message);
}
Last modified 16d ago
Copy link
On this page
Interface
Access Control
Encoding
Example Usage