Create a DID

This guide demonstrates how to create Decentralized Identifiers (DIDs) using the cheqd SDK, with examples based on the SDK's test suite and common usage patterns.

Prerequisites

Before creating DIDs, ensure you have:

  1. A funded wallet for paying transaction fees

  2. Access to a cheqd network (testnet or mainnet)

SDK Initialization

First, initialize the SDK with the required modules:

Basic SDK Setup

import { createCheqdSDK, DIDModule, CheqdNetwork, AbstractCheqdSDKModule } from '@cheqd/sdk';
import { DirectSecp256k1HdWallet } from '@cosmjs/proto-signing';

// Initialize wallet from mnemonic
const wallet = await DirectSecp256k1HdWallet.fromMnemonic(
  'your twelve word mnemonic phrase goes here like this example', 
  { prefix: 'cheqd' }
);

// Create SDK instance
const sdk = await createCheqdSDK({
  modules: [DIDModule as unknown as AbstractCheqdSDKModule],
  rpcUrl: 'https://rpc.cheqd.network', // testnet
  network: CheqdNetwork.Testnet,
  wallet: wallet
});

Advanced SDK Setup with Custom Configuration

DID Creation Examples

Example 1: Basic DID Creation with Ed25519VerificationKey2020

This example creates a DID with a single Ed25519 key using the 2020 verification method:

Example 2: DID Creation with JsonWebKey2020

This example creates a DID using the JsonWebKey2020 verification method:

Example 3: DID Creation with UUID Method Specific Identifier

This example creates a DID using UUID as the method-specific identifier instead of Base58:

Example 4: Multi-Key DID Creation

This example creates a DID with multiple verification methods:

Example 5: DID Creation with Services

This example creates a DID with service endpoints:

Example 6: DID Creation with Custom Version ID

This example creates a DID with a custom version identifier:

Complete Working Example

Here's a complete example you can run:

Error Handling and Validation

Client-side Validation

Before submitting to the ledger, you can validate your DID payload:

Authentication Validation

Validate that your sign inputs match the DID document authentication requirements:

Best Practices

  1. Key Management: Store private keys securely and never expose them in client-side code

  2. Fee Estimation: Always check fee requirements before submitting transactions

  3. Network Selection: Use testnet for development and testing

  4. Error Handling: Implement proper error handling for network and transaction failures

  5. Validation: Validate DID documents and signatures before submitting to the ledger

  6. Gas Limits: Be aware of gas limits when creating complex DID documents

Next Steps

After creating a DID, you can:

Troubleshooting

Common Issues

  1. Insufficient Funds: Ensure your wallet has enough CHEQ tokens for transaction fees

  2. Network Connectivity: Verify connection to the cheqd network RPC endpoint

  3. Key Format Errors: Ensure keys are in the correct format (base64 or hex)

  4. Authentication Mismatches: Verify that sign inputs match the DID's authentication methods

Getting Help

If you encounter issues:

Last updated

Was this helpful?