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 Eligibility/Toggle Chains
  • createEligibilitiesChain
  • createTogglesChain
  • Read From Eligibility/Toggle Chains
  • getRulesets
  • getRulesetsBatched
  • isChain
  • isChainBatched
  1. For Developers
  2. Hats Modules
  3. Modules SDK

Composing Modules

PreviousCreate New Instance/sNextInteract With Instances

Last updated 1 year ago

The following functions support the usage Eligibility/Toggle modules that compose other existing modules with "and"/"or" logical operations. Check out the documentation to learn more.

Create New Eligibility/Toggle Chains

createEligibilitiesChain

Create a new eligibilities chain module.

const createInstanceResult = await hatsModulesClient.createEligibilitiesChain({
    account,
    hatId,
    numClauses,
    clausesLengths,
    modules,
    saltNonce,
});

Arguments:

{
    account: Account | Address;
    hatId: bigint;
    numClauses: number;
    clausesLengths: number[];
    modules: `0x${string}`[];
    saltNonce?: bigint;
}
  • account - Viem account (Address for JSON-RPC accounts or Account for other types).

  • hatId - The hat ID for which the module is created.

  • numClauses - Number of conjunction clauses.

  • clausesLengths - Length of each clause.

  • modules- Array of module instances to chain, at the order corresponding to the provided clauses.

  • saltNonce - Optional salt nonce to use. If not provided, will be randomly generated.

Response:

{
  status: "success" | "reverted";
  transactionHash: `0x${string}`;
  newInstance: `0x${string}`;
}
  • status - "success" if transaction was successful, "reverted" if transaction reverted.

  • transactionHash - transaction's hash.

  • newInstance - In case of success, the address of the new chain module instance.

createTogglesChain

Create a new toggles chain module.

const createInstanceResult = await hatsModulesClient.createTogglesChain({
    account,
    hatId,
    numClauses,
    clausesLengths,
    modules,
    saltNonce,
});

Arguments:

{
    account: Account | Address;
    hatId: bigint;
    numClauses: number;
    clausesLengths: number[];
    modules: `0x${string}`[];
    saltNonce?: bigint;
}
  • account - Viem account (Address for JSON-RPC accounts or Account for other types).

  • hatId - The hat ID for which the module is created.

  • numClauses - Number of conjunction clauses.

  • clausesLengths - Length of each clause.

  • modules- Array of module instances to chain, at the order corresponding to the provided clauses.

  • saltNonce - Optional salt nonce to use. If not provided, will be randomly generated.

Response:

{
  status: "success" | "reverted";
  transactionHash: `0x${string}`;
  newInstance: `0x${string}`;
}
  • status - "success" if transaction was successful, "reverted" if transaction reverted.

  • transactionHash - transaction's hash.

  • newInstance - In case of success, the address of the new chain module instance.

Read From Eligibility/Toggle Chains

The following functions support reading from chain module instances.

getRulesets

Get the rulesets of a module instance.

A ruleset is an array of modules which are chained together with an "AND" logical operator. If the module is a chain with multiple rulesets, then these rulesets are chained together with an "OR" logical operator.

If the provided address is a single module instance (not a chain), then the result will be a single ruleset, which will consist of the single module instance.

const rulesets = await hatsModulesClient.getRulesets(address);

Arguments:

`0x${string}`

Instance address.

Response:

Ruleset[] | undefined

getRulesetsBatched

Get the rulesets of multiple module instances.

A ruleset is an array of modules which are chained together with an "AND" logical operator. If the module is a chain with multiple rulesets, then these rulesets are chained together with an "OR" logical operator.

If the provided address is a single module instance (not a chain), then the result will be a single ruleset, which will consist of the single module instance.

const rulesets = await hatsModulesClient.getRulesetsBatched(addresses);

Arguments:

`0x${string}`[]

Array of instance addresses.

Response:

(Ruleset[] | undefined)[]

isChain

Check whether a module instance is a modules chain.

const isChain = await hatsModulesClient.isChain(address);

Arguments:

`0x${string}`

Instance address.

Response:

boolean

true if the instance is a chain, false otherwise.

isChainBatched

Check whether multiple module instances are modules chains.

const isChainBatched = await hatsModulesClient.isChainBatched(addresses);

Arguments:

`0x${string}`[]

Instance addresses.

Response:

boolean[]

For each instance, true if the instance is a chain, false otherwise.

The module's , or undefined if the provided address is not a module.

For each module instance, returns the module's , or undefined if the provided address is not a module.

๐Ÿงฉ
๐Ÿ”Œ
here
rulesets
rulesets