NOTE: this is still a draft, so it's subject to changes. This alert will be removed as soon as final version will be available

πŸ“’@hsuite/smart-ledgers - Multi-Ledger Management

🌐 Comprehensive multi-blockchain ledger management with unified API interface

Advanced ledger management system providing unified access to multiple blockchain networks including Hedera Hashgraph, Ripple/XRP Ledger, and other supported networks with standardized operations and error handling.


Table of Contents


Quick Start

Installation

npm install @hsuite/smart-ledgers

Basic Setup

Basic Usage


Architecture

Core Multi-Ledger Framework

🌐 Unified Blockchain Interface

  • Multi-Ledger Support - Hedera Hashgraph and Ripple (XRP) networks with unified API

  • Service-Oriented Architecture - Specialized services for tokens, accounts, storage, and transactions

  • Adapter Pattern - Extensible design for adding new blockchain networks

  • Plugin System - Abstract base class for building blockchain-specific operations

πŸ”§ Specialized Service Layer

  • Account Management - Account creation, updates, balance queries, and lifecycle management

  • Token Operations - Complete fungible and non-fungible token support with transfers

  • Transaction Processing - Full transaction lifecycle with query, execute, and validation

  • Cryptographic Operations - Key management, signing, verification, and secure operations

πŸ›οΈ Network & Configuration Management

  • Network Abstraction - Seamless switching between mainnet and testnet environments

  • Configuration Management - Centralized configuration with validation and defaults

  • Connection Pooling - Efficient network connection management and retry mechanisms

  • Type Safety - Comprehensive TypeScript interfaces and runtime validation

πŸ“Š Monitoring & Integration

  • Real-time Status - Network status monitoring and connection health checks

  • NestJS Integration - Full dependency injection and modular design patterns

  • Documentation - JSDoc documentation with Compodoc support

  • Error Handling - Comprehensive error handling with detailed error types

Service Architecture

Module Structure


API Reference

SmartLedgersModule

Static Methods

forRootAsync(options: SmartLedgersAsyncOptions): DynamicModule

  • Purpose: Configure module with async dependencies and multiple ledgers

  • Parameters: Configuration options with ledger credentials and network settings

  • Features: Multi-blockchain support, connection pooling, retry mechanisms

  • Returns: Configured dynamic module with all adapters and services

SmartLedgersService

Core Methods

getAdapter(chain: ChainType): ILedgerAdapter

  • Purpose: Get specific blockchain adapter for operations

  • Parameters: Chain type (HASHGRAPH, RIPPLE)

  • Returns: Configured adapter with full service access

  • Usage: Primary method for accessing blockchain-specific functionality

initializeLedger(type: ChainType, config: ILedgerConfig): Promise<void>

  • Purpose: Initialize ledger with configuration

  • Parameters: Chain type and configuration object

  • Process: Validates configuration, establishes connections, initializes services

  • Error Handling: Throws configuration or connection errors

getTransaction(type: ChainType, transactionId: string): Promise<any>

  • Purpose: Retrieve transaction details from any supported blockchain

  • Parameters: Chain type and transaction identifier

  • Returns: Transaction details with status and metadata

  • Cross-chain: Unified interface across different blockchain formats

getNetworkStatus(type: ChainType): Promise<any>

  • Purpose: Get current network status and connection health

  • Parameters: Chain type to check

  • Returns: Network status with connection details and health metrics

  • Monitoring: Real-time network monitoring capabilities

ILedgerAdapter

Core Interface

getLedger(): ILedger

  • Purpose: Get the main ledger interface for operations

  • Returns: Configured ledger with all specialized services

  • Usage: Gateway to all blockchain operations

initialize(config: ILedgerConfig): Promise<void>

  • Purpose: Initialize adapter with configuration

  • Parameters: Complete ledger configuration object

  • Process: Validates config, establishes connections, prepares services

getType(): ChainType

  • Purpose: Get the blockchain type this adapter handles

  • Returns: Chain type enumeration value

  • Usage: Runtime type checking and routing

Specialized Services

IAccounts - Account Management

create(initialBalance: number, publicKey?: string): Promise<AccountResult>

  • Purpose: Create new blockchain account

  • Parameters: Initial balance and optional public key

  • Returns: Account creation result with account ID and transaction details

  • Blockchain-specific: Handles different account creation patterns

getInfo(accountId: string): Promise<AccountInfo>

  • Purpose: Retrieve comprehensive account information

  • Parameters: Account identifier

  • Returns: Account details including balance, keys, and properties

  • Cross-chain: Unified account information format

getBalance(accountId: string): Promise<BalanceInfo>

  • Purpose: Get account balance for native and token assets

  • Parameters: Account identifier

  • Returns: Balance information with native and token breakdowns

  • Multi-asset: Supports multiple token types per account

IFungibleToken - Token Operations

create(tokenConfig: TokenConfig): Promise<TokenResult>

  • Purpose: Create new fungible token

  • Parameters: Complete token configuration with supply, keys, properties

  • Returns: Token creation result with token ID and metadata

  • Features: Configurable supply, freeze, wipe, and admin keys

mint(tokenId: string, amount: number, supplyKey: string): Promise<MintResult>

  • Purpose: Mint additional tokens to treasury

  • Parameters: Token ID, amount to mint, supply key for authorization

  • Returns: Mint transaction result with new total supply

  • Authorization: Requires valid supply key signature

transfer(fromAccountId: string, toAccountId: string, tokenId: string, amount: number, senderPrivateKey: string): Promise<TransferResult>

  • Purpose: Transfer tokens between accounts

  • Parameters: From/to accounts, token ID, amount, sender's private key

  • Returns: Transfer transaction result with updated balances

  • Validation: Validates balances and authorization before transfer

INonFungibleToken - NFT Operations

mint(tokenId: string, metadata: string, supplyKey: string): Promise<NFTMintResult>

  • Purpose: Mint new NFT with metadata

  • Parameters: Token ID, metadata URI/hash, supply key for authorization

  • Returns: NFT mint result with serial number and transaction details

  • Metadata: Supports IPFS hashes and URI formats

transfer(tokenId: string, serialNumber: number, fromAccountId: string, toAccountId: string, senderPrivateKey: string): Promise<NFTTransferResult>

  • Purpose: Transfer specific NFT between accounts

  • Parameters: Token ID, serial number, from/to accounts, sender key

  • Returns: Transfer result with ownership confirmation

  • Ownership: Validates current ownership before transfer

burn(tokenId: string, serialNumber: number, supplyKey: string): Promise<BurnResult>

  • Purpose: Permanently burn NFT from circulation

  • Parameters: Token ID, serial number, supply key for authorization

  • Returns: Burn transaction result with confirmation

  • Permanent: Irreversible operation reducing total supply

ITransactions - Transaction Management

getTransaction(transactionId: string): Promise<TransactionDetails>

  • Purpose: Get detailed transaction information

  • Parameters: Transaction identifier

  • Returns: Complete transaction details with status and effects

  • History: Access to historical transaction data

executeOfflineTransaction(transaction: any): Promise<ExecutionResult>

  • Purpose: Execute pre-signed transaction

  • Parameters: Serialized transaction object

  • Returns: Execution result with confirmation

  • Offline: Supports offline transaction preparation

ILedgerCryptography - Cryptographic Operations

generateKeyPair(): Promise<KeyPair>

  • Purpose: Generate new cryptographic key pair

  • Returns: Public and private key pair for blockchain operations

  • Security: Uses blockchain-specific cryptographic standards

sign(privateKey: string, message: string): Promise<Signature>

  • Purpose: Sign message with private key

  • Parameters: Private key and message to sign

  • Returns: Digital signature for verification

  • Standards: Follows blockchain-specific signature formats

verify(publicKey: string, message: string, signature: string): Promise<boolean>

  • Purpose: Verify signature against message and public key

  • Parameters: Public key, original message, signature to verify

  • Returns: Boolean indicating signature validity

  • Verification: Cryptographic signature verification

IStorage - Consensus Storage (Hedera HCS)

createTopic(topicConfig: TopicConfig): Promise<TopicResult>

  • Purpose: Create new consensus topic for message storage

  • Parameters: Topic configuration with keys and properties

  • Returns: Topic creation result with topic ID

  • Consensus: Hedera Consensus Service integration

submitMessage(topicId: string, message: string): Promise<MessageResult>

  • Purpose: Submit message to consensus topic

  • Parameters: Topic ID and message content

  • Returns: Message submission result with sequence number

  • Ordering: Messages are consensus-ordered and timestamped

Error Types

Error Type
Description
Resolution

LedgerNotInitializedError

Ledger not properly initialized

Initialize ledger with valid configuration

InvalidChainTypeError

Unsupported blockchain type

Use supported chain types (HASHGRAPH, RIPPLE)

NetworkConnectionError

Network connectivity issues

Check network settings and connectivity

InsufficientBalanceError

Insufficient funds for operation

Ensure account has sufficient balance

InvalidCredentialsError

Invalid account credentials

Verify account ID and private key

TransactionFailedError

Transaction execution failed

Check transaction parameters and retry


πŸ“– Guides

Multi-Blockchain Setup Guide

Complete guide to setting up and configuring multiple blockchain networks. Comprehensive setup instructions covering multi-chain architecture, adapter configuration, network-specific settings, consensus mechanisms, and unified blockchain operations with seamless cross-chain interoperability.

Plugin Development Guide

Advanced guide to creating custom blockchain plugins and extensions. Detailed development guide covering plugin architecture, adapter interface implementation, blockchain-specific customizations, API extensions, and integration patterns for enterprise blockchain solutions.

Token Operations Guide

Comprehensive guide to fungible and non-fungible token operations across blockchains. Advanced token management covering multi-chain token creation, cross-chain transfers, metadata standards, supply management, and enterprise-grade token lifecycle operations.

Security Best Practices Guide

Security recommendations and best practices for blockchain operations. Enterprise security guide covering private key management, transaction signing, access control, audit trails, and secure blockchain integration patterns for production deployments.


Examples

Enterprise Multi-Blockchain Service

Advanced Plugin Development System

Complete Account and Transaction Management


Integration

Required Dependencies

Environment Configuration

Module Integration

Usage Patterns

Plugin Development

Network Switching


🌐 Multi-Blockchain: Unified interface for Hedera Hashgraph and Ripple (XRP) networks with extensible architecture.

πŸ”§ Service-Oriented: Specialized services for accounts, tokens, transactions, and cryptographic operations.

πŸ—οΈ Enterprise-Ready: Full NestJS integration with comprehensive error handling and monitoring capabilities.


Built with ❀️ by the HSuite Team Copyright © 2025 HSuite. All rights reserved.

Last updated