ModuleKit
Build
Fallbacks

Fallbacks

Fallbacks are modules that can add additional functionality into the account. They are called by the fallback function of the account.

A module can be broken down into three different domains:

  1. Config: Handles configurations on the module, such as installation and uninstallation
  2. Business logic: Handles the core logic of the module, depending on the module type
  3. Metadata: Additional data that is used to identify and correctly use a module

This page only covers domain 2 in the specific case of a Fallback Module. For more information on domains 1 and 3, read through the Module page.

⚠️

Fallback modules are still in development and we expect some breaking changes to the interface.

Building a fallback module

To build a compliant fallback module you need to ensure that it:

  • Inherits from the ERC7579FallbackBase contract.
  • Implements the required functions of the interface.

An example of a compliant fallback module (without actual logic) looks like this:

contract FallbackExample is ERC7579FallbackBase {
    /*//////////////////////////////////////////////////////////////////////////
                                     CONFIG
    //////////////////////////////////////////////////////////////////////////*/
 
    ...
 
    /*//////////////////////////////////////////////////////////////////////////
                                     MODULE LOGIC
    //////////////////////////////////////////////////////////////////////////*/
 
    /**
     * ERC-7579 does not define any specific interface for fallbacks, so the
     * fallback can implement any logic that is required for the specific usecase.
     */
 
    /*
     * Handles a fallback call
     * @dev This is an example function that can be used to handle a fallback call
     * @dev This function is not part of the ERC-7579 standard
     * @param account The account that received the call
     * @param sender The sender of the call
     * @param value The value of the call
     * @param data The data of the call
     * @return result The result of the fallback call
     */
    function handle(
        address account,
        address sender,
        uint256 value,
        bytes calldata data
    )
        external
        override
        returns (bytes memory result)
    {
        result = abi.encode(true);
    }
 
    /*//////////////////////////////////////////////////////////////////////////
                                     METADATA
    //////////////////////////////////////////////////////////////////////////*/
 
    ...
}

handle

This function is called when the account receives a call that does not match any of the other modules. It can be used to implement custom logic for handling these calls.

Fallback examples