Receive
Receive an inbound message from any Hyperlane supported network
Developers must implement the
IMessageRecipient
interface in order to be able to receive interchain messages.// SPDX-License-Identifier: MIT OR Apache-2.0
pragma solidity >=0.6.11;
interface IMessageRecipient {
/**
* @notice Handle an interchain message
* @param _origin Domain ID of the chain from which the message came
* @param _sender Address of the message sender on the origin chain as bytes32
* @param _body Raw bytes content of message body
*/
function handle(
uint32 _origin,
bytes32 _sender,
bytes calldata _body
) external;
}
To ensure only valid interchain messages are accepted, it is important to require that
msg.sender
is a known Hyperlane Mailbox.Developers must implement access control on
handle()
in order to ensure the security of interchain messages. Only a Hyperlane Mailbox contract should have permission to call this function. An example of this access control is shown below.address constant mailbox = 0x0E3239277501d215e17a4d31c487F86a425E110B;
// for access control on handle implementations
modifier onlyMailbox() {
require(msg.sender == mailbox);
_;
}
function handle(
uint32 _origin,
bytes32 _sender,
bytes calldata _body
) external onlyMailbox {};
Developers can override Hyperlane's default Multisig ISM-based security model by specifying their own Interchain security modules.
See the Interchain security modules documentation for more info on how to set the ISM used by your application.
Hyperlane message senders are left-padded to
bytes32
for compatibility with virtual machines that are addressed differently.// alignment preserving cast
function bytes32ToAddress(bytes32 _buf) internal pure returns (address) {
return address(uint160(uint256(_buf)));
}
An example
handle()
implementation for receiving messages is provided below.event Received(uint32 origin, address sender, bytes body);
function handle(
uint32 _origin,
bytes32 _sender,
bytes memory _body
) external onlyMailbox() {
address sender = bytes32ToAddress(_sender);
emit Received(_origin, sender, _body);
}
Last modified 1mo ago