Socket
Socket
Sign inDemoInstall

@lido-nestjs/consensus

Package Overview
Dependencies
4
Maintainers
2
Versions
10
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @lido-nestjs/consensus

NestJS Consensus Layer API Module for Lido Finance projects. Part of [Lido NestJS Modules](https://github.com/lidofinance/lido-nestjs-modules/#readme)


Version published
Weekly downloads
31
decreased by-43.64%
Maintainers
2
Install size
3.53 MB
Created
Weekly downloads
 

Readme

Source

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

Config

Debug

Events

Node

Validator

Keywords

FAQs

Last updated on 03 Mar 2023

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc