A powerful and flexible configuration management module for Hashgraph network applications, built on top of NestJS.
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.
-
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
npm install @hsuite/smart-config
{
"@nestjs/common": "^10.4.2",
"@nestjs/core": "^10.4.2"
}
{
"@hsuite/hashgraph-types": "^2.0.0",
"@hsuite/smart-network-types": "^2.0.0",
"@hashgraph/sdk": "^2.51.0"
}
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 {}
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;
}
}
The module supports various network configurations through the SmartConfigOptionsFactory
interface:
interface SmartConfigOptionsFactory {
createSmartConfigOptions(): Promise<ISmartNetwork.INetwork.IConfig.IOptions> | ISmartNetwork.INetwork.IConfig.IOptions;
}
Multiple configuration strategies are available:
- 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],
})
- Existing Factory
SmartConfigModule.forRootAsync({
useExisting: [YourExistingConfigFactory],
})
- Class Factory
SmartConfigModule.forRootAsync({
useClass: YourConfigFactory,
})
getEnvironment()
: Get current network environmentgetClientEnvironment()
: Get client environment as LedgerIdgetNodes()
: Retrieve network node configurationsgetUtilities()
: Get network utility servicesgetFees()
: Retrieve network fee structure
getIssuer()
: Get Hashgraph network issuer configurationgetOperator()
: Get client operator configurationgetMirrorNode()
: Get mirror node settingsgetThreshold()
: Calculate network consensus threshold
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.