API Operations

Features & Benefits

The Canton Node SDK provides a seamless, type-safe experience for developers building applications on the Canton blockchain.

Type Safety & Developer Experience

Full TypeScript Support

Every API operation is fully typed with comprehensive TypeScript definitions:

// TypeScript knows exactly what parameters are required
const user = await client.createUser({
  user: {
    id: 'alice',
    primaryParty: 'Alice::1220',
    isDeactivated: false,
    identityProviderId: 'default',
  },
  rights: [{ kind: { CanActAs: { party: 'Alice::1220' } } }],
});
// TypeScript knows the exact structure of the response
console.log(user.user.id); // ✅ Type-safe

Authentication & Security

OAuth2 Authentication

Built-in OAuth2 support with automatic token management:

// Authentication is handled automatically
const client = new LedgerJsonApiClient(config);
// Tokens are managed behind the scenes
const user = await client.getAuthenticatedUser({
  identityProviderId: 'default',
});

Environment-Based Configuration

Secure configuration management with environment variables:

// Switch between environments easily
const devConfig = EnvLoader.getConfig('LEDGER_JSON_API', {
  network: 'devnet',
  provider: '5n',
});

const prodConfig = EnvLoader.getConfig('LEDGER_JSON_API', {
  network: 'mainnet',
  provider: '5n',
});

Production-Ready Infrastructure

Comprehensive Error Handling

Robust error management with custom error types:

try {
  const result = await client.uploadDarFile({ darFile: buffer });
} catch (error) {
  if (error instanceof ConfigurationError) {
    console.error('Check your environment configuration');
  } else if (error instanceof AuthenticationError) {
    console.error('Authentication failed - check your credentials');
  }
}

Configurable Logging

Flexible logging system with file and console output options.

Complete API Coverage

Ledger JSON API v2

Full implementation of Canton’s Ledger JSON API:

Package Management

// Upload DAR files
await client.uploadDarFile({ darFile: buffer });

// List available packages
const packages = await client.listPackages();

// Check package status
const status = await client.getPackageStatus({ packageId: 'my-package' });

Transaction Operations

// Get transaction updates
const updates = await client.getUpdates({
  beginExclusive: 1000,
  endInclusive: 2000,
  updateFormat: { includeTransactions: { eventFormat: { verbose: true } } },
});

// Query specific transactions
const transaction = await client.getTransactionById({
  transactionId: 'tx-123',
});

Event Handling

// Get events for a specific contract
const events = await client.getEventsByContractId({
  contractId: 'contract-123',
  eventFormat: { verbose: true },
});

User Management

// Create users with specific rights
await client.createUser({
  user: { id: 'alice', primaryParty: 'Alice::1220' },
  rights: [{ kind: { CanActAs: { party: 'Alice::1220' } } }],
});

// Manage user permissions
await client.grantUserRights({
  userId: 'alice',
  rights: [{ kind: { CanReadAs: { party: 'Bob::1221' } } }],
});

Performance & Reliability

Developer Tools

Direct Client Instantiation

Simple and direct client creation:

// Create clients directly
const client = new LedgerJsonApiClient(config);

Use Cases

The Canton Node SDK is perfect for:

Migration Benefits

If you’re currently using raw HTTP calls or other Canton clients:


Ready to get started? Check out the Getting Started Guide for installation and basic usage examples.