> For the complete documentation index, see [llms.txt](https://docs.cheqd.io/product/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.cheqd.io/product/sdk/credo/dids/create-did.md).

# Create a DID

This tutorial shows you how to create a **cheqd DID** using your configured **Credo Agent**, and how to publish the associated **DID Document** to the **cheqd ledger**.

## ⚠️ Prerequisites

Before you begin:

* ✅ Ensure your **Credo agent** is correctly configured with the `@credo-ts/cheqd` module
* ✅ You’ve set up a `cosmosPayerSeed` for publishing to the cheqd network
* ✅ You're connected to the correct network (`mainnet` or `testnet`)

## Method Overview

Credo supports two approaches to creating a DID:

#### Option 1 – Manually construct a full DID Document

Use when you want full control over the DID structure and already have key(s) in your wallet.

#### Option 2 – Auto-generate the DID Document

Use when you want Credo to create the DID Document from a key you specify in `secret`.

## Create DID

### **Parameters**[**​**](https://credo.js.org/guides/tutorials/cheqd#parameters)

1. `method`\*: `cheqd`
2. `secret`
3. `options`\*
4. `didDocument`

### Option 1: Create a DID from a full DID Document

1. First, generate a key pair:

```ts
const key = await agent.wallet.createKey({
  keyType: KeyType.Ed25519,
})

const ed25519PublicKeyBase58 = key.publicKeyBase58
```

2. Use that key to construct and register the DID Document:

```ts
import { DidDocument } from '@credo-ts/core'

await agent.dids.create<CheqdDidCreateOptions>({
  method: 'cheqd',
  secret: {}, // No secret needed if key is already in wallet
  options: {
    network: 'testnet',
  },
  didDocument: new DidDocument({
    id: 'did:cheqd:testnet:92874297-d824-40ea-8ae5-364a1ec9237d',
    controller: ['did:cheqd:testnet:92874297-d824-40ea-8ae5-364a1ec9237d'],
    verificationMethod: [
      {
        id: 'did:cheqd:testnet:92874297-d824-40ea-8ae5-364a1ec9237d#key-1',
        type: 'Ed25519VerificationKey2018',
        controller: 'did:cheqd:testnet:92874297-d824-40ea-8ae5-364a1ec9237d',
        publicKeyBase58: ed25519PublicKeyBase58,
      },
    ],
    authentication: [
      'did:cheqd:testnet:92874297-d824-40ea-8ae5-364a1ec9237d#key-1',
    ],
  }),
})
```

> 📝 Make sure the `publicKeyBase58` matches the key in your wallet.\
> The DID will be written to the `testnet` unless you specify `"mainnet"` in `options.network`.

### **Option 2**[**​**](https://credo.js.org/guides/tutorials/cheqd#option-2)

If you don’t want to manually build a DID Document, you can let Credo handle it based on your input key type and ID.

```ts
await agent.dids.create({
  method: 'cheqd',
  secret: {
    verificationMethod: {
      id: 'key-1', // Logical key name
      type: 'Ed25519VerificationKey2020', // Or another supported type
    },
  },
  options: {
    network: 'testnet',
    methodSpecificIdAlgo: 'uuid', // Optional: 'uuid' (default) or 'base58'
  },
})
```

> 🔐 Credo will generate the DID Document using the key referenced in `secret` and publish it to the network.

## What’s Next?

Now that your DID is live on the cheqd network, try:

<table data-card-size="large" data-view="cards"><thead><tr><th></th><th></th></tr></thead><tbody><tr><td><mark style="color:blue;"><strong>Create DID-Linked Resource</strong></mark></td><td>Associate DID-Linked Resources to your DID using Credo.</td></tr><tr><td><mark style="color:blue;"><strong>Issue Verifiable Credentials</strong></mark></td><td>Issue Credentials using your cheqd DID using Credo.</td></tr></tbody></table>


---

# 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://docs.cheqd.io/product/sdk/credo/dids/create-did.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.
