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
  • Hat & Tree ID Utils
  • hatIdDecimalToHex
  • hatIdHexToDecimal
  • treeIdDecimalToHex
  • treeIdHexToDecimal
  • treeIdToTopHatId
  • hatIdToTreeId
  • hatIdDecimalToIp
  • hatIdIpToDecimal
  • Constants
  1. For Developers
  2. v1 SDK
  3. Core

Utilities

PreviousClaiming HatsNextSubgraph

Last updated 1 year ago

Hat & Tree ID Utils

Following are utility functions to handle various hat & tree ID formats. More information about hat IDs can be found .

hatIdDecimalToHex

Convert a hat ID from decimal to hex.

import { hatIdDecimalToHex } from "@hatsprotocol/sdk-v1-core";

const hatIdHex = hatIdDecimalToHex(hatId);

Arguments:

hatId: bigint

hatId - Hat ID in decimal format.

Response:

`0x${string}`

Hat ID in a hex format.

hatIdHexToDecimal

Convert a hat ID from hex to decimal.

import { hatIdHexToDecimal } from "@hatsprotocol/sdk-v1-core";

const hatIdDecimal = hatIdHexToDecimal(hatId);

Arguments:

hatId: string

hatId - Hat ID in hex format.

Response:

bigint

Hat ID in a decimal format.

treeIdDecimalToHex

Convert a tree ID from decimal to hex. A tree ID is the first 4 bytes in a hat ID.

import { treeIdDecimalToHex } from "@hatsprotocol/sdk-v1-core";

const treeIdHex = treeIdDecimalToHex(treeId);

Arguments:

treeId: number

treeId - Tree ID in decimal format.

Response:

`0x${string}`

Tree ID in a hex format.

treeIdHexToDecimal

Convert a tree ID from hex to decimal. A tree ID is the first 4 bytes in a hat ID.

import { treeIdHexToDecimal } from "@hatsprotocol/sdk-v1-core";

const treeIdDecimal = treeIdHexToDecimal(treeId);

Arguments:

treeId: string

treeId - Tree ID in hex format.

Response:

number

Tree ID in a decimal format.

treeIdToTopHatId

Convert a tree ID to its top-hat ID. A tree ID is the first 4 bytes in a hat ID.

import { treeIdToTopHatId } from "@hatsprotocol/sdk-v1-core";

const tophatId = treeIdToTopHatId(treeId);

Arguments:

treeId: number

treeId - Tree ID in decimal format.

Response:

bigint

Top-hat ID in decimal format.

hatIdToTreeId

Convert a hat ID to its tree ID. A tree ID is the first 4 bytes in a hat ID.

import { hatIdToTreeId } from "@hatsprotocol/sdk-v1-core";

const treeId = hatIdToTreeId(hatId);

Arguments:

hatId: bigint

hatId - Hat ID in decimal format.

Response:

number

Tree ID of the hat, in a decimal format.

hatIdDecimalToIp

The IP format may be used as a "pretty" hat ID format for presenting.

For example, a hat with a hex ID of: 0x00000001000a0002000000000000000000000000000000000000000000000000 will have an IP format of 1.10.2 - Each level is separated by a dot and presented as a decimal number, excluding zeros.

import { hatIdDecimalToIp } from "@hatsprotocol/sdk-v1-core";

const hatIdIp = hatIdDecimalToIp(hatId);

Arguments:

hatId: bigint

hatId - Hat ID in decimal format.

Response:

string

Hat ID in IP format.

hatIdIpToDecimal

Convert a hat ID from an IP format, to a decimal format.

import { hatIdIpToDecimal } from "@hatsprotocol/sdk-v1-core";

const hatIdDecimal = hatIdIpToDecimal(hatId);

Arguments:

hatId: string

hatId - Hat ID in IP format.

Response:

bigint

Hat ID in decimal format.

Constants

Following are Hats-specific exported constant values.

import {   
  HATS_V1, // Hats-Protocol v1 contract address
  MAX_LEVELS, // Max levels on a Hats tree
  MAX_LEVEL_HATS, // Max amount of hats on each level (excluding level 0)
  ZERO_ID, // The zero Hat ID in hex format 
  FALLBACK_ADDRESS, // The fallback address for eligibility and toggle 
} from "@hatsprotocol/sdk-v1-core";
๐Ÿ–ฅ๏ธ
here