Configuration
Complete configuration guide for the Dial SDK.
Client Configuration
Basic Configuration
import { DialClient } from '@dial/sdk';
const dial = new DialClient({
apiKey: 'your-api-key',
walletAddress: '0x...',
network: 'mainnet' // or 'testnet'
});Full Configuration Options
const dial = new DialClient({
// Required
apiKey: string;
// Optional
walletAddress?: string;
network?: 'mainnet' | 'testnet';
sessionToken?: string;
// Advanced options
autoReconnect?: boolean; // default: true
reconnectAttempts?: number; // default: 5
reconnectDelay?: number; // ms, default: 1000
// API configuration
apiUrl?: string; // custom API endpoint
wsUrl?: string; // custom WebSocket endpoint
// Logging
logLevel?: 'debug' | 'info' | 'warn' | 'error'; // default: 'warn'
// Timeouts
requestTimeout?: number; // ms, default: 30000
connectTimeout?: number; // ms, default: 10000
});Environment Variables
Node.js / Next.js
Create a .env.local file:
# Required
DIAL_API_KEY=your_api_key_here
# Optional
DIAL_NETWORK=mainnet
DIAL_LOG_LEVEL=info
# For Next.js (public variables)
NEXT_PUBLIC_DIAL_API_KEY=your_api_key_here
NEXT_PUBLIC_DIAL_NETWORK=mainnetReact / Vite
Create a .env file:
# Vite requires VITE_ prefix
VITE_DIAL_API_KEY=your_api_key_here
VITE_DIAL_NETWORK=mainnet
# Or for Create React App (REACT_APP_ prefix)
REACT_APP_DIAL_API_KEY=your_api_key_here
REACT_APP_DIAL_NETWORK=mainnetNetwork Configuration
Mainnet
const dial = new DialClient({
apiKey: process.env.DIAL_API_KEY,
network: 'mainnet',
apiUrl: 'https://api.dial.wtf',
wsUrl: 'wss://ws.dial.wtf'
});Testnet
const dial = new DialClient({
apiKey: process.env.DIAL_API_KEY,
network: 'testnet',
apiUrl: 'https://api-testnet.dial.wtf',
wsUrl: 'wss://ws-testnet.dial.wtf'
});Local Development
const dial = new DialClient({
apiKey: 'dev-key',
network: 'testnet',
apiUrl: 'http://localhost:3000',
wsUrl: 'ws://localhost:3001',
logLevel: 'debug'
});Connection Settings
WebSocket Configuration
const dial = new DialClient({
apiKey: process.env.DIAL_API_KEY,
autoReconnect: true,
reconnectAttempts: 10,
reconnectDelay: 2000,
heartbeatInterval: 30000 // ping every 30s
});Request Timeouts
const dial = new DialClient({
apiKey: process.env.DIAL_API_KEY,
requestTimeout: 60000, // 60s for API requests
connectTimeout: 15000, // 15s for initial connection
callTimeout: 30000 // 30s for call connection
});Logging Configuration
Set Log Level
const dial = new DialClient({
apiKey: process.env.DIAL_API_KEY,
logLevel: 'debug' // 'debug' | 'info' | 'warn' | 'error'
});
// Or change at runtime
dial.setLogLevel('info');Custom Logger
const dial = new DialClient({
apiKey: process.env.DIAL_API_KEY,
logger: {
debug: (msg, ...args) => console.debug('[DIAL]', msg, ...args),
info: (msg, ...args) => console.info('[DIAL]', msg, ...args),
warn: (msg, ...args) => console.warn('[DIAL]', msg, ...args),
error: (msg, ...args) => console.error('[DIAL]', msg, ...args)
}
});Storage Configuration
Local Storage (Browser)
const dial = new DialClient({
apiKey: process.env.DIAL_API_KEY,
storage: {
type: 'localStorage',
prefix: 'dial_' // key prefix
}
});Session Storage (Browser)
const dial = new DialClient({
apiKey: process.env.DIAL_API_KEY,
storage: {
type: 'sessionStorage'
}
});Custom Storage
const dial = new DialClient({
apiKey: process.env.DIAL_API_KEY,
storage: {
type: 'custom',
get: async (key: string) => {
// Your custom get logic
return value;
},
set: async (key: string, value: any) => {
// Your custom set logic
},
remove: async (key: string) => {
// Your custom remove logic
}
}
});Security Configuration
CORS Settings (Node.js)
const dial = new DialClient({
apiKey: process.env.DIAL_API_KEY,
cors: {
origin: ['https://yourapp.com'],
credentials: true
}
});SSL/TLS Configuration
const dial = new DialClient({
apiKey: process.env.DIAL_API_KEY,
ssl: {
rejectUnauthorized: true, // validate SSL certificates
ca: fs.readFileSync('ca-cert.pem') // custom CA certificate
}
});Performance Optimization
Connection Pooling
const dial = new DialClient({
apiKey: process.env.DIAL_API_KEY,
connectionPool: {
maxConnections: 10,
keepAlive: true,
keepAliveTimeout: 60000
}
});Caching
const dial = new DialClient({
apiKey: process.env.DIAL_API_KEY,
cache: {
enabled: true,
ttl: 300000, // 5 minutes
maxSize: 100 // max cached items
}
});React Configuration
Context Provider
import { DialProvider } from '@dial/sdk/react';
function App() {
return (
<DialProvider
apiKey={process.env.NEXT_PUBLIC_DIAL_API_KEY}
network="mainnet"
logLevel="info"
>
<YourApp />
</DialProvider>
);
}TypeScript Configuration
Type Definitions
import type {
DialClientConfig,
DialClient,
Call,
Message
} from '@dial/sdk';
const config: DialClientConfig = {
apiKey: process.env.DIAL_API_KEY!,
network: 'mainnet'
};
const dial: DialClient = new DialClient(config);Strict Mode
// tsconfig.json
{
"compilerOptions": {
"strict": true,
"esModuleInterop": true,
"skipLibCheck": true
}
}Troubleshooting
Debug Mode
const dial = new DialClient({
apiKey: process.env.DIAL_API_KEY,
logLevel: 'debug',
debug: true // enables additional debug info
});
// Listen to all events for debugging
dial.on('*', (event, data) => {
console.log('Event:', event, data);
});Connection Issues
dial.on('connection:error', (error) => {
console.error('Connection error:', error);
});
dial.on('connection:disconnected', () => {
console.warn('Disconnected, attempting reconnect...');
});
dial.on('connection:reconnected', () => {
console.log('Reconnected successfully');
});Next Steps
Last updated on