npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

nesthers

v0.9.0

Published

Nesthers is a convenient integration of the ethers.js library for NestJS

Downloads

4

Readme

Nesthers

Description

The Nesthers Module is a convenient integration of the ethers.js library into NestJS applications. This module aims to simplify the interaction with Ethereum blockchain features such as smart contracts, wallets, events, and more, providing a seamless and developer-friendly experience within the NestJS framework.

Installation

Install the module via npm:

npm install nesthers

Install the module via yarn:

yarn add nesthers

Features

  • Connection Configuration: Configure the Ethereum provider to connect to your preferred network (e.g., mainnet, testnet).
  • Wallet Management: Manage Ethereum wallets effortlessly for secure transactions.
  • Smart Contract Interaction: Easily interact with Ethereum smart contracts using the provided service methods.
  • Event Handling: Streamline the handling of Ethereum events for real-time updates.
  • Block Handling: Streamline the handling of Ethereum blocks for real-time updates.

Usage

  1. Module initialization
import { Module } from "@nestjs/common";
import { EthersModule, JsonRpcConnection } from "nesthers";

@Module({
  imports: [
    EthersModule.forRoot({
      connection: {
        name: "Connection", // is option
        instace: new JsonRpcConnection({
          url: "<URL>",
        }),
        wallets: [], // is option
        contracts: [], // is option
      },
    }),
  ],
})
export class AppModule {}
  1. Inject Connection
import { Injectable } from "@nestjs/common";
import { InjectConnection, JsonRpcConnection } from "nesthers";

@Injectable()
export class AppService {
  constructor(
    @InjectConnection("Conection") // name is option
    private readonly connection: JsonRpcConnection,
  ) {}
}
  1. WalletBuilder
import { WalletBuilder, Wallet } from "nesthers";

@WalletBuilder({
  privateKey: "0x0...",
})
export class AliceWallet extends Wallet {
  // you can add your own functionality here
}
  1. InjectWallet
import { Injectable } from "@nestjs/common";
import { InjectWallet } from "nesthers";
import { AliceWallet } from "./wallets/alice.wallet";

@Injectable()
export class AppService {
  constructor(
    @InjectWallet(AliceWallet.name) // name is require
    private readonly alice: AliceWallet,
  ) {}
}
  1. ContractBuilder
import { ContractBuilder, Contract } from "nesthers";

@ContractBuilder({
  address: "0x0...",
  abi: [
    {
      "constant": true,
      "inputs": [],
      "name": "name",
      ...
    },
    ...
  ],
})
export class TokenContract extends Contract {
  // you can add your own functionality here
}
  1. InjectContract
import { Injectable } from "@nestjs/common";
import { InjectContract } from "nesthers";
import { TokenContract } from "./contracts/token.contract";

@Injectable()
export class AppService {
  constructor(
    @InjectContract(TokenContract.name) // name is require
    private readonly token: TokenContract,
  ) {}
}
  1. OnBlock
import { Injectable } from "@nestjs/common";
import { OnBlock, Arg } from "nesthers";

@Injectable()
export class AppService {
  @OnBlock({})
  newBlockHandler(@Arg("hash") hash: string) {
    console.log(hash);
  }
}
  1. OnEvent
import { Injectable } from "@nestjs/common";
import { OnEvent, Arg } from "nesthers";

@Injectable()
export class AppService {
  @OnEvent({
    address: "0x0...",
    topics: [ /* args */ ],
  })
  newEventHandler(@Arg("hash") hash: string) {
    console.log(hash);
  }
}

License

nesthers is MIT licensed.