1.0.1 • Published 1 year ago

nestjs-near v1.0.1

Weekly downloads
-
License
ISC
Repository
-
Last release
1 year ago

Introduction

Quick implementation of near in your application. Generation of typed smart contract methods. Including ready for use typed methods in popular smart contract Standards.

Navigation

Setup

You'll need to install the package from npm npm i nestjs-near near-api-js.

Quick Example

// app.module.ts
@Module({
  imports: [
    NestNearModule.forRootAsync({
      networkId: 'testnet',
      keyStore,
      nodeUrl: 'https://rpc.testnet.near.org',
      walletUrl: 'https://wallet.testnet.near.org',
      helperUrl: 'https://helper.testnet.near.org',
    }),
    NestNearContractModule.forRoot({
      accountId: TEST_CONTRACT_ID,
      contractId: TEST_CONTRACT_ID,
      viewMethods: ['ft_balance_of'],
      changeMethods: [],
    }),
    TestModule,
  ],
  controllers: [],
  providers: [],
})
export class AppModule {}

// test.service.ts
@Injectable({})
export class TestService {
  constructor(
    @InjectNestNear() public near: NestNear,
    @InjectNestNearContract(TEST_CONTRACT_ID) public contract: NestNearContract & { ft_balance_of: any },
  ) {}

  public async test(): Promise<any> {
    const account = await this.near.account('muzikant.testnet');
    const nearBalance = await account.getAccountBalance();

    const ftBalance = await this.contract.ft_balance_of({ account_id: 'muzikant.testnet' });

    return Promise.resolve({ nearBalance, ftBalance });
  }
}

Authors