Skip to content

Commit c2b3f1b

Browse files
Update ethers.deployContract with DeployContractOptions (#853)
Co-authored-by: Dainis Gorbunovs <[email protected]>
1 parent 33879dc commit c2b3f1b

File tree

7 files changed

+62
-37
lines changed

7 files changed

+62
-37
lines changed

.changeset/cuddly-ghosts-drum.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'@typechain/hardhat': patch
3+
'@typechain/ethers-v6': patch
4+
---
5+
6+
Support for the newest hardhat-ethers version

examples/hardhat/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"typecheck": "pnpm compile && pnpm test && pnpm tsc --noEmit"
1212
},
1313
"devDependencies": {
14-
"@nomicfoundation/hardhat-ethers": "^3.0.0",
14+
"@nomicfoundation/hardhat-ethers": "^3.0.4",
1515
"@nomicfoundation/hardhat-chai-matchers": "^2.0.0",
1616
"@typechain/ethers-v6": "workspace:^0.4.0",
1717
"@typechain/hardhat": "workspace:^8.0.0",

examples/hardhat/test/counter.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import chai from 'chai'
22
import chaiAsPromised from 'chai-as-promised'
33
import { solidity } from 'ethereum-waffle'
44
import { ethers } from 'hardhat'
5+
import { DeployContractOptions } from '@nomicfoundation/hardhat-ethers/types'
56

67
import type { Counter } from '../typechain-types'
78

@@ -17,13 +18,15 @@ describe('Counter', () => {
1718
const signers = await ethers.getSigners()
1819

1920
// 2
20-
counter = await ethers.deployContract('Counter')
21-
21+
const gasPrice = 1637083528
22+
const options: DeployContractOptions = { gasPrice }
23+
counter = await ethers.deployContract('Counter', options)
2224
const initialCount = await counter.getCount()
2325

2426
// 3
2527
expect(initialCount).to.eq(0)
2628
expect(await counter.getAddress()).to.properAddress
29+
expect(counter.deploymentTransaction()?.gasPrice).to.eq(gasPrice)
2730
})
2831

2932
// 4

packages/hardhat-test/typechain-types/hardhat.d.ts

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import { ethers } from "ethers";
66
import {
7+
DeployContractOptions,
78
FactoryOptions,
89
HardhatEthersHelpers as HardhatEthersHelpersBase,
910
} from "@nomicfoundation/hardhat-ethers/types";
@@ -52,40 +53,40 @@ declare module "hardhat/types/runtime" {
5253

5354
deployContract(
5455
name: "Counter",
55-
signerOrOptions?: ethers.Signer | FactoryOptions
56+
signerOrOptions?: ethers.Signer | DeployContractOptions
5657
): Promise<Contracts.Counter>;
5758
deployContract(
5859
name: "Demo",
59-
signerOrOptions?: ethers.Signer | FactoryOptions
60+
signerOrOptions?: ethers.Signer | DeployContractOptions
6061
): Promise<Contracts.Demo>;
6162
deployContract(
6263
name: "Hello",
63-
signerOrOptions?: ethers.Signer | FactoryOptions
64+
signerOrOptions?: ethers.Signer | DeployContractOptions
6465
): Promise<Contracts.Hello>;
6566
deployContract(
6667
name: "StructsInConstructor",
67-
signerOrOptions?: ethers.Signer | FactoryOptions
68+
signerOrOptions?: ethers.Signer | DeployContractOptions
6869
): Promise<Contracts.StructsInConstructor>;
6970

7071
deployContract(
7172
name: "Counter",
7273
args: any[],
73-
signerOrOptions?: ethers.Signer | FactoryOptions
74+
signerOrOptions?: ethers.Signer | DeployContractOptions
7475
): Promise<Contracts.Counter>;
7576
deployContract(
7677
name: "Demo",
7778
args: any[],
78-
signerOrOptions?: ethers.Signer | FactoryOptions
79+
signerOrOptions?: ethers.Signer | DeployContractOptions
7980
): Promise<Contracts.Demo>;
8081
deployContract(
8182
name: "Hello",
8283
args: any[],
83-
signerOrOptions?: ethers.Signer | FactoryOptions
84+
signerOrOptions?: ethers.Signer | DeployContractOptions
8485
): Promise<Contracts.Hello>;
8586
deployContract(
8687
name: "StructsInConstructor",
8788
args: any[],
88-
signerOrOptions?: ethers.Signer | FactoryOptions
89+
signerOrOptions?: ethers.Signer | DeployContractOptions
8990
): Promise<Contracts.StructsInConstructor>;
9091

9192
// default types
@@ -105,12 +106,12 @@ declare module "hardhat/types/runtime" {
105106
): Promise<ethers.Contract>;
106107
deployContract(
107108
name: string,
108-
signerOrOptions?: ethers.Signer | FactoryOptions
109+
signerOrOptions?: ethers.Signer | DeployContractOptions
109110
): Promise<ethers.Contract>;
110111
deployContract(
111112
name: string,
112113
args: any[],
113-
signerOrOptions?: ethers.Signer | FactoryOptions
114+
signerOrOptions?: ethers.Signer | DeployContractOptions
114115
): Promise<ethers.Contract>;
115116
}
116117
}

packages/hardhat/test/fixture-projects/hardhat-project/typechain-types/hardhat.d.ts

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import { ethers } from "ethers";
66
import {
7+
DeployContractOptions,
78
FactoryOptions,
89
HardhatEthersHelpers as HardhatEthersHelpersBase,
910
} from "@nomicfoundation/hardhat-ethers/types";
@@ -61,49 +62,49 @@ declare module "hardhat/types/runtime" {
6162

6263
deployContract(
6364
name: "EdgeCases",
64-
signerOrOptions?: ethers.Signer | FactoryOptions
65+
signerOrOptions?: ethers.Signer | DeployContractOptions
6566
): Promise<Contracts.EdgeCases>;
6667
deployContract(
6768
name: "SafeMath",
68-
signerOrOptions?: ethers.Signer | FactoryOptions
69+
signerOrOptions?: ethers.Signer | DeployContractOptions
6970
): Promise<Contracts.SafeMath>;
7071
deployContract(
7172
name: "TestContract",
72-
signerOrOptions?: ethers.Signer | FactoryOptions
73+
signerOrOptions?: ethers.Signer | DeployContractOptions
7374
): Promise<Contracts.TestContract>;
7475
deployContract(
7576
name: "TestContract1",
76-
signerOrOptions?: ethers.Signer | FactoryOptions
77+
signerOrOptions?: ethers.Signer | DeployContractOptions
7778
): Promise<Contracts.TestContract1>;
7879
deployContract(
7980
name: "ERC20",
80-
signerOrOptions?: ethers.Signer | FactoryOptions
81+
signerOrOptions?: ethers.Signer | DeployContractOptions
8182
): Promise<Contracts.ERC20>;
8283

8384
deployContract(
8485
name: "EdgeCases",
8586
args: any[],
86-
signerOrOptions?: ethers.Signer | FactoryOptions
87+
signerOrOptions?: ethers.Signer | DeployContractOptions
8788
): Promise<Contracts.EdgeCases>;
8889
deployContract(
8990
name: "SafeMath",
9091
args: any[],
91-
signerOrOptions?: ethers.Signer | FactoryOptions
92+
signerOrOptions?: ethers.Signer | DeployContractOptions
9293
): Promise<Contracts.SafeMath>;
9394
deployContract(
9495
name: "TestContract",
9596
args: any[],
96-
signerOrOptions?: ethers.Signer | FactoryOptions
97+
signerOrOptions?: ethers.Signer | DeployContractOptions
9798
): Promise<Contracts.TestContract>;
9899
deployContract(
99100
name: "TestContract1",
100101
args: any[],
101-
signerOrOptions?: ethers.Signer | FactoryOptions
102+
signerOrOptions?: ethers.Signer | DeployContractOptions
102103
): Promise<Contracts.TestContract1>;
103104
deployContract(
104105
name: "ERC20",
105106
args: any[],
106-
signerOrOptions?: ethers.Signer | FactoryOptions
107+
signerOrOptions?: ethers.Signer | DeployContractOptions
107108
): Promise<Contracts.ERC20>;
108109

109110
// default types
@@ -123,12 +124,12 @@ declare module "hardhat/types/runtime" {
123124
): Promise<ethers.Contract>;
124125
deployContract(
125126
name: string,
126-
signerOrOptions?: ethers.Signer | FactoryOptions
127+
signerOrOptions?: ethers.Signer | DeployContractOptions
127128
): Promise<ethers.Contract>;
128129
deployContract(
129130
name: string,
130131
args: any[],
131-
signerOrOptions?: ethers.Signer | FactoryOptions
132+
signerOrOptions?: ethers.Signer | DeployContractOptions
132133
): Promise<ethers.Contract>;
133134
}
134135
}

packages/target-ethers-v6/src/codegen/hardhat.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ export function generateHardhatHelper(contracts: string[]): string {
55
return `
66
77
import { ethers } from 'ethers'
8-
import { FactoryOptions, HardhatEthersHelpers as HardhatEthersHelpersBase} from "@nomicfoundation/hardhat-ethers/types";
8+
import { DeployContractOptions, FactoryOptions, HardhatEthersHelpers as HardhatEthersHelpersBase} from "@nomicfoundation/hardhat-ethers/types";
99
1010
import * as Contracts from "."
1111
@@ -29,14 +29,15 @@ declare module "hardhat/types/runtime" {
2929
3030
${contracts
3131
.map(
32-
(n) => `deployContract(name: '${n}', signerOrOptions?: ethers.Signer | FactoryOptions): Promise<Contracts.${n}>`,
32+
(n) =>
33+
`deployContract(name: '${n}', signerOrOptions?: ethers.Signer | DeployContractOptions): Promise<Contracts.${n}>`,
3334
)
3435
.join('\n')}
3536
3637
${contracts
3738
.map(
3839
(n) =>
39-
`deployContract(name: '${n}', args: any[], signerOrOptions?: ethers.Signer | FactoryOptions): Promise<Contracts.${n}>`,
40+
`deployContract(name: '${n}', args: any[], signerOrOptions?: ethers.Signer | DeployContractOptions): Promise<Contracts.${n}>`,
4041
)
4142
.join('\n')}
4243
@@ -57,12 +58,12 @@ declare module "hardhat/types/runtime" {
5758
): Promise<ethers.Contract>;
5859
deployContract(
5960
name: string,
60-
signerOrOptions?: ethers.Signer | FactoryOptions
61+
signerOrOptions?: ethers.Signer | DeployContractOptions
6162
): Promise<ethers.Contract>;
6263
deployContract(
6364
name: string,
6465
args: any[],
65-
signerOrOptions?: ethers.Signer | FactoryOptions
66+
signerOrOptions?: ethers.Signer | DeployContractOptions
6667
): Promise<ethers.Contract>;
6768
}
6869
}

pnpm-lock.yaml

Lines changed: 20 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)