Hats Protocol Docs
hatsprotocol.xyzGithub
  • 👋Welcome to Hats Protocol
  • 🧢Getting Started with Hats
  • ⭐Quick Start
  • Using The Hats App
    • 🤠Essentials For Hat Wearers
    • 🎩Creating My First Hat
    • 🧙Admins: Creating, Issuing, and Revising Hats
    • 👥What Hats Do I Need?
    • 🌳Drafting, Exporting, and Deploying Tree Changes
    • 🏗️Setting a Hat's Basic Properties
    • 🥳Adding Wearers
    • 🔐Connecting Hats w/ Permissions & Authorities
      • Types of Hat-Powered Authorities
      • Connecting Hats to Token Gates
        • Hats Protocol Contract Addresses
        • Finding a Hat's Token ID
      • Documenting Hat Powers & Responsibilities
    • 🌟Revocation & Eligibility: Requirements for Wearers
    • ⚡Deactivating & Reactivating Hats
    • ✅Making Hats Claimable
    • 🔗Linking Trees Together
    • ⛓️Hats Protocol Supported Chains
    • ❓Glossary & FAQ
  • Hats Integrations
    • 🔐Permissions & Authorities
      • Coordinape
      • Council Voting Vault
      • Charmverse
      • Discord
        • Collab.Land --> Discord
        • Guild.xyz --> Discord
      • Farcaster Casting Rights
      • Fileverse
      • Google Workspace
      • Hats Account
      • Role-Based Compensation
      • Safe Multisig Signing Authority
      • Telegram
        • Collab.Land --> Telegram
        • Guild.xyz --> Telegram
      • Snapshot: Voting, Weight & Proposal Creation
      • Wonderverse
    • 🌟Eligibility & Accountability Criteria
      • Agreement Eligibility
      • Allow-List Eligibility
      • CoLinks Eligibility
      • ERC20 Eligibility
      • ERC721 Eligibility
      • ERC1155 Eligibility
      • Hat-Wearing Eligibility
      • Hats Election Eligibility
      • JokeRace Eligibility
      • Pass-Through (Hat-Based) Eligibility
      • Staking Eligibility
      • Subscription or Membership Fee (Unlock Protocol)
      • Gitcoin Passport Eligibility
    • ⚡Activation & Deactivation Criteria
      • Seasonal/ Time-Expiry Toggle
      • Pass-Through (Hat-Based) Toggle
    • 👷Hatter Modules
      • Multi Claims Hatter
      • DAOhaus Moloch v3 Membership & Share Allocation
  • For Developers
    • 👷Hats Protocol, for Developers
      • Hat Properties
      • Wearing a Hat
      • Hat Admins & Hatter Contracts
      • Hats Trees
      • Hat IDs
      • Linking Hats Trees
      • Eligibility Modules
      • Toggle Modules
      • Hat Mutability and Editing
      • Creating Hats
      • Minting Hats
      • Transfering Hats
      • Renouncing Hats
      • Batch Actions
      • Hat Image URIs
      • ERC1155 Compatibility
      • ⛓️Supported Chains
    • 🤖v1 Protocol Spec
      • Hats.sol
      • HatsEvents.sol
      • HatsErrors.sol
      • HatsIdUtilities.sol
      • Interfaces
        • IHats.sol
        • IHatsIdUtilities.sol
        • IHatsEligibility.sol
        • IHatsToggle.sol
    • 🖥️v1 SDK
      • Core
        • Getting Started
        • Onchain Reads
        • Onchain Writes
        • Multicall
        • Claiming Hats
        • Utilities
      • Subgraph
        • Getting Started
        • Fetching Hats
        • Fetching Wearers
        • Fetching Trees
        • Misc
        • Types
      • Hat Details
        • Getting Started
        • Usage
    • 🔭v1 Subgraphs
    • 🧩Hats Modules
      • 🔌Modules SDK
        • Getting Started
        • Get Available Modules
        • Create New Instance/s
        • Composing Modules
        • Interact With Instances
        • Utilities
        • Types
      • ⚒️Building Hats Modules
        • Inside a Hats Module
          • Immutable Arguments
          • Module Setup
          • Versioning
        • Creating New Modules
        • How Module Instances Are Deployed
        • Modules Registry
        • About Module Chains
    • 🔏Hats Signer Gate v2
    • 👒Hats Signer Gate SDK
      • Getting Started
      • Creating New Instances
      • Hats Signer Gate
      • Multi Hats Signer Gate
      • HSG & MHSG Handlers
    • 💼Hats Account SDK
      • 1 of N Hats Account
        • Getting Started
        • Creating New Instances
        • Executing From An Instance
        • Constants
        • Types
    • 🌐Hats Security Audits
  • Legal
    • Terms
      • Terms of Service
      • Acceptable Use
      • Privacy Policy
      • Cookie Policy
      • Attribution
Powered by GitBook
On this page
  • Create New Instance
  • Batch Create Multiple Instances
  • Predict Module's Address
  • Check If Deployed
  • HatsModuleFactory Deployments
  1. For Developers
  2. Hats Modules
  3. Building Hats Modules

How Module Instances Are Deployed

All contracts that inherit from HatsModule can be deployed as minimal proxy clones via HatsModuleFactory, which offers several operations:

  • create a single module instance

  • batch create multiple module instances

  • predict the address of a module instance

  • check if a module instance has already been deployed

Each of these functions can be called directly on the HatsModuleFactory contract, or they can be accessed via the Modules SDK to easily deploy new module instances and more.

Create New Instance

The createHatsModule function deploys a new proxy instance, for the provided implementation, to a deterministic address. The instance's immutable arguments are set its creation, and then instance.setUp is called with the provided initialization data.

function createHatsModule(
    address _implementation,
    uint256 _hatId,
    bytes calldata _otherImmutableArgs,
    bytes calldata _initData
) public returns (address _instance)

Parameters:

  • _implementation - The address of the implementation contract for which to deploy a clone.

  • _hatId - The hat for which to deploy the module.

  • _otherImmutableArgs: Immutable arguments to pass to the clone, packed encoded (via abi.encodePacked). These are additional to the ones already included in HatsModule.

  • _initData - Encoded data (via abi.encode) to pass to the setUp function of the new instance.

Returns:

  • _instance - The new instance's address.

Events:

Once the new module deployment and setup have completed, the function will emit the following event, which contains the new instance address:

event HatsModuleFactory_ModuleDeployed(
    address implementation, address instance, uint256 hatId, bytes otherImmutableArgs, bytes initData
);

Batch Create Multiple Instances

The batchCreateHatsModule function creates multiple instances, using the createHatsModule function.

The necessary creation parameters are passed as arrays, which must have the same length, equal to the number of modules to be created. For each module, the createHatsModule function will be called with the arrays entries, on the same corresponding index.

function batchCreateHatsModule(
    address[] calldata _implementations,
    uint256[] calldata _hatIds,
    bytes[] calldata _otherImmutableArgsArray,
    bytes[] calldata _initDataArray
) public returns (bool success)

Parameters:

  • _implementations - The addresses of the implementation contracts for which to deploy a clone.

  • _hatIds - The hats for which to deploy the modules.

  • _otherImmutableArgsArray: Immutable argumentss to pass to the clones, packed encoded (via abi.encodePacked). These are additional to the ones already included in HatsModule.

  • _initDataArray - Encoded data (via abi.encode) to pass to the setUp function of each new module instance.

Returns:

  • success - True if all modules were successfully created and initialized, false otherwise.

Events:

For every successfully created module, the function will emit the following event, which contains the new instance address:

event HatsModuleFactory_ModuleDeployed(
    address implementation, address instance, uint256 hatId, bytes otherImmutableArgs, bytes initData
);

Predict Module's Address

The getHatsModuleAddress function predicts the address of a module instance before it was created.

function getHatsModuleAddress(address _implementation, uint256 _hatId, bytes calldata _otherImmutableArgs)
    public
    view
returns (address)

Parameters:

  • _implementation - The address of the implementation contract.

  • _hatId - The hat for which to deploy a module.

  • _otherImmutableArgs: Immutable arguments to pass to the clone, packed encoded (via abi.encodePacked). These are additional to the ones already included in HatsModule.

Returns:

  • The predicted instance address.

Check If Deployed

The deployed function checks if a certain module instance has been deployed.

function deployed(address _implementation, uint256 _hatId, bytes calldata _otherImmutableArgs)
    public
    view
returns (bool)

Parameters:

  • _implementation - The address of the implementation contract.

  • _hatId - The hat for which to deploy a module.

  • _otherImmutableArgs: Immutable arguments to pass to the clone, packed encoded (via abi.encodePacked). These are additional to the ones already included in HatsModule.

Returns:

  • True if the instance has been deployed, false otherwise.

HatsModuleFactory Deployments

HatsModuleFactory v0.6.0 is deployed to the same address on all networks: 0xfE661c01891172046feE16D3a57c3Cf456729efA

It is known to have been deployed to the following networks:

  • Ethereum Mainnet

  • Optimism

  • Gnosis Chain

  • Polygon

  • Arbitrum

  • PGN

  • Celo

  • Base

  • Sepolia testnet

  • Goerli testnet

PreviousCreating New ModulesNextModules Registry

Last updated 1 year ago

🧩
⚒️