Fetching Hats
getHat
Get a Hat by its ID.
const hat = await hatsSubgraphClient.getHat({
chainId,
hatId,
props,
});
Arguments:
{
chainId: number;
hatId: bigint;
props: HatPropsConfig;
}
chainId
- ID of the chain to fetch from.hatId
- ID of the Hat to fetch.props
- Hat's properties to fetch, including the ones of nested objects. Check the HatPropsConfig type for the available properties and query filters.
Response:
Hat
A Hat object, containing the chosen properties.
Example:
const res = await client.getHat({
chainId: 10, // optimism
hatId: BigInt(
"0x0000000100020001000100000000000000000000000000000000000000000000"
),
props: {
maxSupply: true, // get the maximum amount of wearers for the hat
wearers: { // get the hat's wearers
props: {}, // for each wearer, include only its ID (address)
},
events: { // get the hat's events
props: {
transactionID: true, // for each event, include the transaction ID
},
filters: {
first: 10, // fetch only the latest 10 events
},
},
},
});
getHatsByIds
Get Hats by their IDs.
const hats = await hatsSubgraphClient.getHatsByIds({
chainId,
hatIds,
props,
});
Arguments:
{
chainId: number;
hatIds: bigint[];
props: HatPropsConfig;
}
chainId
- ID of the chain to fetch from.hatIds
- IDs of the Hats to fetch.props
- Hat's properties to fetch, including the ones of nested objects. Check the HatPropsConfig type for the available properties and query filters.
Response:
Hat[]
An array of Hat objects, containing the chosen properties.
Example:
const res = await client.getHatsByIds({
chainId: 10, // optimism
hatIds: [
BigInt("0x0000000100020001000100000000000000000000000000000000000000000000"),
BigInt("0x0000000100020001000000000000000000000000000000000000000000000000"),
],
props: {
wearers: { // get each hat's wearers
props: {
currentHats: { // for each wearer, get its hats
props: {}, // for each hat, include only its ID
},
},
},
},
});
Last updated