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
  • getTree
  • getTreesByIds
  • getTreesPaginated
  1. For Developers
  2. v1 SDK
  3. Subgraph

Fetching Trees

PreviousFetching WearersNextMisc

Last updated 1 year ago

getTree

Get a Tree by its ID.

const tree = await hatsSubgraphClient.getTree({
    chainId,
    treeId,
    props,
});

Arguments:

{
    chainId: number;
    treeId: number;
    props: TreePropsConfig;
}
  • chainId - ID of the chain to fetch from.

  • treeId - ID of the Tree to fetch (Tree's top-hat domain - first 4 bytes of the top-hat ID).

  • props - Tree's properties to fetch, including the ones of nested objects. Check the type for the available properties and query filters.

Response:

Tree

Example:

// get a tree's top-hat
const res = await client.getTree({
  chainId: 10, // optimism
  treeId: 1, 
  props: {
    hats: { // get the tree's hats
      props: {}, // for each hat, include only its ID
      filters: { first: 1 }, // fetch only the first hat (the top-hat)
    },
  },
});

getTreesByIds

Get Trees by their IDs.

const trees = await hatsSubgraphClient.getTreesByIds({
    chainId,
    treeIds,
    props,
});

Arguments:

{
    chainId: number;
    treeIds: number[];
    props: TreePropsConfig;
}
  • chainId - ID of the chain to fetch from.

  • treeIds - IDs of the Trees to fetch (Tree's top-hat domain - first 4 bytes of the top-hat ID).

Response:

Tree[]

Example:

const res = await client.getTreesByIds({
  chainId: 10, // optimism
  treeIds: [1, 2],
  props: {
    hats: { // for each tree, fetch its hats
      props: {
        status: true, // for each hat, include its status (active/inactive)
      },
      filters: { first: 200 }, // fetch only the first 200 hats
    },
  },
});

getTreesPaginated

Paginate over Trees.

const trees = await hatsSubgraphClient.getTreesPaginated({
    chainId,
    props,
    page,
    perPage,
});

Arguments:

{
    chainId: number;
    props: TreePropsConfig;
    page: number;
    perPage: number;
}
  • chainId - ID of the chain to fetch from.

  • page - Number of page to fetch.

  • perPage - Number of Trees to fetch in each page.

Response:

Tree[]

Example:

const res = await client.getTreesPaginated({
  chainId: 10, // optimism
  props: {
    hats: { // for each tree, get its hats
      props: {}, // for each hat, include only its ID 
      filters: { first: 1 }, // fetch only the first hat of every tree (the top-hat)
    },
  },
  page: 3, // get the third page
  perPage: 10, // each page contains 10 trees
});

A , containing the chosen properties.

props - Tree's properties to fetch, including the ones of nested objects. Check the type for the available properties and query filters.

An array of , containing the chosen properties.

props - Tree's properties to fetch, including the ones of nested objects. Check the type for the available properties and query filters.

An array of , containing the chosen properties.

๐Ÿ–ฅ๏ธ
TreePropsConfig
Tree object
TreePropsConfig
Tree objects
TreePropsConfig
Tree objects