LogoLogo
  • ⏩Introduction
    • Hyperlane Introduction
    • Getting started
    • Why Should You Use Hyperlane?
  • Permissionless Interoperability
    • Overview
    • Deploy Hyperlane
    • Warp Routes
      • Deploy a Warp Route
      • Deploy a UI for your Warp Route
    • Modular Rollup Interoperability
  • Build With Hyperlane
    • Quickstarts
      • Messaging
      • Accounts
      • Queries
      • hyperlane-quickstart repo
    • Guides
      • Finding my messages
      • Automatically pay for interchain gas
      • Manually pay for interchain gas
      • Choosing an interchain gas paymaster contract
      • Unit testing
      • Specifying an ISM
      • V2 migration guide
    • Explorer
      • Debugging messages
      • Configuring PI Chains
      • REST API
      • GraphQL API
    • Troubleshooting/Developer FAQ
    • Example apps
  • APIs and SDKs
    • Messaging API
      • Send
      • Receive
    • Accounts API
    • Queries API
    • Warp Route API
    • Interchain gas paymaster API
    • Hyperlane App Framework
      • Example usage
        • HelloWorld
        • Interchain Token
      • Solidity SDK
        • HyperlaneConnectionClient
        • Router
      • NodeJS SDK
        • RPC Providers
        • Deployment
        • Interchain testing
        • Quoting gas payments
        • App Abstraction
    • Hooks API
      • Contract addresses
  • Protocol
    • Overview
    • Mailbox
    • Interchain security modules
      • Interface
      • Multisig ISM
      • Routing ISM
      • Aggregation ISM
      • Optimistic ISM
      • Wormhole ISM
      • Hook ISM
      • CCIP-Read ISM
    • Interchain gas payments
    • Staking and slashing
    • Agents
      • Validators
      • Relayers
      • Watchtowers
    • Warp Routes
    • Implementation Guide
  • Operators
    • Validators
      • Guide
      • AWS setup
      • Monitoring and alerting
    • Relayers
      • Guide
      • Message filtering
    • Agent keys
      • Hexadecimal keys
      • AWS KMS keys
    • Agent configuration
      • Configuration reference
    • Running with docker compose
  • Resources
    • FAQ
    • Glossary
    • Contract addresses
      • Permissionless Deployment Contract Addresses
    • Domain identifiers
      • Permissionless Domain Identifiers
    • Default ISM settings
    • Coming Soon: Hyperlane v3
    • Token sources & faucets
    • Latencies
    • Github
    • Discord
    • Website
Powered by GitBook
On this page
  • Interface
  • Security
  • Access control
  • Interchain security modules
  • Encoding
  • Example usage
  1. APIs and SDKs
  2. Messaging API

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.

Interface

// 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;
}

Security

Access control

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 {};

Interchain security modules

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.

Encoding

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)));
}

Example usage

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);
}
PreviousSendNextAccounts API

Last updated 2 years ago

The following utility is provided in the for convenience.

TypeCasts library