Receive a message
Contracts can receive interchain messages by implementing the handle
function.
Handle
This function is called by the Mailbox
contract when a message is received.
To ensure only valid interchain messages are accepted, it is important to restrict access control to the Mailbox address.
- Solidity
- CosmWasm
- Sealevel
function handle(
uint32 _origin,
bytes32 _sender,
bytes calldata _message
) external payable;
Parameters
origin
: Domain of origin chainsender
: Address of sender on origin chain as bytes32messageBody
: Raw bytes content of message body
Sender addresses 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)));
}
🚧 Coming soon! 🚧
🚧 Coming soon! 🚧
Access Control
The handle
function should be restricted to the Mailbox address if the contract should only accept calls from interchain messages.
The following utility is provided in the MailboxClient
library for convenience.
- Solidity
- CosmWasm
- Sealevel
* @notice Only accept messages from an Hyperlane Mailbox contract
*/
modifier onlyMailbox() {
require(
msg.sender == address(mailbox),
"MailboxClient: sender not mailbox"
);
🚧 Coming soon! 🚧
🚧 Coming soon! 🚧
Examples
- Solidity
- CosmWasm
- Sealevel
function handle(
uint32 _origin,
bytes32 _sender,
bytes calldata _data
) external payable virtual override {
emit ReceivedMessage(_origin, _sender, msg.value, string(_data));
lastSender = _sender;
lastData = _data;
}
🚧 Coming soon! 🚧
🚧 Coming soon! 🚧
Verify
When a message is received, the Mailbox will verify security with an Interchain Security Module before calling the message recipient's handle
.
Default Security
To query the default ISM address, you can call the defaultIsm
function.
- Solidity
function defaultHook() external view returns (IPostDispatchHook);
Modular Security
To leverage Hyperlane's modular security, message recipients can specify a custom Interchain Security Module to verify anything about incoming messages. The Mailbox will defer to this ISM when specified.
- Solidity
- CosmWasm
- Sealevel
) external returns (bool);
}
interface ISpecifiesInterchainSecurityModule {
🚧 Coming soon! 🚧
🚧 Coming soon! 🚧