> For the complete documentation index, see [llms.txt](https://ryan-44.gitbook.io/portrait/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://ryan-44.gitbook.io/portrait/portrait-sdk/portrait-class/read/getportraithash.md).

# getPortraitHash()

The `getPortraitHash()` function is a method that can be used to get the hash of a User Portrait or Collective Portrait, if there is one. The hash is a unique identifier for a Portrait. If there is no hash set, the function will return `null`.

### Syntax

```typescript
getPortraitHash(identity: Identity): string
```

### Parameters

* `identity`: A required parameter of type `Identity`. `Identity` is of type:
  * `UserPortraitAddress` – Ethereum address
  * `UserPortraitENSName` – ENS name
  * `CollectivePortraitName`  – Collective Portrait Name (a-z, 0-9, min. 3 chars, max. 64 chars.)

### Return Value

This function returns a string value that represents the IPFS hash of a Portrait, if there is one. If there is no hash set, the function returns `null`.

### Usage

This function is useful in situations where you need to retrieve the unique identifier for a Portrait. The function takes an identity as input, which can be either an Ethereum address, an ENS name, or a Collective Portrait name. The function determines the type of the input identity and retrieves the IPFS hash accordingly.

The function uses the following logic to determine the type of identity and retrieve the portrait hash:

* If the input identity is an Ethereum address, it uses the `getPortraitHash()` method of the `user` object to retrieve the portrait hash.
* If the input identity is a valid ENS name, it resolves the name using the default provider and uses the `getPortraitHash()` method of the `user` object to retrieve the portrait hash.
* If the input identity is a Collective Portrait Name, it uses the `getPortraitHash()` method of the `collective` object to retrieve the hash.
* If the input identity is none of the above types, the function returns `null`.

### Example

```typescript
import { Portrait } from 'portrait-sdk';

const portrait = new Portrait()

const identity = 'vitalik.eth'; // ENS name

const portraitHash = portrait.getPortraitHash(identity);

if (portraitHash) {
  console.log(`The Portrait IPFS hash for ${identity} is ${portraitHash}`);
} else {
  console.log(`${identity} does not have a Portrait`);
}
```

In this example, the `getPortraitHash()` function is used to retrieve the Portrait hash for the given ENS name. If the address has a Portrait, the function logs the IPFS hash to the console. If the address does not have a Portrait, the function logs a message indicating that the address does not have a Portrait.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://ryan-44.gitbook.io/portrait/portrait-sdk/portrait-class/read/getportraithash.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
