Skip to content

zhixian001/alchemy-api

Repository files navigation

Nest Logo

Nest Alchemy API module

Description

Alchemy Web3 API module for Nest.

Installation

$ npm i -s @darrenyeom/alchemy-api @alch/alchemy-web3

Quickstart

app.module.ts

import { Module } from '@nestjs/common';
import { AlchemyApiModule } from '@darrenyeom/alchemy-api';
import { AppController } from './app.controller';
import { AppService } from './app.service';

@Module({
  imports: [
    AlchemyApiModule.forRoot({
      alchemyUrl:
        'wss://eth-mainnet.alchemyapi.io/v2/<API_KEY>',
    }),
  ],
  controllers: [AppController],
  providers: [AppService],
})
export class AppModule {}

app.service.ts

import { Injectable } from '@nestjs/common';
import { AlchemyApiService } from '@darrenyeom/alchemy-api';

@Injectable()
export class AppService {
  constructor(private readonly alchemyApiService: AlchemyApiService) {}

  async getBlockNumber() {
    return this.alchemyApiService.client.eth.getBlockNumber();
  }
}

License

MIT.