Direct Message Delivery

Set directMsgsEnabled to true and reduce gas fees

There are two ways that an application can receive messages from the protocol. These are:

  1. From the endpoint, or

  2. Directly from the receiving module.

The advantage of receiving from the module is that you spend less gas; fewer function calls, etc. .

On the other hand, the advantage of using the endpoint is that you do not need to update the address of the receive module whenever you change the library for receiving messages; as you can see from the PingPong example application, there is an onlyEndpointOrLibraryReceiveModule guard make sure that the receiveMsg function is called from the receive endpoint or the library. Code example is shown below.

// Modifier used for the receive function to endure that the only address 
// that can call the function is the endpoint
modifier onlyEndpointOrLibraryReceiveModule() {
    if (!directMsgsEnabled) {
        require(msg.sender == endpoint);
    } else {
        require(msg.sender == libraryReceiveModule);

function receiveMsg(
    uint256 _senderChainId,
    bytes memory _sender,
    uint256 _nonce,
    bytes memory _payload,
    bytes memory _additionalInfo
) external onlyEndpointOrLibraryReceiveModule() {
    // some business logic here

If direct messages are enabled, changing the library means that we would also need to update the saved libraryReceiveModule variable so that it checks against the correct address.

Our team is available to help if you need assistance implementing/testing this. Reach out if you are interested in building an oracle or relayer or if you have any questions; our discord is the best place to get in touch with us!

Last updated