Create a DID-Linked Resource
This guide demonstrates how to create DID-Linked Resources using the cheqd SDK, with examples based on the SDK's test suite and common usage patterns. DID-Linked Resources allow you to associate data like schemas, credential definitions, status lists, and other artifacts with DIDs.
Prerequisites
Before creating DID-Linked Resources, ensure you have:
Created a DID to link resources to
A funded wallet for paying transaction fees
Access to a cheqd network (testnet or mainnet)
The private keys associated with the DID's authentication methods
SDK Initialization
First, initialize the SDK with the required modules:
Basic SDK Setup
import { createCheqdSDK, ResourceModule, 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: [ResourceModule as unknown as AbstractCheqdSDKModule],
rpcUrl: 'https://rpc.cheqd.network', // testnet
network: CheqdNetwork.Testnet,
wallet: wallet
});Advanced SDK Setup with Multiple Modules
Resource Creation Examples
Example 1: Basic JSON Schema Resource
This example creates a JSON Schema as a DID-Linked Resource:
Example 2: Credential Definition Resource
This example creates an AnonCreds Credential Definition resource:
Example 3: Bitstring Status List Resource
This example creates a Bitstring Status List for credential status management:
Example 4: Image/Logo Resource
This example creates an image resource (e.g., organization logo):
Example 5: Custom Metadata Resource
This example creates a resource with custom metadata and multiple alternative URIs:
Example 6: Resource with Custom Version ID
This example creates a resource with a custom version identifier for tracking:
Complete Working Example
Here's a complete example you can run:
Error Handling and Validation
Resource Payload Validation
Before submitting to the ledger, validate your resource payload:
Content Size Limits
Check resource content size limits:
Fee Calculation by Media Type
The SDK provides specific fee calculation methods based on the resource media type:
DID Authorization Check
Verify that the signing keys have authority over the collection DID:
Best Practices
Resource Design
Meaningful Names: Use descriptive names that clearly identify the resource
Version Management: Use semantic versioning for resource versions
Media Types: Use appropriate MIME types for your content
Resource Types: Use standardized resource type names when possible
Size Optimization: Keep resources reasonably sized for network efficiency
Security Considerations
Key Management: Secure storage of private keys used for signing
Content Validation: Validate content before creating resources
Access Control: Ensure only authorized entities can create resources for a DID
Backup Strategies: Maintain backups of critical resources
Version Control: Track resource changes and maintain audit trails
Performance Optimization
Batch Operations: Group related resource creations when possible
Content Compression: Compress large text-based resources
Caching: Implement caching strategies for frequently accessed resources
CDN Integration: Use Content Delivery Networks for global distribution
Alternative URIs: Provide multiple access methods through
alsoKnownAs
Common Resource Types
Standard Resource Types
JSONSchema- JSON Schema definitionsCL_SCHEMA- AnonCreds credential definitionsBitstringStatusList- W3C Bitstring Status List for credential statusImage- Images, logos, and graphicsDocumentation- API docs, specifications, guidesEntityMetadata- Organization or entity informationTermsOfService- Legal terms and conditionsPrivacyPolicy- Privacy policies and data handling terms
Custom Resource Types
You can create custom resource types for specific use cases:
Next Steps
After creating resources, you can:
Implement resource versioning strategies
Troubleshooting
Common Issues
DID Not Found: Verify the collection DID exists and is active
Insufficient Permissions: Ensure signing keys have authority over the collection DID
Resource Too Large: Check resource size limits and compress if needed
Invalid Media Type: Use proper MIME types for your content
Network Errors: Verify connection to the cheqd network
Fee Calculation Errors: Ensure wallet has sufficient funds
Getting Help
If you encounter issues:
Check the cheqd SDK GitHub repository for updates
Review the test files for examples
Consult the cheqd documentation for comprehensive guides
Join the cheqd Community Discord for support
Last updated
Was this helpful?