NestJS Contracts Module for Lido Finance projects. Part of Lido NestJS Modules
yarn add @poolsea-nestjs/contracts
// Import
import { Module } from '@nestjs/common';
import { LidoContractModule } from '@poolsea-nestjs/contracts';
import { getDefaultProvider } from '@ethersproject/providers';
import { MyService } from './my.service';
@Module({
imports: [
LidoContractModule.forFeature({
provider: getDefaultProvider('mainnet'),
}),
],
providers: [MyService],
exports: [MyService],
})
export class MyModule {}
// Usage
import { LIDO_CONTRACT_TOKEN, Lido } from '@poolsea-nestjs/contracts';
import { Inject } from '@nestjs/common';
export class MyService {
constructor(@Inject(LIDO_CONTRACT_TOKEN) private contract: Lido) {}
async myMethod() {
return await this.contract.decimals();
}
}
Specify a different address:
LidoContractModule.forFeature({
address: '0xae7ab96520DE3A18E5e111B5EaAb095312D7fE84',
});
import { Module } from '@nestjs/common';
import { LidoContractModule } from '@poolsea-nestjs/contracts';
@Module({
imports: [LidoContractModule.forRoot()],
})
export class MyModule {}
import { Module } from '@nestjs/common';
import { LidoContractModule } from '@poolsea-nestjs/contracts';
import { ConfigModule, ConfigService } from './config.service';
@Module({
imports: [
LidoContractModule.forRootAsync({
async useFactory(testService: TestService) {
return { address: testService.address };
},
inject: [TestService],
}),
],
})
export class MyModule {}
import { Module } from '@nestjs/common';
import { LidoContractModule } from '@poolsea-nestjs/contracts';
import { ProviderModule } from './provider.service';
@Module({
imports: [ProviderModule.forRoot(), LidoContractModule.forRoot()],
})
export class MyModule {}
- Put ABI into
packages/contracts/abi
folder - Set up
packages/contracts/<your name of abi>
: module, contracts - Nice to have: add test for ABI:
packages/contracts/test/contracts.spec.ts
- Go through install FAQ
- Enjoy