Network Overview
Cardano DevKit supports seamless switching between networks for different stages of development.
Supported Networks
| Network | Type | Block Time | Use Case |
|---|---|---|---|
| LocalDevnet | Local | 100ms-1s | Development, testing |
| Preview | Testnet | ~20s | Early testing |
| Preprod | Testnet | ~20s | Pre-production staging |
| Mainnet | Production | ~20s | Live deployment |
Development Workflow
Local Devnet → Preview/Preprod → Mainnet
↓ ↓ ↓
Rapid Testnet Production
Iteration Testing Deployment
Recommended Flow
- Local Devnet: Rapid development with 200ms blocks
- Preprod: Test with realistic network conditions
- Mainnet: Deploy with confidence
Quick Network Switching
Using Helper Methods
import { createDevKit } from 'cardano-devkit';
const devKit = createDevKit({ network: 'LocalDevnet' });
await devKit.init();
// Switch to testnet
await devKit.usePreprod();
// Switch to preview
await devKit.usePreview();
// Switch to mainnet (requires confirmation)
await devKit.useMainnet({ confirmMainnet: true });
// Back to local
await devKit.useLocalDevnet();
Using switchNetwork
// Generic network switch
await devKit.switchNetwork('Preview');
await devKit.switchNetwork('Preprod');
// Mainnet requires explicit options
await devKit.switchNetwork('Mainnet', { confirmMainnet: true });
Environment Detection
// Check current environment
const env = devKit.getEnvironment();
console.log(env); // 'development' | 'testnet' | 'production'
// Safety checks
if (devKit.isSafeForTesting()) {
// OK to use test operations
}
if (devKit.isLocalDevnet()) {
// Local devnet specific features
await devKit.topup(address);
}
if (devKit.isTestnet()) {
// Testnet features
}
Network Configuration
Default Configuration
const devKit = createDevKit({
network: 'Preprod' // Default
});
Custom Provider
const devKit = createDevKit({
network: 'Preprod',
provider: {
type: 'blockfrost',
apiKey: process.env.BLOCKFROST_KEY
}
});
Local Devnet with Custom Port
const devKit = createDevKit({
network: 'LocalDevnet',
provider: {
type: 'koios',
baseUrl: 'http://localhost:9090/api/v1'
},
localDevnetConfig: {
blockTimeMs: 200
}
});
Provider Types
| Provider | Networks | Features |
|---|---|---|
| Blockfrost | All | Hosted, reliable, rate-limited |
| Koios | All | Self-hostable, no rate limits |
| Maestro | Preprod, Mainnet | High performance |
| Custom | Any | Your own provider |
Setting Provider per Network
// Different providers for different networks
const configs = {
development: {
network: 'LocalDevnet',
provider: { type: 'koios', baseUrl: 'http://localhost:10080/api/v1' }
},
staging: {
network: 'Preprod',
provider: { type: 'blockfrost', apiKey: process.env.BLOCKFROST_PREPROD }
},
production: {
network: 'Mainnet',
provider: { type: 'blockfrost', apiKey: process.env.BLOCKFROST_MAINNET }
}
};
const env = process.env.NODE_ENV || 'development';
const devKit = createDevKit(configs[env]);
Mainnet Safety
Switching to mainnet requires explicit confirmation to prevent accidents:
// ❌ This will throw an error
await devKit.useMainnet();
// Error: Mainnet switch requires explicit confirmation
// ✅ Correct way
await devKit.useMainnet({
confirmMainnet: true,
checkWalletBalance: true, // Optional: warn if wallet has funds
requireReadOnlyFirst: true // Optional: connect read-only first
});
Mainnet Checklist
Before switching to mainnet, ensure:
- All tests pass on Preprod
- Smart contracts are audited
- Wallet backup is secure
- Transaction fees are acceptable
- Error handling is robust
Network-Specific Features
| Feature | LocalDevnet | Preview | Preprod | Mainnet |
|---|---|---|---|---|
| Faucet | Built-in | External | External | N/A |
| Fast blocks | ✅ | ❌ | ❌ | ❌ |
| Reset state | ✅ | ❌ | ❌ | ❌ |
| Free ADA | ✅ | ✅ | ✅ | ❌ |
| Real value | ❌ | ❌ | ❌ | ✅ |
Network Magic Numbers
For advanced use cases:
| Network | Magic ID |
|---|---|
| Mainnet | 764824073 |
| Preprod | 1 |
| Preview | 2 |
| LocalDevnet | 42 (custom) |