Skip to content

Commit 64d18f7

Browse files
krzkaczorchmanie
andauthored
[ethers-v6] Support node16 moduleSuffix in ethers-v6 target (#863)
Co-authored-by: chmanie <code@chmanie.com>
1 parent ec6b860 commit 64d18f7

File tree

14 files changed

+1676
-21
lines changed

14 files changed

+1676
-21
lines changed

.changeset/moody-mayflies-marry.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@typechain/ethers-v6': minor
3+
---
4+
5+
Add support for ESM module resolutions using the `--node16-modules` flag in the `ethers-v6` target.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# TypeChain x Ethers-v6 example
2+
3+
Note: examples in this dir require building monorepo first
4+
5+
```sh
6+
# in the root of monorepo
7+
pnpm i
8+
pnpm build
9+
```
10+
11+
## Running
12+
13+
```sh
14+
pnpm install # it will automatically run TypeChain types generation
15+
16+
# pnpm generate-types to manually regenerate them
17+
18+
pnpm start
19+
```
Lines changed: 277 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,277 @@
1+
[
2+
3+
{
4+
"inputs": [{ "internalType": "uint256", "name": "chainId_", "type": "uint256" }],
5+
"payable": false,
6+
"stateMutability": "nonpayable",
7+
"type": "constructor"
8+
},
9+
{
10+
"anonymous": false,
11+
"inputs": [
12+
{ "indexed": true, "internalType": "address", "name": "src", "type": "address" },
13+
{ "indexed": true, "internalType": "address", "name": "guy", "type": "address" },
14+
{ "indexed": false, "internalType": "uint256", "name": "wad", "type": "uint256" }
15+
],
16+
"name": "Approval",
17+
"type": "event"
18+
},
19+
{
20+
"anonymous": true,
21+
"inputs": [
22+
{ "indexed": true, "internalType": "bytes4", "name": "sig", "type": "bytes4" },
23+
{ "indexed": true, "internalType": "address", "name": "usr", "type": "address" },
24+
{ "indexed": true, "internalType": "bytes32", "name": "arg1", "type": "bytes32" },
25+
{ "indexed": true, "internalType": "bytes32", "name": "arg2", "type": "bytes32" },
26+
{ "indexed": false, "internalType": "bytes", "name": "data", "type": "bytes" }
27+
],
28+
"name": "LogNote",
29+
"type": "event"
30+
},
31+
{
32+
"anonymous": false,
33+
"inputs": [
34+
{ "indexed": true, "internalType": "address", "name": "src", "type": "address" },
35+
{ "indexed": true, "internalType": "address", "name": "dst", "type": "address" },
36+
{ "indexed": false, "internalType": "uint256", "name": "wad", "type": "uint256" }
37+
],
38+
"name": "Transfer",
39+
"type": "event"
40+
},
41+
{
42+
"constant": true,
43+
"inputs": [],
44+
"name": "DOMAIN_SEPARATOR",
45+
"outputs": [{ "internalType": "bytes32", "name": "", "type": "bytes32" }],
46+
"payable": false,
47+
"stateMutability": "view",
48+
"type": "function"
49+
},
50+
{
51+
"constant": true,
52+
"inputs": [],
53+
"name": "PERMIT_TYPEHASH",
54+
"outputs": [{ "internalType": "bytes32", "name": "", "type": "bytes32" }],
55+
"payable": false,
56+
"stateMutability": "view",
57+
"type": "function"
58+
},
59+
{
60+
"constant": true,
61+
"inputs": [
62+
{ "internalType": "address", "name": "", "type": "address" },
63+
{ "internalType": "address", "name": "", "type": "address" }
64+
],
65+
"name": "allowance",
66+
"outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }],
67+
"payable": false,
68+
"stateMutability": "view",
69+
"type": "function"
70+
},
71+
{
72+
"constant": false,
73+
"inputs": [
74+
{ "internalType": "address", "name": "usr", "type": "address" },
75+
{ "internalType": "uint256", "name": "wad", "type": "uint256" }
76+
],
77+
"name": "approve",
78+
"outputs": [{ "internalType": "bool", "name": "", "type": "bool" }],
79+
"payable": false,
80+
"stateMutability": "nonpayable",
81+
"type": "function"
82+
},
83+
{
84+
"constant": true,
85+
"inputs": [{ "internalType": "address", "name": "", "type": "address" }],
86+
"name": "balanceOf",
87+
"outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }],
88+
"payable": false,
89+
"stateMutability": "view",
90+
"type": "function"
91+
},
92+
{
93+
"constant": false,
94+
"inputs": [
95+
{ "internalType": "address", "name": "usr", "type": "address" },
96+
{ "internalType": "uint256", "name": "wad", "type": "uint256" }
97+
],
98+
"name": "burn",
99+
"outputs": [],
100+
"payable": false,
101+
"stateMutability": "nonpayable",
102+
"type": "function"
103+
},
104+
{
105+
"constant": true,
106+
"inputs": [],
107+
"name": "decimals",
108+
"outputs": [{ "internalType": "uint8", "name": "", "type": "uint8" }],
109+
"payable": false,
110+
"stateMutability": "view",
111+
"type": "function"
112+
},
113+
{
114+
"constant": false,
115+
"inputs": [{ "internalType": "address", "name": "guy", "type": "address" }],
116+
"name": "deny",
117+
"outputs": [],
118+
"payable": false,
119+
"stateMutability": "nonpayable",
120+
"type": "function"
121+
},
122+
{
123+
"constant": false,
124+
"inputs": [
125+
{ "internalType": "address", "name": "usr", "type": "address" },
126+
{ "internalType": "uint256", "name": "wad", "type": "uint256" }
127+
],
128+
"name": "mint",
129+
"outputs": [],
130+
"payable": false,
131+
"stateMutability": "nonpayable",
132+
"type": "function"
133+
},
134+
{
135+
"constant": false,
136+
"inputs": [
137+
{ "internalType": "address", "name": "src", "type": "address" },
138+
{ "internalType": "address", "name": "dst", "type": "address" },
139+
{ "internalType": "uint256", "name": "wad", "type": "uint256" }
140+
],
141+
"name": "move",
142+
"outputs": [],
143+
"payable": false,
144+
"stateMutability": "nonpayable",
145+
"type": "function"
146+
},
147+
{
148+
"constant": true,
149+
"inputs": [],
150+
"name": "name",
151+
"outputs": [{ "internalType": "string", "name": "", "type": "string" }],
152+
"payable": false,
153+
"stateMutability": "view",
154+
"type": "function"
155+
},
156+
{
157+
"constant": true,
158+
"inputs": [{ "internalType": "address", "name": "", "type": "address" }],
159+
"name": "nonces",
160+
"outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }],
161+
"payable": false,
162+
"stateMutability": "view",
163+
"type": "function"
164+
},
165+
{
166+
"constant": false,
167+
"inputs": [
168+
{ "internalType": "address", "name": "holder", "type": "address" },
169+
{ "internalType": "address", "name": "spender", "type": "address" },
170+
{ "internalType": "uint256", "name": "nonce", "type": "uint256" },
171+
{ "internalType": "uint256", "name": "expiry", "type": "uint256" },
172+
{ "internalType": "bool", "name": "allowed", "type": "bool" },
173+
{ "internalType": "uint8", "name": "v", "type": "uint8" },
174+
{ "internalType": "bytes32", "name": "r", "type": "bytes32" },
175+
{ "internalType": "bytes32", "name": "s", "type": "bytes32" }
176+
],
177+
"name": "permit",
178+
"outputs": [],
179+
"payable": false,
180+
"stateMutability": "nonpayable",
181+
"type": "function"
182+
},
183+
{
184+
"constant": false,
185+
"inputs": [
186+
{ "internalType": "address", "name": "usr", "type": "address" },
187+
{ "internalType": "uint256", "name": "wad", "type": "uint256" }
188+
],
189+
"name": "pull",
190+
"outputs": [],
191+
"payable": false,
192+
"stateMutability": "nonpayable",
193+
"type": "function"
194+
},
195+
{
196+
"constant": false,
197+
"inputs": [
198+
{ "internalType": "address", "name": "usr", "type": "address" },
199+
{ "internalType": "uint256", "name": "wad", "type": "uint256" }
200+
],
201+
"name": "push",
202+
"outputs": [],
203+
"payable": false,
204+
"stateMutability": "nonpayable",
205+
"type": "function"
206+
},
207+
{
208+
"constant": false,
209+
"inputs": [{ "internalType": "address", "name": "guy", "type": "address" }],
210+
"name": "rely",
211+
"outputs": [],
212+
"payable": false,
213+
"stateMutability": "nonpayable",
214+
"type": "function"
215+
},
216+
{
217+
"constant": true,
218+
"inputs": [],
219+
"name": "symbol",
220+
"outputs": [{ "internalType": "string", "name": "", "type": "string" }],
221+
"payable": false,
222+
"stateMutability": "view",
223+
"type": "function"
224+
},
225+
{
226+
"constant": true,
227+
"inputs": [],
228+
"name": "totalSupply",
229+
"outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }],
230+
"payable": false,
231+
"stateMutability": "view",
232+
"type": "function"
233+
},
234+
{
235+
"constant": false,
236+
"inputs": [
237+
{ "internalType": "address", "name": "dst", "type": "address" },
238+
{ "internalType": "uint256", "name": "wad", "type": "uint256" }
239+
],
240+
"name": "transfer",
241+
"outputs": [{ "internalType": "bool", "name": "", "type": "bool" }],
242+
"payable": false,
243+
"stateMutability": "nonpayable",
244+
"type": "function"
245+
},
246+
{
247+
"constant": false,
248+
"inputs": [
249+
{ "internalType": "address", "name": "src", "type": "address" },
250+
{ "internalType": "address", "name": "dst", "type": "address" },
251+
{ "internalType": "uint256", "name": "wad", "type": "uint256" }
252+
],
253+
"name": "transferFrom",
254+
"outputs": [{ "internalType": "bool", "name": "", "type": "bool" }],
255+
"payable": false,
256+
"stateMutability": "nonpayable",
257+
"type": "function"
258+
},
259+
{
260+
"constant": true,
261+
"inputs": [],
262+
"name": "version",
263+
"outputs": [{ "internalType": "string", "name": "", "type": "string" }],
264+
"payable": false,
265+
"stateMutability": "view",
266+
"type": "function"
267+
},
268+
{
269+
"constant": true,
270+
"inputs": [{ "internalType": "address", "name": "", "type": "address" }],
271+
"name": "wards",
272+
"outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }],
273+
"payable": false,
274+
"stateMutability": "view",
275+
"type": "function"
276+
}
277+
]
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"name": "example-ethers-v6-nodenext",
3+
"private": true,
4+
"version": "0.0.1",
5+
"main": "index.js",
6+
"type": "module",
7+
"license": "MIT",
8+
"scripts": {
9+
"generate-types": "typechain --target=ethers-v6 --node16-modules 'abi/*.json'",
10+
"start": "ts-node ./src/index.ts",
11+
"typecheck": "pnpm generate-types && tsc --noEmit"
12+
},
13+
"devDependencies": {
14+
"@typechain/ethers-v6": "workspace:^0.4.3",
15+
"@types/bn.js": "^5.1.0",
16+
"ts-node": "^10.7.0",
17+
"typechain": "workspace:^8.3.1",
18+
"typescript": "^4.7"
19+
},
20+
"dependencies": {
21+
"ethers": "^6.1.0"
22+
}
23+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import { ethers } from 'ethers'
2+
3+
import { Dai__factory } from '../types/ethers-contracts/factories/Dai__factory.js'
4+
5+
const RPC_HOST = 'https://mainnet.infura.io/v3/6d6c70e65c77429482df5b64a4d0c943'
6+
const DAI_ADDRESS = '0x6B175474E89094C44Da98b954EedeAC495271d0F'
7+
const BLOCK_NUMBER = 13730326
8+
9+
async function main() {
10+
const provider = new ethers.JsonRpcProvider(RPC_HOST)
11+
const dai = Dai__factory.connect(DAI_ADDRESS, provider)
12+
const balance = await dai.balanceOf('0x70b144972C5Ef6CB941A5379240B74239c418CD4')
13+
14+
console.log(`Our DAI balance is: ${ethers.formatEther(balance)}`)
15+
16+
console.log(`Listing Transfer events for block ${BLOCK_NUMBER}`)
17+
const eventsFilter = dai.filters.Transfer()
18+
const events = await dai.queryFilter(eventsFilter, BLOCK_NUMBER, BLOCK_NUMBER)
19+
20+
for (const event of events) {
21+
console.log(`${event.args.src} -> ${event.args.dst} | ${ethers.formatEther(event.args.wad)} DAI`)
22+
}
23+
}
24+
25+
main().catch((e) => {
26+
console.error(e)
27+
process.exit(1)
28+
})
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"compilerOptions": {
3+
"lib": ["ES2018", "DOM"],
4+
"module": "NodeNext",
5+
"moduleResolution": "node16",
6+
"strict": true,
7+
"target": "ES2018",
8+
"sourceMap": true,
9+
"esModuleInterop": true,
10+
"forceConsistentCasingInFileNames": true
11+
}
12+
}

0 commit comments

Comments
 (0)