> ## Documentation Index
> Fetch the complete documentation index at: https://docs.crossmint.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Retrieve Credentials

> Get access to credentials you care about

Retrieving and effectively presenting credentials is essential for issuers, verifiers, and credential subjects. However, doing so requires interfacing with the blockchain, 3rd party services to fetch NFTs, all while at the same time struggling with unpredictable network issues, and data inconsistency.

Crossmint’s Verifiable Credentials API and SDK simplify credential management, allowing you to seamlessly retrieve and use verifiable credentials where they matter most.

## Verifiable Credential API

Crossmint's Verifiable Credentials API is primarily meant to be used by issuers. It's designed for robust backend operations, enabling seamless, automated credential retrieval without requiring user interaction.

The API integrates with your existing server-side infrastructure, ensuring efficient and scalable credential management. With the API, you can implement complex business logic, providing unparalleled control and customization.

​​You can retrieve a Verifiable Credential via the Crossmint API using different identifiers associated with the credential itself, or the NFT associated with the credential.

* [Get Verifiable Credential by ID](/api-reference/verifiable-credentials/credentials/retrieve-credential-by-id) uses the format: `urn:uuid:<UUID>`
* [Get Verifiable Credential by NFT Locator](/api-reference/verifiable-credentials/credentials/retrieve-credential-by-nft-locator) uses the format: `<chain>:<contractAddress>:<tokenId>`
* [Get Verifiable Credential by NFT ID](/api-reference/verifiable-credentials/credentials/retrieve-credential-by-nft) uses crossmint's internal NFT ID

<Warning>
  There is no access control on credential retrieval. Credential data is public and can be retrieved by anyone. Choose
  to [encrypt your credentials](/minting/verifiable-credentials/integrate/encrypt-credentials) if you need to protect
  your data.
</Warning>

<Warning>
  Credential retrieval via the crossmint API will not work for [delegated
  storage](/minting/verifiable-credentials/integrate/store-credentials).
</Warning>

To retrieve the credential, copy the `retrieveCredential.js` file from below, use your API key, the `credentialId`, and run the file from your terminal.

<CodeGroup>
  ```javascript retrieveCredential.js theme={null}
  const options = {
      method: "GET",
      headers: {
          "X-API-KEY": "YOUR_API_KEY",
      },
  };

  fetch(`https://staging.crossmint.com/api/v1-alpha1/credentials/${credentialId}`, options)
      .then((response) => response.json())
      .then((response) => console.log(JSON.stringify(response)))
      .catch((err) => console.error(err));
  ```

  ```json Response theme={null}
  {
      "unencryptedCredential": {
          "id": "urn:uuid:4c9c41af-8410-4265-9fe4-3674d74e80d9",
          "credentialSubject": {
              "course": "Blockchain 101",
              "grade": "A",
              "id": "did:polygon-amoy:0xbFB0d0F9d49d80062103199c5aD309CE7a808039"
          },
          "validUntil": "2034-02-02",
          "nft": {
              "tokenId": "1",
              "chain": "polygon-amoy",
              "contractAddress": "0x288AAbb7D72A041Ea10719d2d676B65D2E9689F5"
          },
          "issuer": { "id": "did:polygon-amoy:0xB658f974Fe3744A6F9344810BC88e021E31B4d3e" },
          "type": ["VerifiableCredential", "crossmint:5fe6040e-07a1-48bb-97a3-b588a7e927d2:courseCompletionQuickstart"],
          "validFrom": "2024-09-14T13:59:34.918Z",
          "@context": ["https://www.w3.org/2018/credentials/v1"],
          "proof": {
              "verificationMethod": "did:polygon-amoy:0xB658f974Fe3744A6F9344810BC88e021E31B4d3e#evmAddress",
              "created": "2024-09-14T13:59:34.918Z",
              "proofPurpose": "assertionMethod",
              "type": "EthereumEip712Signature2021",
              "proofValue": "0x80587c5e9a801f4eed5bca95c48083277fc2ffe2fc1254f230f1b8c11cab59f63afaaa29bf29007129068243feb0069c46a8e583a64e64ff2517a2e3babd18101b",
              "eip712": {
                  "domain": {
                      "name": "Crossmint",
                      "version": "0.1",
                      "chainId": 4,
                      "verifyingContract": "0xD8393a735e8b7B6E199db9A537cf27C61Aa74954"
                  },
                  "types": {
                      "VerifiableCredential": [
                          { "name": "@context", "type": "string[]" },
                          { "name": "type", "type": "string[]" },
                          { "name": "id", "type": "string" },
                          { "name": "issuer", "type": "Issuer" },
                          { "name": "credentialSubject", "type": "CredentialSubject" },
                          { "name": "validFrom", "type": "string" },
                          { "name": "validUntil", "type": "string" },
                          { "name": "nft", "type": "Nft" }
                      ],
                      "CredentialSubject": [
                          { "name": "id", "type": "string" },
                          { "name": "course", "type": "string" },
                          { "name": "grade", "type": "string" }
                      ],
                      "Issuer": [{ "name": "id", "type": "string" }],
                      "Nft": [
                          { "name": "tokenId", "type": "string" },
                          { "name": "contractAddress", "type": "string" },
                          { "name": "chain", "type": "string" }
                      ]
                  },
                  "primaryType": "VerifiableCredential"
              }
          }
      }
  }
  ```
</CodeGroup>

```shell theme={null}
node retrieveCredential.js
```

## Verifiable Credentials SDK

Crossmint's Verifiable Credentials SDK is primarily meant to be used by verifiers. Using the Verifiable Credentials client-side SDK is advantageous in scenarios where direct interaction with the user's wallet is preferred, directly integrating their credentials with your browser-based application.

* **Wallet Integration**: The Verifiable Credentials SDK is designed to work smoothly with any wallet, providing a streamlined experience for both users and verifiers. This reduces friction and improves the user experience.
* **Efficient Retrieval**: Once the wallet is connected, the SDK can directly interact with it to retrieve credentials. Instead of dealing with multiple API calls, the SDK surfaces credential retrieval capabilities that matter most to verifiers, such as fetching credentials based on specific filter conditions, i.e. type and issuer.
* **User Approvals**: The SDK takes care of prompting the user, when applicable, to approve transactions, such as decryption requests, enhancing security and the user's confidence in the application.

Using the SDK requires a Crossmint developer account and a client-side API key scoped to `credentials.read` and `credentials.decrypt`. Go to the `Developers -> API Keys` tab, click on `New API Key` in the `Client-side keys` section, and select the API key scopes.

<Note>
  You can download the SDK [here](https://www.npmjs.com/package/@crossmint/client-sdk-verifiable-credentials).
</Note>

The SDKs offer functions to easily retrieve and filter NFTs associated with credentials. For example, the `getCredentialNFTs` function fetches all VC NFTs in a wallet and lets you filter by credential type or issuer.

Below, we show how easy it is to retrieve academic credentials from a user's wallet.

<CodeGroup>
  ```typescript index.ts theme={null}
  import * as sdk from '@crossmint/client-sdk-verifiable-credentials';

  sdk.CrossmintAPI.init('YOUR_API_KEY');

  const wallet = "USER_WALLET";
  const filters = {
      // typeId represents an academic credential schema
      type: <typeId>
  };

  const credentials = await sdk.getCredentialNFTs(
      "polygon",
      wallet,
      filters
  );

  console.log('Academic credentials retrieved successfully:', credentials);

  ```

  ```json Response theme={null}
  [
   {
          "contractAddress": "0x5E1ab2aC27f1a0AD28f1b0DDb0E00baF2677725e",
          "chain": "polygon-amoy",
          "nfts": [
              {
                  "chain": "polygon-amoy",
                  "contractAddress": "0x5E1ab2aC27f1a0AD28f1b0DDb0E00baF2677725e",
                  "tokenId": "1"
              }
          ],
          "metadata": {
              "name": "Crossmint Tickets",
              "description": "Access Crossmint Events",
              "image": "ipfs://Qme551yKU6a5Cptsk8hxcMtWwTrKkHArZtTTwFSvu19eFD",
              "credentialMetadata": {
                  "type": [
                      "VerifiableCredential",
                      "userName"
                  ],
                  "encryption": {
                      "type": "crossmint-recoverable"
                  },
                  "credentialsEndpoint": "ipfs://bafybeidmfu6xmdpxddads6nsyxfg6hd5ylj2drrywhzvfi2bbq45owklsa",
                  "issuerDid": "did:polygon:0xd9d8BA9D5956f78E02F4506940f42ac2dAB9DABd"
              }
          }
      },
      {
          "contractAddress": "0x38989746BF435d5f6Dc7C8DdE6038b5a17E62cE2",
          "chain": "polygon-amoy",
          "nfts": [
              {
                  "chain": "polygon-amoy",
                  "contractAddress": "0x38989746BF435d5f6Dc7C8DdE6038b5a17E62cE2",
                  "tokenId": "1"
              }
          ],
          "metadata": {
              "name": "Crossmint Tickets",
              "description": "Access Crossmint Events",
              "image": "ipfs://Qme551yKU6a5Cptsk8hxcMtWwTrKkHArZtTTwFSvu19eFD",
              "credentialMetadata": {
                  "type": [
                      "VerifiableCredential",
                      "userName"
                  ],
                  "encryption": {
                      "type": "crossmint-recoverable"
                  },
                  "credentialsEndpoint": "a",
                  "issuerDid": "did:polygon:0xd9d8BA9D5956f78E02F4506940f42ac2dAB9DABd"
              }
          }
      }
  ]
  ```
</CodeGroup>

Now that the credential is retrieved, it's important to decrypt it and verify it.

<Note>In case the endpoint is called by the issuer the credential will be automatically decrypted.</Note>

<CardGroup cols={2}>
  <Card title="API Reference" icon="terminal" color="#B56710" href="/api-reference/verifiable-credentials/credentials/retrieve-credential-by-id">
    Test any API in seconds directly from the docs.
  </Card>

  <Card title="Talk to an expert" icon="message" iconType="duotone" color="#ADD8E6" href="https://www.crossmint.com/contact/sales">
    Contact our sales team for support.
  </Card>
</CardGroup>
