Installation
Complete installation guide for Chaindoc SDKs. Set up Server SDK for backend integration and Embed SDK for frontend signing interface.
Prerequisites
Server SDK Installation
The Server SDK is used for backend integration - document management, signature requests, and blockchain verification.
Step 1: Install Package
npm install @chaindoc_io/server-sdkStep 2: Configure Environment Variables
Create a .env file in your project root:
# Production keys
CHAINDOC_SECRET_KEY=sk_live_xxxxxxxxxxxxx
# Staging/Testing keys
# CHAINDOC_SECRET_KEY=sk_test_xxxxxxxxxxxxx
# Optional: Custom API endpoint
# CHAINDOC_API_URL=https://api.chaindoc.ioStep 3: Initialize SDK
import { Chaindoc } from '@chaindoc_io/server-sdk';
// Basic initialization
export const chaindoc = new Chaindoc({
secretKey: process.env.CHAINDOC_SECRET_KEY!,
});
// Advanced configuration
export const chaindocAdvanced = new Chaindoc({
secretKey: process.env.CHAINDOC_SECRET_KEY!,
baseUrl: process.env.CHAINDOC_API_URL, // Optional
timeout: 60000, // 60 seconds
retry: {
maxRetries: 5,
baseDelayMs: 1000,
maxDelayMs: 10000,
},
headers: {
'X-Custom-Header': 'value',
},
});Step 4: Verify Connection
// Test API connection
const health = await chaindoc.healthCheck();
if (health.status === 'ok' && health.apiKeyValid) {
console.log('✓ Connected to Chaindoc API');
console.log('User ID:', health.userId);
} else {
console.error('✗ Connection failed');
}Embed SDK Installation
The Embed SDK provides a signing interface for web applications. Works with any JavaScript framework.
Step 1: Install Package
npm install @chaindoc_io/embed-sdkStep 2: Configure Environment Variables
# .env.local
REACT_APP_CHAINDOC_PUBLIC_KEY=pk_live_xxxxx
# or for Next.js
NEXT_PUBLIC_CHAINDOC_PUBLIC_KEY=pk_live_xxxxxStep 3: Initialize in Your App
// hooks/useChaindoc.ts
import { useRef, useEffect } from 'react';
import { ChaindocEmbed } from '@chaindoc_io/embed-sdk';
export function useChaindoc() {
const sdkRef = useRef<ChaindocEmbed | null>(null);
useEffect(() => {
sdkRef.current = new ChaindocEmbed({
publicKey: process.env.REACT_APP_CHAINDOC_PUBLIC_KEY!,
environment: 'production',
});
return () => {
sdkRef.current?.destroy();
};
}, []);
return sdkRef.current;
}Framework-Specific Setup
Next.js (App Router)
'use client';
import { createContext, useContext, useEffect, useRef } from 'react';
import { ChaindocEmbed } from '@chaindoc_io/embed-sdk';
const ChaindocContext = createContext<ChaindocEmbed | null>(null);
export function ChaindocProvider({ children }: { children: React.ReactNode }) {
const sdkRef = useRef<ChaindocEmbed | null>(null);
useEffect(() => {
if (!sdkRef.current) {
sdkRef.current = new ChaindocEmbed({
publicKey: process.env.NEXT_PUBLIC_CHAINDOC_PUBLIC_KEY!,
});
}
return () => {
sdkRef.current?.destroy();
};
}, []);
return (
<ChaindocContext.Provider value={sdkRef.current}>
{children}
</ChaindocContext.Provider>
);
}
export const useChaindoc = () => useContext(ChaindocContext);Next.js (Pages Router)
import type { AppProps } from 'next/app';
import { useEffect, useRef } from 'react';
import { ChaindocEmbed } from '@chaindoc_io/embed-sdk';
export default function App({ Component, pageProps }: AppProps) {
const sdkRef = useRef<ChaindocEmbed | null>(null);
useEffect(() => {
sdkRef.current = new ChaindocEmbed({
publicKey: process.env.NEXT_PUBLIC_CHAINDOC_PUBLIC_KEY!,
});
return () => {
sdkRef.current?.destroy();
};
}, []);
return <Component {...pageProps} />;
}Nuxt 3
import { ChaindocEmbed } from '@chaindoc_io/embed-sdk';
export default defineNuxtPlugin(() => {
const config = useRuntimeConfig();
const chaindoc = new ChaindocEmbed({
publicKey: config.public.chaindocPublicKey,
});
return {
provide: {
chaindoc,
},
};
});Angular
import { Injectable, OnDestroy } from '@angular/core';
import { ChaindocEmbed } from '@chaindoc_io/embed-sdk';
import { environment } from '../environments/environment';
@Injectable({
providedIn: 'root'
})
export class ChaindocService implements OnDestroy {
private sdk: ChaindocEmbed;
constructor() {
this.sdk = new ChaindocEmbed({
publicKey: environment.chaindocPublicKey,
});
}
getSdk(): ChaindocEmbed {
return this.sdk;
}
ngOnDestroy(): void {
this.sdk.destroy();
}
}TypeScript Configuration
Both SDKs include full TypeScript definitions. No additional @types packages needed.
{
"compilerOptions": {
"target": "ES2020",
"module": "ESNext",
"moduleResolution": "bundler",
"lib": ["ES2020", "DOM", "DOM.Iterable"],
"types": ["node"],
"strict": true,
"esModuleInterop": true,
"skipLibCheck": true
}
}Environment Configuration
Development Environment
// Use test keys for development
const chaindoc = new Chaindoc({
secretKey: 'sk_test_xxxxx',
baseUrl: 'https://api.chaindoc.io',
});
const embed = new ChaindocEmbed({
publicKey: 'pk_test_xxxxx',
environment: 'staging',
debug: true, // Enable detailed logs
});Production Environment
// Use live keys for production
const chaindoc = new Chaindoc({
secretKey: process.env.CHAINDOC_SECRET_KEY!, // sk_live_xxxxx
});
const embed = new ChaindocEmbed({
publicKey: process.env.NEXT_PUBLIC_CHAINDOC_PUBLIC_KEY!, // pk_live_xxxxx
environment: 'production',
});Verification
Test your installation with these verification steps:
1Check SDK Versionconsole.log(ChaindocEmbed.version); // Should output version number
2Verify API ConnectionTest health check endpoint to confirm API keys are valid
3Test File UploadUpload a small test file to verify media endpoints work
4Initialize Embed SDKInitialize SDK and check browser console for any errors
Troubleshooting
Module Not Found Error
# Clear cache and reinstall
rm -rf node_modules package-lock.json
npm install
# For yarn
rm -rf node_modules yarn.lock
yarn installTypeScript Errors
If you see TypeScript errors, ensure your tsconfig.json has correct module resolution settings and Node.js types are installed.
npm install --save-dev @types/nodeAPI Key Issues
Next Steps
- Review Quick Start guide for your first integration
- Check API Documentation for endpoint reference
- Explore SDKs documentation for advanced features
- Set up Webhooks for real-time notifications
- Join developer community on GitHub for support