Alchemy Web3 API module for Nest.
$ npm i -s @darrenyeom/alchemy-api @alch/alchemy-web3
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();
}
}
MIT.