Fetching Trees
Last updated
// 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)
},
},
});const trees = await hatsSubgraphClient.getTreesByIds({
chainId,
treeIds,
props,
});{
chainId: number;
treeIds: number[];
props: TreePropsConfig;
}Tree[]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
},
},
});const trees = await hatsSubgraphClient.getTreesPaginated({
chainId,
props,
page,
perPage,
});{
chainId: number;
props: TreePropsConfig;
page: number;
perPage: number;
}Tree[]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
});