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:
A funded wallet for paying transaction fees
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
Key Management: Store private keys securely and never expose them in client-side code
Fee Estimation: Always check fee requirements before submitting transactions
Network Selection: Use testnet for development and testing
Error Handling: Implement proper error handling for network and transaction failures
Validation: Validate DID documents and signatures before submitting to the ledger
Gas Limits: Be aware of gas limits when creating complex DID documents
Next Steps
After creating a DID, you can:
Query the DID from the ledger
Troubleshooting
Common Issues
Insufficient Funds: Ensure your wallet has enough CHEQ tokens for transaction fees
Network Connectivity: Verify connection to the cheqd network RPC endpoint
Key Format Errors: Ensure keys are in the correct format (base64 or hex)
Authentication Mismatches: Verify that sign inputs match the DID's authentication methods
Getting Help
If you encounter issues:
Check the cheqd SDK GitHub repository for the latest updates
Review the test files for additional examples
Consult the cheqd documentation for comprehensive guides
Join the cheqd community for support and discussions
Last updated
Was this helpful?