Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for ethers v6 in @typechain/hardhat #843

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/tough-radios-smile.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@typechain/hardhat': major
'@typechain/ethers-v6': minor
---

Added support for ethers v6 in @typechain/hardhat
19 changes: 11 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
npm install --save-dev typechain
```

You will also need to install a desired target for example `@typechain/ethers-v5`. [Learn more about targets](#targets-)
You will also need to install a desired target for example `@typechain/ethers-v6`. [Learn more about targets](#targets-)

_Take note, that code generated by TypeChain requires TypeScript version 4.3 or newer._

Expand All @@ -49,7 +49,8 @@ _Take note, that code generated by TypeChain requires TypeScript version 4.3 or
| Package | Version | Description | Examples |
| ------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------- | -------------------------------------------- | -------------------------------------------------------------------------------------------------------------------- |
| [`typechain`](/packages/typechain) | [![npm](https://img.shields.io/npm/v/typechain.svg)](https://www.npmjs.com/package/typechain) | Core package | - |
| [`@typechain/ethers-v5`](/packages/target-ethers-v5) | [![npm](https://img.shields.io/npm/v/@typechain/ethers-v5.svg)](https://www.npmjs.com/package/@typechain/ethers-v5) | Ethers ver 5 support (⚠️ requires TS 4.0 >=) | [example](./examples/ethers-v5) |
| [`@typechain/ethers-v5`](/packages/target-ethers-v5) | [![npm](https://img.shields.io/npm/v/@typechain/ethers-v5.svg)](https://www.npmjs.com/package/@typechain/ethers-v5) | Ethers ver 5 support (⚠️ requires TS 4.0 >=) | [example](./examples/ethers-v5) |
| [`@typechain/ethers-v6`](/packages/target-ethers-v6) | [![npm](https://img.shields.io/npm/v/@typechain/ethers-v6.svg)](https://www.npmjs.com/package/@typechain/ethers-v6) | Ethers ver 6 support (⚠️ requires TS 4.0 >=) | [example](./examples/ethers-v6) |
| [`@typechain/starknet.js`](/packages/target-starknet) | [![npm](https://img.shields.io/npm/v/@typechain/starknet.svg)](https://www.npmjs.com/package/@typechain/starknet) | Starknet.js ver 3.9 | |
| [`@typechain/truffle-v5`](/packages/target-truffle-v5) | [![npm](https://img.shields.io/npm/v/@typechain/truffle-v5.svg)](https://www.npmjs.com/package/@typechain/truffle-v5) | Truffle ver 5 support | [example](./examples/truffle-v5) |
| [`@typechain/web3-v1`](/packages/target-web3-v1) | [![npm](https://img.shields.io/npm/v/@typechain/web3-v1.svg)](https://www.npmjs.com/package/@typechain/web3-v1) | Web3 ver 1 support | [example](./examples/web3-v1) |
Expand All @@ -72,25 +73,25 @@ _Note: If you use hardhat just use
[hardhat plugin](https://github.com/ethereum-ts/TypeChain/tree/master/packages/hardhat)._

```
typechain --target=(ethers-v5|truffle-v4|truffle-v5|web3-v1|path-to-custom-target) [glob]
typechain --target=(ethers-v5|ethers-v6|truffle-v4|truffle-v5|web3-v1|path-to-custom-target) [glob]
```

- `glob` - pattern that will be used to find ABIs, remember about adding quotes: `typechain "**/*.json"`, examples:
`./abis/**/*.abi`, `./abis/?(Oasis.abi|OasisHelper.abi)`.
- `--target` - ethers-v5, truffle-v4, truffle-v5, web3-v1 or path to your custom target. Typechain will try to load
- `--target` - ethers-v5, ethers-v6, truffle-v4, truffle-v5, web3-v1 or path to your custom target. Typechain will try to load
package named: `@typechain/${target}`, so make sure that desired package is installed.
- `--out-dir` (optional) - put all generated files to a specific dir.
- `--always-generate-overloads` (optional) - some targets won't generate unnecessary types for overloaded functions by
default, this option forces to always generate them
- `--discriminate-types` (optional) - ethers-v5 will add an artificial field `contractName` that helps discriminate
- `--discriminate-types` (optional) - ethers-v5 and ethers-v6 will add an artificial field `contractName` that helps discriminate
between contracts

TypeChain always will rewrite existing files. You should not commit them. Read more in FAQ section.

Example:

```
typechain --target ethers-v5 --out-dir app/contracts './node_modules/neufund-contracts/build/contracts/*.json'
typechain --target ethers-v6 --out-dir app/contracts './node_modules/neufund-contracts/build/contracts/*.json'
```

## Videos
Expand Down Expand Up @@ -123,13 +124,15 @@ That's it! Now, you can simply import typings, check out our examples for more d

## Targets 🎯

### Ethers.js v5
### Ethers.js v6

Use `ethers-v5` target to generate wrappers for [ethers.js](https://github.com/ethers-io/ethers.js/) lib. To make it
Use `ethers-v6` target to generate wrappers for [ethers.js](https://github.com/ethers-io/ethers.js/) lib. To make it
work great with Hardhat, use [Hardhat plugin](https://github.com/ethereum-ts/TypeChain/tree/master/packages/hardhat).

If you use `nodenext` aka `node16modules` flip the flag `--node16-modules` to generate compatible typings.

If you are using Ethers.js v5, use the `@typechain/ethers-v5` target.

If you're using Ethers.js v4, you can find legacy `@typechain/ethers-v4` target on
[npm](https://www.npmjs.com/package/@typechain/ethers-v4) and commit
[`db551b5`](https://github.com/dethcrypto/TypeChain/tree/db551b5c5f70e86f3ca342551e9e0369d099cfa2).
Expand Down
8 changes: 4 additions & 4 deletions examples/hardhat/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
"typecheck": "pnpm compile && pnpm test && pnpm tsc --noEmit"
},
"devDependencies": {
"@nomiclabs/hardhat-ethers": "^2.0.2",
"@nomiclabs/hardhat-waffle": "^2.0.1",
"@typechain/ethers-v5": "workspace:^11.0.0",
"@nomicfoundation/hardhat-ethers": "^3.0.0",
"@nomicfoundation/hardhat-chai-matchers": "^2.0.0",
"@typechain/ethers-v6": "workspace:^0.3.0",
"@typechain/hardhat": "workspace:^7.0.0",
"@types/chai": "^4.2.15",
"@types/chai-as-promised": "^7.1.3",
Expand All @@ -23,7 +23,7 @@
"chai-as-promised": "^7.1.1",
"dotenv": "^8.2.0",
"ethereum-waffle": "^3.2.2",
"ethers": "5.4.0",
"ethers": "6.3.0",
"@ethersproject/providers": "5.4.0",
"@ethersproject/contracts": "5.4.0",
"@ethersproject/abi": "5.4.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/hardhat-test/hardhat.config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// We load the plugin here.
import '@typechain/hardhat'
import '@nomiclabs/hardhat-ethers'
import '@nomicfoundation/hardhat-ethers'

import type { HardhatUserConfig } from 'hardhat/types'

Expand Down
6 changes: 3 additions & 3 deletions packages/hardhat-test/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@
"devDependencies": {
"@ethersproject/providers": "^5.4.7",
"@ethersproject/abi": "^5.4.7",
"@nomiclabs/hardhat-ethers": "^2.0.2",
"@typechain/ethers-v5": "workspace:^11.0.0",
"@nomicfoundation/hardhat-ethers": "^3.0.0",
"@typechain/ethers-v6": "workspace:^0.3.0",
"@typechain/hardhat": "workspace:^7.0.0",
"ethers": "^5.4.7",
"ethers": "~6.3.0",
"hardhat": "^2.9.9",
"test-utils": "1.0.0",
"typechain": "workspace:^8.2.0"
Expand Down
199 changes: 98 additions & 101 deletions packages/hardhat-test/typechain-types/Counter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,139 +3,136 @@
/* eslint-disable */
import type {
BaseContract,
BigNumber,
BigNumberish,
BytesLike,
CallOverrides,
ContractTransaction,
Overrides,
PopulatedTransaction,
Signer,
utils,
} from "ethers";
import type {
FunctionFragment,
Result,
Interface,
EventFragment,
} from "@ethersproject/abi";
import type { Listener, Provider } from "@ethersproject/providers";
AddressLike,
ContractRunner,
ContractMethod,
Listener,
} from "ethers";
import type {
TypedEventFilter,
TypedEvent,
TypedContractEvent,
TypedDeferredTopicFilter,
TypedEventLog,
TypedLogDescription,
TypedListener,
OnEvent,
TypedContractMethod,
} from "./common";

export interface CounterInterface extends utils.Interface {
functions: {
"countDown()": FunctionFragment;
"countUp()": FunctionFragment;
"getCount()": FunctionFragment;
};

export interface CounterInterface extends Interface {
getFunction(
nameOrSignatureOrTopic: "countDown" | "countUp" | "getCount"
nameOrSignature: "countDown" | "countUp" | "getCount"
): FunctionFragment;

getEvent(nameOrSignatureOrTopic: "CountedTo"): EventFragment;

encodeFunctionData(functionFragment: "countDown", values?: undefined): string;
encodeFunctionData(functionFragment: "countUp", values?: undefined): string;
encodeFunctionData(functionFragment: "getCount", values?: undefined): string;

decodeFunctionResult(functionFragment: "countDown", data: BytesLike): Result;
decodeFunctionResult(functionFragment: "countUp", data: BytesLike): Result;
decodeFunctionResult(functionFragment: "getCount", data: BytesLike): Result;

events: {
"CountedTo(uint256)": EventFragment;
};

getEvent(nameOrSignatureOrTopic: "CountedTo"): EventFragment;
}

export interface CountedToEventObject {
number: BigNumber;
export namespace CountedToEvent {
export type InputTuple = [number: BigNumberish];
export type OutputTuple = [number: bigint];
export interface OutputObject {
number: bigint;
}
export type Event = TypedContractEvent<InputTuple, OutputTuple, OutputObject>;
export type Filter = TypedDeferredTopicFilter<Event>;
export type Log = TypedEventLog<Event>;
export type LogDescription = TypedLogDescription<Event>;
}
export type CountedToEvent = TypedEvent<[BigNumber], CountedToEventObject>;

export type CountedToEventFilter = TypedEventFilter<CountedToEvent>;

export interface Counter extends BaseContract {
connect(signerOrProvider: Signer | Provider | string): this;
attach(addressOrName: string): this;
connect(runner?: ContractRunner | null): BaseContract;
attach(addressOrName: AddressLike): this;
deployed(): Promise<this>;

interface: CounterInterface;

queryFilter<TEvent extends TypedEvent>(
event: TypedEventFilter<TEvent>,
queryFilter<TCEvent extends TypedContractEvent>(
event: TCEvent,
fromBlockOrBlockhash?: string | number | undefined,
toBlock?: string | number | undefined
): Promise<Array<TEvent>>;

listeners<TEvent extends TypedEvent>(
eventFilter?: TypedEventFilter<TEvent>
): Array<TypedListener<TEvent>>;
listeners(eventName?: string): Array<Listener>;
removeAllListeners<TEvent extends TypedEvent>(
eventFilter: TypedEventFilter<TEvent>
): this;
removeAllListeners(eventName?: string): this;
off: OnEvent<this>;
on: OnEvent<this>;
once: OnEvent<this>;
removeListener: OnEvent<this>;

functions: {
countDown(
overrides?: Overrides & { from?: string }
): Promise<ContractTransaction>;

countUp(
overrides?: Overrides & { from?: string }
): Promise<ContractTransaction>;

getCount(overrides?: CallOverrides): Promise<[BigNumber]>;
};

countDown(
overrides?: Overrides & { from?: string }
): Promise<ContractTransaction>;

countUp(
overrides?: Overrides & { from?: string }
): Promise<ContractTransaction>;

getCount(overrides?: CallOverrides): Promise<BigNumber>;

callStatic: {
countDown(overrides?: CallOverrides): Promise<BigNumber>;
): Promise<Array<TypedEventLog<TCEvent>>>;
queryFilter<TCEvent extends TypedContractEvent>(
filter: TypedDeferredTopicFilter<TCEvent>,
fromBlockOrBlockhash?: string | number | undefined,
toBlock?: string | number | undefined
): Promise<Array<TypedEventLog<TCEvent>>>;

on<TCEvent extends TypedContractEvent>(
event: TCEvent,
listener: TypedListener<TCEvent>
): Promise<this>;
on<TCEvent extends TypedContractEvent>(
filter: TypedDeferredTopicFilter<TCEvent>,
listener: TypedListener<TCEvent>
): Promise<this>;

once<TCEvent extends TypedContractEvent>(
event: TCEvent,
listener: TypedListener<TCEvent>
): Promise<this>;
once<TCEvent extends TypedContractEvent>(
filter: TypedDeferredTopicFilter<TCEvent>,
listener: TypedListener<TCEvent>
): Promise<this>;

listeners<TCEvent extends TypedContractEvent>(
event: TCEvent
): Promise<Array<TypedListener<TCEvent>>>;
listeners(eventName?: string): Promise<Array<Listener>>;
removeAllListeners<TCEvent extends TypedContractEvent>(
event?: TCEvent
): Promise<this>;

countDown: TypedContractMethod<[], [bigint], "nonpayable">;

countUp: TypedContractMethod<[], [bigint], "nonpayable">;

getCount: TypedContractMethod<[], [bigint], "view">;

getFunction<T extends ContractMethod = ContractMethod>(
key: string | FunctionFragment
): T;

countUp(overrides?: CallOverrides): Promise<BigNumber>;
getFunction(
nameOrSignature: "countDown"
): TypedContractMethod<[], [bigint], "nonpayable">;
getFunction(
nameOrSignature: "countUp"
): TypedContractMethod<[], [bigint], "nonpayable">;
getFunction(
nameOrSignature: "getCount"
): TypedContractMethod<[], [bigint], "view">;

getCount(overrides?: CallOverrides): Promise<BigNumber>;
};
getEvent(
key: "CountedTo"
): TypedContractEvent<
CountedToEvent.InputTuple,
CountedToEvent.OutputTuple,
CountedToEvent.OutputObject
>;

filters: {
"CountedTo(uint256)"(number?: null): CountedToEventFilter;
CountedTo(number?: null): CountedToEventFilter;
};

estimateGas: {
countDown(overrides?: Overrides & { from?: string }): Promise<BigNumber>;

countUp(overrides?: Overrides & { from?: string }): Promise<BigNumber>;

getCount(overrides?: CallOverrides): Promise<BigNumber>;
};

populateTransaction: {
countDown(
overrides?: Overrides & { from?: string }
): Promise<PopulatedTransaction>;

countUp(
overrides?: Overrides & { from?: string }
): Promise<PopulatedTransaction>;

getCount(overrides?: CallOverrides): Promise<PopulatedTransaction>;
"CountedTo(uint256)": TypedContractEvent<
CountedToEvent.InputTuple,
CountedToEvent.OutputTuple,
CountedToEvent.OutputObject
>;
CountedTo: TypedContractEvent<
CountedToEvent.InputTuple,
CountedToEvent.OutputTuple,
CountedToEvent.OutputObject
>;
};
}
Loading