nestjs-moralis
TypeScript icon, indicating that this package has built-in type declarations

1.0.0 • Public • Published

NestJS Moralis Module

Module to provide easy integration of Moralis.io API with NestJS.

Installation

To install npm package run command below:

npm install --save nestjs-moralis

Example

Below you can see examples of how to import MoralisModule into your NestJS application.

Sync module registration

@Module({
  imports: [
    MoralisModule.register({
      apiKey: "MORALIS_API_KEY_HERE",
    }),
  ],
  controllers: [],
  providers: [],
  exports: [],
})
export class ExampleModule {}

Async module registration

@Module({
  imports: [
    MoralisModule.registerAsync({
      imports: [ConfigModule],
      useFactory: async (configService: ConfigService) => {
        return {
          apiKey: configService.get<string>("MORALIS_API_KEY"),
        };
      },
      inject: [ConfigService],
    }),
    ConfigModule,
  ],
  controllers: [],
  providers: [],
  exports: [],
})
export class ExampleModule {}

Use in your Service

import { EvmChain } from "@moralisweb3/common-evm-utils";

@Injectable()
export class ExampleService {
  constructor(private readonly moralisService: MoralisService) {}

  async getEvmWalletBalance(address: `0x${string}`, chain: EvmChain) {
    const response = await this.moralisService.EvmApi.balance.getNativeBalance({
      address,
      chain,
    });

    return response.toJSON();
  }
}

Module config options

Module options include all config options available in Moralis plus additional properties defined below.

export type MoralisModuleOptions = Partial<MoralisConfigValues> & {
  /**
   * @dev set to true if module should be @Global
   */
  isGlobal?: boolean;
};

Package Sidebar

Install

npm i nestjs-moralis

Weekly Downloads

4

Version

1.0.0

License

MIT

Unpacked Size

107 kB

Total Files

29

Last publish

Collaborators

  • mac-lisowski