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
  • mintTopHat
  • createHat
  • batchCreateHats
  • mintHat
  • batchMintHats
  • setHatStatus
  • checkHatStatus
  • setHatWearerStatus
  • checkHatWearerStatus
  • renounceHat
  • transferHat
  • makeHatImmutable
  • changeHatDetails
  • changeHatEligibility
  • changeHatToggle
  • changeHatImageURI
  • changeHatMaxSupply
  • requestLinkTopHatToTree
  • approveLinkTopHatToTree
  • unlinkTopHatFromTree
  • relinkTopHatWithinTree
  1. For Developers
  2. v1 SDK
  3. Core

Onchain Writes

mintTopHat

Create a new tophat (new tree).

const mintTopHatResult = await hatsClient.mintTopHat({
    account,
    target,
    details,
    imageURI,
});

Arguments:

{
    account: Account | Address;
    target: Address;
    details: string;
    imageURI?: string;
}
  • account - Viem account (Address for JSON-RPC accounts or Account for other types).

  • target - tophat's wearer address.

  • details - tophat's details field.

  • imageURI - optional tophat's image URI.

Response:

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

  • transactionHash - transaction's hash.

  • hatId - ID of the created tophat.

createHat

Create a hat.

const createHatResult = await hatsClient.createHat({
    account,
    admin,
    details,
    maxSupply,
    eligibility,
    toggle,
    mutable,
    imageURI,
});

Arguments:

{
    account: Account | Address;
    admin: bigint;
    details: string;
    maxSupply: number;
    eligibility: Address;
    toggle: Address;
    mutable: boolean;
    imageURI?: string;
}
  • account - Viem account (Address for JSON-RPC accounts or Account for other types).

  • admin - hat's admin ID.

  • details - hat's details field.

  • maxSupply - hat's maximum amount of possible wearers.

  • eligibility - hat's eligibility address (zero address is not valid).

  • toggle - hat's toggle address (zero address is not valid).

  • mutable - true if the hat should be mutable, false otherwise.

  • imageURI - optional hat's image URI.

Response:

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

  • transactionHash - transaction's hash.

  • hatId - ID of the created hat.

batchCreateHats

Create multiple hats.

const batchCreateHatsResult = await hatsClient.batchCreateHats({
    account,
    admins,
    details,
    maxSupplies,
    eligibilityModules,
    toggleModules,
    mutables,
    imageURIs,
});

Arguments:

{
    account: Account | Address;
    admins: bigint[];
    details: string[];
    maxSupplies: number[];
    eligibilityModules: Address[];
    toggleModules: Address[];
    mutables: boolean[];
    imageURIs?: string[];
}
  • account - Viem account (Address for JSON-RPC accounts or Account for other types).

  • admins - hats admin IDs.

  • details - hats details fields.

  • maxSupplies - hats maximum amounts of possible wearers.

  • eligibilityModules - hats eligibility addresses (zero address is not valid).

  • toggleModules - hats toggle addresses (zero address is not valid).

  • mutables - true if the hat should be mutable, false otherwise.

  • imageURIs - optional hats image URIs.

Response:

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

  • transactionHash - transaction's hash.

  • hatIds - IDs of the created hats.

mintHat

Mint a hat.

const mintHatResult = await hatsClient.mintHat({
    account,
    hatId,
    wearer,
});

Arguments:

{
    account: Account | Address;
    hatId: bigint;
    wearer: Address;
}
  • account - Viem account (Address for JSON-RPC accounts or Account for other types).

  • hatId - hat's ID.

  • wearer - address of the new wearer.

Response:

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

  • transactionHash - transaction's hash.

batchMintHats

Mint multiple hats.

const batchMintHatsResult = await hatsClient.batchMintHats({
    account,
    hatIds,
    wearers,
});

Arguments:

{
    account: Account | Address;
    hatIds: bigint[];
    wearers: Address[];
}
  • account - Viem account (Address for JSON-RPC accounts or Account for other types).

  • hatIds - hats IDs.

  • wearers - addresses of the new wearers.

Response:

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

  • transactionHash - transaction's hash.

setHatStatus

Set a hat's status to active/inactive.

const setHatStatusResult = await hatsClient.setHatStatus({
    account,
    hatId,
    newStatus,
});

Arguments:

{
    account: Account | Address;
    hatId: bigint;
    newStatus: boolean;
}
  • account - Viem account (Address for JSON-RPC accounts or Account for other types).

  • hatId - hat's ID.

  • newStatus - hat's new status: true for active, false for inactive.

Response:

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

  • transactionHash - transaction's hash.

checkHatStatus

Check a hat's status by calling its toggle module, and updating the status as needed.

const checkHatStatusResult = await hatsClient.checkHatStatus({
    account,
    hatId,
});

Arguments:

{
    account: Account | Address;
    hatId: bigint;
}
  • account - Viem account (Address for JSON-RPC accounts or Account for other types).

  • hatId - hat's ID.

Response:

{
  status: "success" | "reverted";
  transactionHash: `0x${string}`;
  toggled: boolean;
  newStatus?: "active" | "inactive";
}
  • status - "success" if transaction was successful, "reverted" if transaction reverted.

  • transactionHash - transaction's hash.

  • toggled - true if the hat's status was changed (toggled), false otherwise.

  • newStatus - if hat's status was changed (toggled), then contains its new status.

setHatWearerStatus

Set a hat's wearer status.

const setHatWearerStatusResult = await hatsClient.setHatWearerStatus({
    account,
    hatId,
    wearer,
    eligible,
    standing,
});

Arguments:

{
    account: Account | Address;
    hatId: bigint;
    wearer: Address;
    eligible: boolean;
    standing: boolean;
}
  • account - Viem account (Address for JSON-RPC accounts or Account for other types).

  • hatId - hat's ID.

  • wearer - wearer address.

  • eligible - wearer's eligibility. true for eligible, false otherwise.

  • standing - wearer's standing. true for good, false for bad.

Response:

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

  • transactionHash - transaction's hash.

checkHatWearerStatus

Check a hat's wearer status by calling the hat's eligibility module. If the wearer is non eligible and/or in bad standing, then its hat is burned.

const checkHatWearerStatusResult = await hatsClient.checkHatWearerStatus({
    account,
    hatId,
    wearer,
});

Arguments:

{
    account: Account | Address;
    hatId: bigint;
    wearer: Address;
}
  • account - Viem account (Address for JSON-RPC accounts or Account for other types).

  • hatId - hat's ID.

  • wearer - wearer address.

Response:

{
  status: "success" | "reverted";
  transactionHash: `0x${string}`;
  wearerStandingUpdated: boolean;
  hatBurned: boolean;
  newWearerStanding?: "good" | "bad";
}
  • status - "success" if transaction was successful, "reverted" if transaction reverted.

  • transactionHash - Transaction's hash.

  • wearerStandingUpdated - true if the wearer's standing was changed (toggled), false otherwise.

  • hatBurned - true if the wearer's hat was burned in the transaction, false otherwise.

  • newWearerStanding - if the wearer standing was changed, then contains the new standing status.

renounceHat

Renounce a hat. This action burns the hat for the renouncing wearer (the caller).

const renounceHatResult = await hatsClient.renounceHat({
    account,
    hatId,
});

Arguments:

{
    account: Account | Address;
    hatId: bigint;
}
  • account - Viem account (Address for JSON-RPC accounts or Account for other types).

  • hatId - hat's ID.

Response:

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

  • transactionHash - transaction's hash.

transferHat

Transfer a hat from one wearer to another.

const transferHatResult = await hatsClient.transferHat({
    account,
    hatId,
    from,
    to,
});

Arguments:

{
    account: Account | Address;
    hatId: bigint;
    from: Address;
    to: Address;
}
  • account - Viem account (Address for JSON-RPC accounts or Account for other types).

  • hatId - hat's ID.

  • from - current wearer address.

  • to - new wearer address.

Response:

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

  • transactionHash - transaction's hash.

makeHatImmutable

Make a hat immutable.

const makeHatImmutableResult = await hatsClient.makeHatImmutable({
    account,
    hatId,
});

Arguments:

{
    account: Account | Address;
    hatId: bigint;
}
  • account - Viem account (Address for JSON-RPC accounts or Account for other types).

  • hatId - hat's ID.

Response:

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

  • transactionHash - transaction's hash.

changeHatDetails

Change a hat's details.

const changeHatDetailsResult = await hatsClient.changeHatDetails({
    account,
    hatId,
    newDetails,
});

Arguments:

{
    account: Account | Address;
    hatId: bigint;
    newDetails: string;
}
  • account - Viem account (Address for JSON-RPC accounts or Account for other types).

  • hatId - hat's ID.

  • newDetails - hat's new details.

Response:

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

  • transactionHash - transaction's hash.

changeHatEligibility

Change a hat's eligibility.

const changeHatEligibilityResult = await hatsClient.changeHatEligibility({
    account,
    hatId,
    newEligibility,
});

Arguments:

{
    account: Account | Address;
    hatId: bigint;
    newEligibility: Address;
}
  • account - Viem account (Address for JSON-RPC accounts or Account for other types).

  • hatId - hat's ID.

  • newEligibility - hat's new eligibility.

Response:

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

  • transactionHash - transaction's hash.

changeHatToggle

Change a hat's toggle.

const changeHatToggleResult = await hatsClient.changeHatToggle({
    account,
    hatId,
    newToggle,
});

Arguments:

{
    account: Account | Address;
    hatId: bigint;
    newToggle: Address;
}
  • account - Viem account (Address for JSON-RPC accounts or Account for other types).

  • hatId - hat's ID.

  • newToggle - hat's new toggle.

Response:

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

  • transactionHash - transaction's hash.

changeHatImageURI

Change a hat's image URI.

const changeHatImageURIResult = await hatsClient.changeHatImageURI({
    account,
    hatId,
    newImageURI,
});

Arguments:

{
    account: Account | Address;
    hatId: bigint;
    newImageURI: string;
}
  • account - Viem account (Address for JSON-RPC accounts or Account for other types).

  • hatId - hat's ID.

  • newImageURI - hat's new image URI.

Response:

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

  • transactionHash - transaction's hash.

changeHatMaxSupply

Change a hat's maximum supply.

const changeHatMaxSupplyResult = await hatsClient.changeHatMaxSupply({
    account,
    hatId,
    newMaxSupply,
});

Arguments:

{
    account: Account | Address;
    hatId: bigint;
    newMaxSupply: number;
}
  • account - Viem account (Address for JSON-RPC accounts or Account for other types).

  • hatId - hat's ID.

  • newMaxSupply - hat's new maximum supply.

Response:

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

  • transactionHash - transaction's hash.

requestLinkTopHatToTree

Request a link from a tophat to a new admin hat.

const requestLinkTopHatToTreeResult = await hatsClient.requestLinkTopHatToTree({
    account,
    topHatDomain,
    requestedAdminHat,
});

Arguments:

{
    account: Account | Address;
    topHatDomain: number;
    requestedAdminHat: bigint;
}
  • account - Viem account (Address for JSON-RPC accounts or Account for other types).

  • topHatDomain - the tree domain of the requesting tree. The tree domain is the first four bytes of the tophat ID.

  • requestedAdminHat - ID of the requested new admin hat.

Response:

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

  • transactionHash - transaction's hash.

approveLinkTopHatToTree

Approve a tophat's linkage request.

const approveLinkTopHatToTreeResult = await hatsClient.approveLinkTopHatToTree({
    account,
    topHatDomain,
    newAdminHat,
    newEligibility,
    newToggle,
    newDetails,
    newImageURI,
});

Arguments:

{
    account: Account | Address;
    topHatDomain: number;
    newAdminHat: bigint;
    newEligibility?: Address;
    newToggle?: Address;
    newDetails?: string;
    newImageURI?: string;
}
  • account - Viem account (Address for JSON-RPC accounts or Account for other types).

  • topHatDomain - the tree domain of the requesting tree. The tree domain is the first four bytes of the tophat ID.

  • newAdminHat - ID of the new admin hat.

  • newEligibility - optional new eligibility for the linked tophat.

  • newToggle - optional new toggle for the linked tophat.

  • newDetails - optional new details for the linked tophat.

  • newImageURI - optional new image URI for the linked tophat.

Response:

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

  • transactionHash - transaction's hash.

unlinkTopHatFromTree

Unlink a tree.

const unlinkTopHatFromTreeResult = await hatsClient.unlinkTopHatFromTree({
    account,
    topHatDomain,
    wearer,
});

Arguments:

{
    account: Account | Address;
    topHatDomain: number;
    wearer: Address;
}
  • account - Viem account (Address for JSON-RPC accounts or Account for other types).

  • topHatDomain - the tree domain. The tree domain is the first four bytes of the tophat ID.

  • wearer - The current wearer of the tophat that is about to be unlinked.

Response:

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

  • transactionHash - transaction's hash.

relinkTopHatWithinTree

Relink a tree within the same global tree that it is already part of.

const relinkTopHatWithinTreeResult = await hatsClient.relinkTopHatWithinTree({
    account,
    topHatDomain,
    newAdminHat,
    newEligibility,
    newToggle,
    newDetails,
    newImageURI,
});

Arguments:

{
    account: Account | Address;
    topHatDomain: number;
    newAdminHat: bigint;
    newEligibility?: Address;
    newToggle?: Address;
    newDetails?: string;
    newImageURI?: string;
}
  • account - Viem account (Address for JSON-RPC accounts or Account for other types).

  • topHatDomain - the tree domain of the relinked tree. The tree domain is the first four bytes of the tophat ID.

  • newAdminHat - ID of the new admin hat.

  • newEligibility - optional new eligibility for the linked tophat.

  • newToggle - optional new toggle for the linked tophat.

  • newDetails - optional new details for the linked tophat.

  • newImageURI - optional new image URI for the linked tophat.

Response:

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

  • transactionHash - transaction's hash.

PreviousOnchain ReadsNextMulticall

Last updated 1 year ago

🖥️