> For the complete documentation index, see [llms.txt](https://docs.hatsprotocol.xyz/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.hatsprotocol.xyz/for-developers/v1-sdk/subgraph/fetching-hats.md).

# Fetching Hats

### <mark style="color:purple;">getHat</mark>

Get a Hat by its ID.

```typescript
const hat = await hatsSubgraphClient.getHat({
    chainId,
    hatId,
    props,
});
```

***Arguments***:

```typescript
{
    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](/for-developers/v1-sdk/subgraph/types.md#hatpropsconfig) type for the available properties and query filters.

***Response***:

```typescript
Hat
```

A [Hat object](/for-developers/v1-sdk/subgraph/types.md#hat), containing the chosen properties.

***Example***:

```typescript
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
      },
    },
  },
});
```

### <mark style="color:purple;">getHatsByIds</mark>

Get Hats by their IDs.

<pre class="language-typescript"><code class="lang-typescript">const hats = await hatsSubgraphClient.getHatsByIds({
<strong>    chainId,
</strong>    hatIds,
    props,
});
</code></pre>

***Arguments***:

```typescript
{
    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](/for-developers/v1-sdk/subgraph/types.md#hatpropsconfig) type for the available properties and query filters.

***Response***:

```typescript
Hat[]
```

An array of [Hat objects](/for-developers/v1-sdk/subgraph/types.md#hat), containing the chosen properties.

***Example***:

```typescript
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
        },
      },
    },
  },
});
```
