HbarSuite Docs
  • Welcome to HbarSuite
  • HbarSuite Developer Documentation
    • HbarSuite Smart Engine Applications
      • @hsuite/cross-chain-exchange
      • @hsuite/dao
      • @hsuite/exchange
      • @hsuite/launchpad
      • @hsuite/multisig
      • @hsuite/nft-exchange
    • HSuite Libraries
      • @hsuite/api-key
      • @hsuite/auth-types
      • @hsuite/auth
      • @hsuite/client-types
      • @hsuite/client
      • @hsuite/dkg-types
      • @hsuite/hashgraph-types
      • @hsuite/health
      • @hsuite/helpers
      • @hsuite/ipfs
      • @hsuite/smart-config
      • @hsuite/smart-network-types
      • @hsuite/smart-transaction-types
      • @hsuite/smartnode-sdk
      • @hsuite/snapshots
      • @hsuite/subscriptions-types
      • @hsuite/subscriptions
      • @hsuite/throttler-types
      • @hsuite/throttler
      • @hsuite/users-types
      • @hsuite/users
      • @hsuite/validators-types
  • General Documentation
    • Tokenomics
      • Tokenomics v1
      • Tokenomics V2
    • Smart Apps and Interaction
      • Subscription-Based Model
      • Token-Gate Model
    • The Smart Node Network
      • security-layer
        • Security Layer Integration
        • Setting Up Secure Clusters
        • Generating and Sharing Keys Collaboratively
        • Protecting Secrets with Shamir's Method
        • Managing Cluster Membership
        • Handling Node Expulsion and Replacement
        • Automating Responses to Network Changes & Key Rotation
        • Ensuring Continuous Operation and Recovery
      • Understanding Validators in Our System
        • Type of Validators Explained
    • What is a Smart Node?
  • Restful APIs Documentation
Powered by GitBook
On this page
  • Overview
  • Features
  • Installation
  • Peer Dependencies
  • Dependencies
  • Usage
  • Module Registration
  • Using the Service
  • Configuration Options
  • Network Configuration
  • Async Configuration
  • API Reference
  • SmartConfigService
  • Development
  • Documentation
  1. HbarSuite Developer Documentation
  2. HSuite Libraries

@hsuite/smart-config

Previous@hsuite/ipfsNext@hsuite/smart-network-types

Last updated 3 months ago

A powerful and flexible configuration management module for Hashgraph network applications, built on top of NestJS.

Overview

The Smart Config module provides a centralized configuration management system for Hashgraph network operations. It handles various aspects of configuration including network environments, node management, service discovery, and fee structures.

Features

  • Network Environment Management

    • Support for testnet and mainnet environments

    • Public and private network configurations

    • Custom network settings

    • Local development environment support

  • Node Configuration

    • Dynamic node discovery and management

    • Consensus threshold calculation

    • Network entity configuration

    • Node health monitoring

  • Service Integration

    • Mirror node configuration

    • HTTP service integration

    • Utility service discovery

    • Fee structure management

  • Operator Management

    • Operator credentials handling

    • Access permission management

    • Operation parameter configuration

Installation

npm install @hsuite/smart-config

Peer Dependencies

{
  "@nestjs/common": "^10.4.2",
  "@nestjs/core": "^10.4.2"
}

Dependencies

{
  "@hsuite/hashgraph-types": "^2.0.0",
  "@hsuite/smart-network-types": "^2.0.0",
  "@hashgraph/sdk": "^2.51.0"
}

Usage

Module Registration

The Smart Config module can be registered asynchronously in your NestJS application:

import { Module } from '@nestjs/common';
import { SmartConfigModule } from '@hsuite/smart-config';

@Module({
  imports: [
    SmartConfigModule.forRootAsync({
      useFactory: () => ({
        environment: 'testnet',
        network: 'public',
        client_environment: 'testnet',
        // Additional configuration options
      }),
    }),
  ],
})
export class AppModule {}

Using the Service

Inject and use the SmartConfigService in your application:

import { Injectable } from '@nestjs/common';
import { SmartConfigService } from '@hsuite/smart-config';

@Injectable()
export class YourService {
  constructor(private readonly configService: SmartConfigService) {}

  async getNetworkNodes() {
    const nodes = await this.configService.getNodes();
    return nodes;
  }

  async getNetworkFees() {
    const fees = await this.configService.getFees();
    return fees;
  }
}

Configuration Options

Network Configuration

The module supports various network configurations through the SmartConfigOptionsFactory interface:

interface SmartConfigOptionsFactory {
  createSmartConfigOptions(): Promise<ISmartNetwork.INetwork.IConfig.IOptions> | ISmartNetwork.INetwork.IConfig.IOptions;
}

Async Configuration

Multiple configuration strategies are available:

  1. Factory Function

SmartConfigModule.forRootAsync({
  useFactory: (configService: ConfigService) => ({
    environment: configService.get('NETWORK_ENVIRONMENT'),
    network: configService.get('NETWORK_TYPE'),
    client_environment: configService.get('CLIENT_ENVIRONMENT'),
  }),
  inject: [ConfigService],
})
  1. Existing Factory

SmartConfigModule.forRootAsync({
  useExisting: [YourExistingConfigFactory],
})
  1. Class Factory

SmartConfigModule.forRootAsync({
  useClass: YourConfigFactory,
})

API Reference

SmartConfigService

Network Operations

  • getEnvironment(): Get current network environment

  • getClientEnvironment(): Get client environment as LedgerId

  • getNodes(): Retrieve network node configurations

  • getUtilities(): Get network utility services

  • getFees(): Retrieve network fee structure

Configuration Management

  • getIssuer(): Get Hashgraph network issuer configuration

  • getOperator(): Get client operator configuration

  • getMirrorNode(): Get mirror node settings

  • getThreshold(): Calculate network consensus threshold

Development

Documentation

Generate documentation using Compodoc:

npm run compodoc

Check documentation coverage:

npm run compodoc:coverage

Built with ❤️ by the HbarSuite Team Copyright © 2024 HbarSuite. All rights reserved.