@lido-nestjs/consensus
v1.5.0
Published
NestJS Consensus Layer API Module for Lido Finance projects. Part of [Lido NestJS Modules](https://github.com/lidofinance/lido-nestjs-modules/#readme)
Downloads
1,137
Readme
Consensus Layer API Module
NestJS Consensus Layer API Module for Lido Finance projects. Part of Lido NestJS Modules
Install
yarn add @lido-nestjs/consensus
Update types
The types used in the API methods are based on Eth2Spec. To update them use the script:
./generate.sh
Usage
This module depends on FetchModule
from @lido-nestjs/fetch
, so you need to provide it as a global module or import it into ConsensusModule
.
// Import
import { Module } from '@nestjs/common';
import { ConsensusModule } from '@lido-nestjs/consensus';
import { FetchModule } from '@lido-nestjs/fetch';
import { MyService } from './my.service';
@Module({
imports: [ConsensusModule.forFeature({ imports: [FetchModule] })],
providers: [MyService],
exports: [MyService],
})
export class MyModule {}
// Usage
import { ConsensusService } from '@lido-nestjs/consensus';
export class MyService {
constructor(private consensusService: ConsensusService) {}
async myMethod() {
return await this.consensusService.getGenesis();
}
}
Global usage
import { Module } from '@nestjs/common';
import { ConsensusModule } from '@lido-nestjs/consensus';
import { FetchModule } from '@lido-nestjs/fetch';
@Module({
imports: [FetchModule.forRoot(), ConsensusModule.forRoot()],
})
export class MyModule {}
Async usage
import { Module } from '@nestjs/common';
import { ConsensusModule } from '@lido-nestjs/consensus';
import { FetchModule } from '@lido-nestjs/fetch';
import { ConfigModule, ConfigService } from './my.service';
@Module({
imports: [
ConfigModule.forRoot(),
FetchModule.forRoot(),
ConsensusModule.forRootAsync({
async useFactory(configService: ConfigService) {
return { pollingInterval: configService.pollingInterval };
},
inject: [ConfigService],
}),
],
})
export class MyModule {}
Fetch options
Methods support fetch options
:
// Usage
import { ConsensusService } from '@lido-nestjs/consensus';
export class MyService {
constructor(private consensusService: ConsensusService) {}
async myMethod() {
return await this.consensusService.getGenesis({
options: { headers: { 'x-header-foo': 'bar' } },
});
}
}
Subscription
Subscribe to head blocks:
import { ConsensusService } from '@lido-nestjs/consensus';
export class MyService {
constructor(private consensusService: ConsensusService) {
this.consensusService.subscribe((error, data) => {
console.log(error, data);
});
}
}
Subscribe to finalized blocks:
import { ConsensusService } from '@lido-nestjs/consensus';
export class MyService {
constructor(private consensusService: ConsensusService) {
this.consensusService.subscribe(
(error, data) => {
console.log(error, data);
},
{ blockId: 'finalized' },
);
}
}
Methods
Beacon
- getGenesis
- getStateRoot
- getStateFork
- getStateFinalityCheckpoints
- getStateValidators
- getStateValidator
- getStateValidatorBalances
- getEpochCommittees
- getEpochSyncCommittees
- getBlockHeaders
- getBlockHeader
- publishBlock
- getBlock
- getBlockV2
- getBlockRoot
- getBlockAttestations
- getPoolAttestations
- submitPoolAttestations
- getPoolAttesterSlashings
- submitPoolAttesterSlashings
- getPoolProposerSlashings
- submitPoolProposerSlashings
- submitPoolSyncCommitteeSignatures
- getPoolVoluntaryExits
- submitPoolVoluntaryExit