Skip to content

Commit 64bec96

Browse files
MMujtabaRoohani0xslipkMMujtabaRoohani-BlockApex
authored
147 add support for ethers v6 (#168)
* Remove jest in order to use tap * update timeout * remove deps * update ts config * migration * add node lts 20.x * merging changes from main * update doc links and allow FetchRequest in custom RPCs * BscscanProvider will use etherscan url only as etherscan v2 supports all chains in one URL * fix tests with appropriate mocks * update readme with migration to v3 section * bump version to 3.0.0 * fix tests failing due to real RPC calls * add missing test to improve coverage --------- Co-authored-by: Jose Ramirez <jarcodallo@gmail.com> Co-authored-by: Muhammad Mujtaba Roohani <mujtaba.roohani@blockapex.io>
1 parent b5416e2 commit 64bec96

23 files changed

+4231
-4130
lines changed

.circleci/config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,4 +50,4 @@ workflows:
5050
- test:
5151
matrix:
5252
parameters:
53-
node-version: ['22.10', '20.17', '18.20']
53+
node-version: ['22.10', '20.17', '18.20']

.eslintrc.js

Lines changed: 0 additions & 35 deletions
This file was deleted.

.nvmrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
lts/jod
1+
lts/jod

README.md

Lines changed: 24 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ import { EthersModule } from 'nestjs-ethers';
3333
class MyModule {}
3434
```
3535

36-
**NOTE:** *By default `EthersModule` will try to connect using [getDefaultProvider](https://docs.ethers.io/v5/api/providers/#providers-getDefaultProvider). It's the safest, easiest way to begin developing on Ethereum. It creates a [FallbackProvider](https://docs.ethers.io/v5/api/providers/other/#FallbackProvider) connected to as many backend services as possible.*
36+
**NOTE:** *By default `EthersModule` will try to connect using [getDefaultProvider](https://docs.ethers.org/v6/api/providers/#getDefaultProvider). It's the safest, easiest way to begin developing on Ethereum. It creates a [FallbackProvider](https://docs.ethers.org/v6/api/providers/fallback-provider/) connected to as many backend services as possible.*
3737

3838
### Configuration params
3939

@@ -47,9 +47,9 @@ interface EthersModuleOptions {
4747
* If no network is provided, homestead (i.e. mainnet) is used.
4848
* The network may also be a URL to connect to,
4949
* such as http://localhost:8545 or wss://example.com.
50-
* @see {@link https://docs.ethers.io/v5/api/providers/types/#providers-Networkish}
50+
* @see {@link https://docs.ethers.org/v6/api/providers/#Networkish}
5151
*/
52-
network?: Network | string;
52+
network?: Networkish;
5353

5454
/**
5555
* Optional parameter for Alchemy API Token
@@ -104,39 +104,25 @@ interface EthersModuleOptions {
104104
ankr?: AnkrProviderOptions | string;
105105

106106
/**
107-
* Optional parameter for a custom StaticJsonRpcProvider
108-
* You can connect using an URL, ConnectionInfo or an array of both.
109-
* @see {@link https://docs.ethers.io/v5/api/providers/jsonrpc-provider/#StaticJsonRpcProvider}
110-
* @ses {@link https://docs.ethers.io/v5/api/utils/web/#ConnectionInfo}
107+
* Optional parameter for a custom JsonRpcProvider
108+
* You can connect using an URL, FetchRequest or an array of both.
109+
* @see {@link https://docs.ethers.org/v6/api/providers/jsonrpc/}
110+
* @ses {@link https://docs.ethers.org/v6/api/utils/fetching/#FetchRequest}
111111
*/
112-
custom?: ConnectionInfo | string | (ConnectionInfo | string)[]
112+
custom?: string | FetchRequest | (string | FetchRequest)[]
113113

114114
/**
115115
* Optional parameter the number of backends that must agree
116116
* (default: 2 for mainnet, 1 for testnets)
117117
*/
118118
quorum?: number;
119119

120-
/**
121-
* Optional parameter if this option is false, EthersModule won't wait until
122-
* the providers are ready. If this option is true, EthersModule will wait
123-
* until the network has heen established for all the providers.
124-
* @see {@link https://docs.ethers.io/v5/api/providers/provider/#Provider-ready}
125-
*/
126-
waitUntilIsConnected?: boolean;
127-
128120
/**
129121
* Optional parameter if this option is false, EthersModule will try to connect
130122
* with the credentials provided in options. If you define more than one provider,
131123
* EthersModule will use the FallbackProvider to send multiple requests simultaneously.
132124
*/
133125
useDefaultProvider?: boolean;
134-
135-
/**
136-
* Optional parameter if this option is true, EthersModule will disable
137-
* the console.log in the ethers.js library.
138-
*/
139-
disableEthersLogger?: boolean
140126

141127
/**
142128
* Optional parameter to associate a token name to EthersProvider,
@@ -301,7 +287,7 @@ class TestModule {}
301287

302288
## BaseProvider
303289

304-
`BaseProvider` implements standard [Ether.js Provider](https://docs.ethers.io/v5/api/providers/provider/). So if you are familiar with it, you are ready to go.
290+
`BaseProvider` implements standard [Ether.js Provider](https://docs.ethers.org/v6/api/providers/#Provider). So if you are familiar with it, you are ready to go.
305291

306292
```ts
307293
import { InjectEthersProvider, BaseProvider } from 'nestjs-ethers';
@@ -397,9 +383,9 @@ class TestController {
397383
}
398384
```
399385

400-
## Custom StaticJsonRpcProvider
386+
## Custom JsonRpcProvider
401387

402-
if you are familiar with [StaticJsonRpcProvider](https://docs.ethers.io/v5/api/providers/jsonrpc-provider/#StaticJsonRpcProvider), you are ready to go. The custom provider is very helpful when you want to use a RPC that is not defined in [ethers](https://github.com/ethers-io/ethers.js/). This is the case for Binance Smart Chain public [RPCs](https://docs.binance.org/smart-chain/developer/rpc.html).
388+
if you are familiar with [JsonRpcProvider](https://docs.ethers.org/v6/api/providers/jsonrpc/), you are ready to go. The custom provider is very helpful when you want to use a RPC that is not defined in [ethers](https://github.com/ethers-io/ethers.js/). This is the case for Binance Smart Chain public [RPCs](https://docs.binance.org/smart-chain/developer/rpc.html).
403389

404390
```ts
405391
import {
@@ -479,7 +465,7 @@ class TestController {
479465

480466
## EthersSigner
481467

482-
`EthersSigner` implements methods to create a [Wallet](https://docs.ethers.io/v5/api/signer/#Wallet) or [VoidSigner](https://docs.ethers.io/v5/api/signer/#VoidSigner). A `Signer` in ethers is an abstraction of an Ethereum Account, which can be used to sign messages and transactions and send signed transactions to the Ethereum Network. This service will also inject the `BaseProvider` into the wallet.
468+
`EthersSigner` implements methods to create a [Wallet](https://docs.ethers.org/v6/api/wallet/#Wallet) or [VoidSigner](https://docs.ethers.org/v6/api/providers/abstract-signer/#VoidSigner). A `Signer` in ethers is an abstraction of an Ethereum Account, which can be used to sign messages and transactions and send signed transactions to the Ethereum Network. This service will also inject the `BaseProvider` into the wallet.
483469

484470
Create a `Wallet` from a private key:
485471

@@ -502,7 +488,7 @@ export class TestService {
502488
}
503489
```
504490

505-
Create a random [Wallet](https://docs.ethers.io/v5/api/signer/#Wallet-createRandom):
491+
Create a random [Wallet](https://docs.ethers.org/v6/api/wallet/#Wallet_createRandom):
506492

507493
```ts
508494
import { EthersSigner, InjectSignerProvider, Wallet } from 'nestjs-ethers';
@@ -521,7 +507,7 @@ export class TestService {
521507
}
522508
```
523509

524-
Create a [Wallet](https://docs.ethers.io/v5/api/signer/#Wallet-fromEncryptedJson) from an encrypted JSON:
510+
Create a [Wallet](https://docs.ethers.org/v6/api/wallet/#Wallet_fromEncryptedJson) from an encrypted JSON:
525511

526512
```ts
527513
import { EthersSigner, InjectSignerProvider, Wallet } from 'nestjs-ethers';
@@ -569,7 +555,7 @@ export class TestService {
569555
}
570556
```
571557

572-
Create a [Wallet](https://docs.ethers.io/v5/api/signer/#Wallet.fromMnemonic) from a mnemonic:
558+
Create a [Wallet](https://docs.ethers.org/v6/api/wallet/#Wallet_fromPhrase) from a mnemonic:
573559

574560
```ts
575561
import { EthersSigner, InjectSignerProvider, Wallet } from 'nestjs-ethers';
@@ -590,7 +576,7 @@ export class TestService {
590576
}
591577
```
592578

593-
Create a [VoidSigner](https://docs.ethers.io/v5/api/signer/ from an address:
579+
Create a [VoidSigner](https://docs.ethers.org/v6/api/providers/#Signer) from an address:
594580

595581
```ts
596582
import { EthersSigner, InjectSignerProvider, VoidSigner } from 'nestjs-ethers';
@@ -613,7 +599,7 @@ export class TestService {
613599

614600
## EthersContract
615601

616-
`EthersContract` implements a method for the creation of a [Contract](https://docs.ethers.io/v5/api/contract/) instance. This service will also inject the a `BaseProvider` into the contract.
602+
`EthersContract` implements a method for the creation of a [Contract](https://docs.ethers.org/v6/api/contract/) instance. This service will also inject the a `BaseProvider` into the contract.
617603

618604
Create a `SmartContract` attached to an address:
619605

@@ -638,7 +624,7 @@ class TestService {
638624
}
639625
```
640626

641-
Create a [Contract](https://docs.ethers.io/v5/api/contract/) with a Wallet:
627+
Create a [Contract](https://docs.ethers.org/v6/api/contract/) with a Wallet:
642628

643629
```ts
644630
import {
@@ -998,6 +984,12 @@ class TestService {
998984
}
999985
```
1000986

987+
### v3
988+
989+
- Migrated to ethers.js v6 from v5, introduced breaking changes, see the [migration guide](https://docs.ethers.org/v6/migrating/#migrating) for comprehensive list of changes
990+
- `BigNumber` was replaced with the standard `bigint`
991+
- `StaticJsonRpcProvider` was merged to `JsonRpcProvider` with `staticNetwork` option.
992+
1001993
## Change Log
1002994

1003995
See [Changelog](CHANGELOG.md) for more information.

eslint.config.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
const { fixupPluginRules } = require('@eslint/compat')
22
const { FlatCompat } = require('@eslint/eslintrc')
33
const js = require('@eslint/js')
4-
const typescriptEslintEslintPlugin = require('@typescript-eslint/eslint-plugin')
54
const tsParser = require('@typescript-eslint/parser')
65
const _import = require('eslint-plugin-import')
76
const globals = require('globals')
@@ -14,12 +13,11 @@ const compat = new FlatCompat({
1413

1514
module.exports = [
1615
{
17-
ignores: ['**/eslint.config.js'],
16+
ignores: ['**/eslint.config.js', '**/dist/**', '**/node_modules/**'],
1817
},
1918
...compat.extends('plugin:@typescript-eslint/recommended', 'plugin:prettier/recommended'),
2019
{
2120
plugins: {
22-
'@typescript-eslint': typescriptEslintEslintPlugin,
2321
import: fixupPluginRules(_import),
2422
},
2523

0 commit comments

Comments
 (0)