Skip to content

Commit

Permalink
Merge pull request #1 from nazarkhatsko/develop
Browse files Browse the repository at this point in the history
Release v0.9.0
  • Loading branch information
nazarkhatsko authored Dec 17, 2023
2 parents ad48435 + 4da05df commit e9eed57
Show file tree
Hide file tree
Showing 59 changed files with 1,370 additions and 2 deletions.
27 changes: 27 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Editor config
# http://EditorConfig.org

# This EditorConfig overrides any parent EditorConfigs
root = true

# Default rules applied to all file types
[*]

# No trailing spaces, newline at EOF
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
end_of_line = lf

# 2 space indentation
indent_style = space
indent_size = 2

# JavaScript-specific settings
[*.{js,ts}]
quote_type = double
continuation_indent_size = 2
curly_bracket_next_line = false
indent_brace_style = BSD
spaces_around_operators = true
spaces_around_brackets = none
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dist
29 changes: 29 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
module.exports = {
parser: "@typescript-eslint/parser",
parserOptions: {
project: "tsconfig.json",
tsconfigRootDir : __dirname,
sourceType: "module",
},
plugins: [
"@typescript-eslint/eslint-plugin"
],
extends: [
"plugin:@typescript-eslint/recommended",
"plugin:prettier/recommended",
],
root: true,
env: {
node: true,
jest: true,
},
ignorePatterns: [
".eslintrc.js"
],
rules: {
"@typescript-eslint/interface-name-prefix": "off",
"@typescript-eslint/explicit-function-return-type": "off",
"@typescript-eslint/explicit-module-boundary-types": "off",
"@typescript-eslint/no-explicit-any": "off",
},
};
36 changes: 36 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# compiled output
/dist
/node_modules
package-lock.json

# Logs
logs
*.log
npm-debug.log*
pnpm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*

# OS
.DS_Store

# Tests
/coverage
/.nyc_output

# IDEs and editors
/.idea
.project
.classpath
.c9/
*.launch
.settings/
*.sublime-workspace

# IDE - VSCode
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json
69 changes: 69 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage

# nyc test coverage
.nyc_output

# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
bower_components

#ide
.vscode
.idea

# node-waf configuration
.lock-wscript

# Compiled binary addons (http://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules/
jspm_packages/

# Typescript v1 declaration files
typings/

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# dotenv environment variables file
.env

# NPM
src
examples
gulpfile.js
.prettierrc
.travis.yml
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dist
9 changes: 9 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"semi": true,
"singleQuote": false,
"trailingComma": "all",
"bracketSpacing": true,
"arrowParens": "avoid",
"printWidth": 100,
"tabWidth": 2
}
161 changes: 159 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,159 @@
# nestjs-web3
NestJS module for working with web3 applications (EVM)
# Nesthers


## Description

The Nesthers Module is a convenient integration of the [ethers.js](https://github.com/ethers-io/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:

```sh
npm install nesthers
```

Install the module via yarn:

```sh
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
```ts
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 {}
```
2. Inject Connection
```ts
import { Injectable } from "@nestjs/common";
import { InjectConnection, JsonRpcConnection } from "nesthers";

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

@WalletBuilder({
privateKey: "0x0...",
})
export class AliceWallet extends Wallet {
// you can add your own functionality here
}
```
4. InjectWallet
```ts
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,
) {}
}
```
5. ContractBuilder
```ts
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
}
```
6. InjectContract
```ts
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,
) {}
}
```
7. OnBlock
```ts
import { Injectable } from "@nestjs/common";
import { OnBlock, Arg } from "nesthers";

@Injectable()
export class AppService {
@OnBlock({})
newBlockHandler(@Arg("hash") hash: string) {
console.log(hash);
}
}
```
8. OnEvent
```ts
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](LICENSE).
8 changes: 8 additions & 0 deletions lib/common/block.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { ethers } from "ethers";
import { BlockOptions } from "../intefaces/block-options.interface";

export class Block extends ethers.Block {
constructor(options: BlockOptions) {
super(options.block, options.provider);
}
}
Loading

0 comments on commit e9eed57

Please sign in to comment.