NestJS Consensus Layer API Module for Lido Finance projects. Part of Lido NestJS Modules
yarn add @lido-nestjs/consensus
The types used in the API methods are based on Eth2Spec. To update them use the script:
./generate.sh
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();
}
}
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 {}
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 {}
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' } },
});
}
}
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' },
);
}
}
- 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