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
  • getSchema
  • verify
  • solidityToTypescriptType
  • checkAndEncodeArgs
  • checkImmutableArgs
  • checkMutableArgs
  • getNewInstancesFromReceipt
  1. For Developers
  2. Hats Modules
  3. Modules SDK

Utilities

getSchema

The SDK uses Zod schemas in order to verify inputs for createNewInstance, according to their target Solidity types. The getSchema function is exported as a utility function, to get the Zod schema for a corresponding Solidity type.

import { getSchema } from "@hatsprotocol/modules-sdk";

const schema = getSchema(solidityType);

Arguments:

solidityType: string

solidityType - The name of the Solidity type, e.g. "uint256".

Response:

ZodType

The Zod schema for the provided type.

verify

Verify a value according to its target Solidity type.

import { verify } from "@hatsprotocol/modules-sdk";

const isValid = verify(val, type);

Arguments:

(val: unknown, type: string)
  • val - The value to verify.

  • type - The target Solidity type for the provided value.

Response:

boolean

true if the provided value is compatible with the Solidity type, false otherwise.

solidityToTypescriptType

Utility function that maps between a Solidity type to its compatible Typescript type.

import { solidityToTypescriptType } from "@hatsprotocol/modules-sdk";

const tsType = solidityToTypescriptType(solidityType);

Arguments:

solidityType: string

solidityType - The name of the Solidity type, e.g. "uint256".

Response:

"number"    | 
"bigint"    |
"string"    |
"boolean"   |
"number[]"  | 
"bigint[]"  | 
"string[]"  | 
"boolean[]" | 
"unknown"

The name of the Typescript type which is compatible to the provided Solidity one.

checkAndEncodeArgs

Check and encode the immutable and mutable arguments for module creation.

import { checkAndEncodeArgs } from "@hatsprotocol/modules-sdk";

const { encodedImmutableArgs, encodedMutableArgs } = checkAndEncodeArgs({
   module,
   immutableArgs,
   mutableArgs,
});

Arguments:

{
  module: Module;
  immutableArgs: unknown[];
  mutableArgs: unknown[];
}

module - The module object of the module that will be created.

immutableArgs - The module's immutable arguments.

mutableArgs - The modules's mutable arguments.

Response:

{
  encodedImmutableArgs: "" | `0x${string}`;
  encodedMutableArgs: "" | `0x${string}`;
}

checkImmutableArgs

Check the immutable arguments for module creation.

Checks that the provided immutable arguments are valid according to the module's schema from the registry. If not, the function will throw a detailed error.

import { checkImmutableArgs } from "@hatsprotocol/modules-sdk";

checkImmutableArgs({ module, immutableArgs });

Arguments:

{
  module: Module;
  immutableArgs: unknown[];
}

module - The module object of the module that will be created.

immutableArgs - The module's immutable arguments.

checkMutableArgs

Check the mutable arguments for module creation.

Checks that the provided mutable arguments are valid according to the module's schema from the registry. If not, the function will throw a detailed error.

import { checkMutableArgs } from "@hatsprotocol/modules-sdk";

checkMutableArgs({ module, mutableArgs });

Arguments:

{
  module: Module;
  mutableArgs: unknown[];
}

module - The module object of the module that will be created.

mutableArgs - The module's mutable arguments.

getNewInstancesFromReceipt

Get the addresses of newly created module instance/s, using the creation transaction receipt.

import { getNewInstancesFromReceipt } from "@hatsprotocol/modules-sdk";

const instances = getNewInstancesFromReceipt(receipt);

Arguments:

receipt: TransactionReceipt

receipt - The transaction receipt as a TransactionReceipt Viem object.

Response:

`0x${string}`[]

An array of the newly created instances/s.

PreviousInteract With InstancesNextTypes

Last updated 1 year ago

This is a utility function for interacting with the directly, rather than using the function from the SDK. This may be useful in cases where the module creation is proxied by another contract and expects similar input parameters as the function from the factory.

The encoded immutable and mutable arguments, as expected by the function from the factory.

๐Ÿงฉ
๐Ÿ”Œ
createHatsModule
HatsModuleFactory
createHatsModule
createNewInstance