Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@catalist-nestjs/consensus

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@catalist-nestjs/consensus

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

  • 1.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

Consensus Layer API Module

NestJS Consensus Layer API Module for Catalist Finance projects. Part of Catalist NestJS Modules

Install

yarn add @catalist-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 @catalist-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 '@catalist-nestjs/consensus';
import { FetchModule } from '@catalist-nestjs/fetch';
import { MyService } from './my.service';

@Module({
  imports: [ConsensusModule.forFeature({ imports: [FetchModule] })],
  providers: [MyService],
  exports: [MyService],
})
export class MyModule {}

// Usage
import { ConsensusService } from '@catalist-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 '@catalist-nestjs/consensus';
import { FetchModule } from '@catalist-nestjs/fetch';

@Module({
  imports: [FetchModule.forRoot(), ConsensusModule.forRoot()],
})
export class MyModule {}

Async usage

import { Module } from '@nestjs/common';
import { ConsensusModule } from '@catalist-nestjs/consensus';
import { FetchModule } from '@catalist-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 '@catalist-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 '@catalist-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 '@catalist-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

Package last updated on 30 Apr 2024

Did you know?

Socket

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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc