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

PreviousCreating New ModulesNextModules Registry

Last updated 1 year ago

All contracts that inherit from can be deployed as minimal proxy clones via , 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 to easily deploy new module instances and more.

Create New Instance

The 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 .

  • _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 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.

  • _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

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.

Returns:

  • The predicted instance address.

Check If 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.

Returns:

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

HatsModuleFactory Deployments

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

The function creates multiple instances, using the function.

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

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

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

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

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

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

๐Ÿงฉ
โš’๏ธ
getHatsModuleAddress
deployed
v0.6.0
Ethereum Mainnet
Optimism
Gnosis Chain
Polygon
Arbitrum
PGN
Celo
Base
Sepolia testnet
Goerli testnet
batchCreateHatsModule
createHatsModule
HatsModule
HatsModuleFactory
Modules SDK
createHatsModule
already included in HatsModule
already included in HatsModule
already included in HatsModule
already included in HatsModule