# Inside a Hats Module

Typically, Hats Modules inherit from the [HatsModule.sol](https://github.com/Hats-Protocol/hats-module/blob/main/src/HatsModule.sol) contract. This is an abstract contract that provides a generic structure that modules can extend to support any specific use case.

It serves several key functions:

1. Provide the basic boiler plate required for a new Hats module contract.
2. Enable compatibility with [HatsModuleFactory.sol](/for-developers/hats-modules/building-hats-modules/how-module-instances-are-deployed.md), the easiest and cheapest way for users to deploy new instances of a given module.
3. Enable compatibility with the [module registry](https://github.com/Hats-Protocol/modules-registry), which facilitates user discovery and integration into Hats front ends.

{% hint style="info" %}
Inheriting from HatsModule.sol is necessary to be deployable via HatsModuleFactory, to be listed in the Module registry, and to appear natively in the applications using the registry.&#x20;

However, it is *not* required for compatibility with Hats Protocol more generally. See the docs for [Eligibility](/for-developers/hats-protocol-for-developers/eligibility-modules.md) and [Toggle](/for-developers/hats-protocol-for-developers/toggle-modules.md) modules for those requirements.

The remainder of this documentation assumes inheritance of HatsModule.
{% endhint %}

## HatsModule.sol

HatsModule.sol's primary function is to enable a module to be configured and deployed via [HatsModuleFactory](/for-developers/hats-modules/building-hats-modules/how-module-instances-are-deployed.md). Often, each new hat to which a module is attached involves a new instance of that module, so its important for deployment to be gas-efficient. Additionally, each module is likely to be called many times over its life, so its also important for runtime execution to be gas-efficient.&#x20;

For these reasons, HatsModule.sol is structured as a minimal proxy (clone) contract — similar to the [EIP-1167](https://eips.ethereum.org/EIPS/eip-1167) standard — that also supports immutable arguments. It implements the gas-efficient [LibClone.sol](https://github.com/Vectorized/solady/blob/6c54795ef69838e233020e9ab29f3f6288efdf06/src/utils/LibClone.sol) library.

See the following pages for more detail about how HatsModule.sol operates:

{% content-ref url="/pages/vokQXo16OuQDIszO7Krp" %}
[Immutable Arguments](/for-developers/hats-modules/building-hats-modules/inside-a-hats-module/immutable-arguments.md)
{% endcontent-ref %}

{% content-ref url="/pages/0IyDA235qClbd13GWZbr" %}
[Module Setup](/for-developers/hats-modules/building-hats-modules/inside-a-hats-module/module-setup.md)
{% endcontent-ref %}

{% content-ref url="/pages/ZtkvFYh7zsBQbEF9Gvel" %}
[Versioning](/for-developers/hats-modules/building-hats-modules/inside-a-hats-module/versioning.md)
{% endcontent-ref %}

### Extensions

There are a couple stock extensions to HatsModule.sol that are useful starting points for common types of modules:

* HatsEligibilityModule.sol: implements [`IHatsEligibility.sol`](/for-developers/hats-protocol-for-developers/eligibility-modules.md)
* HatsToggleModule.sol: implements [`IHatsToggle.sol`](/for-developers/hats-protocol-for-developers/toggle-modules.md)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.hatsprotocol.xyz/for-developers/hats-modules/building-hats-modules/inside-a-hats-module.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
