@riaskov/iohtee-abi-wrapper 3.0.1 → 3.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -21,6 +21,60 @@ Or global:
21
21
  pnpm add -g @riaskov/iohtee-abi-wrapper
22
22
  ```
23
23
 
24
+ ## Tutorial: Solidity -> JSON ABI (Hardhat 3)
25
+
26
+ ### 1. Create Hardhat 3 project
27
+
28
+ ```bash
29
+ mkdir my-contracts && cd my-contracts
30
+ pnpm init
31
+ pnpm add -D hardhat typescript tsx
32
+ pnpm hardhat --init
33
+ ```
34
+
35
+ Put your contract in `contracts/`, for example `contracts/Unidirectional.sol`.
36
+
37
+ ### 2. Compile contracts
38
+
39
+ ```bash
40
+ pnpm hardhat compile
41
+ ```
42
+
43
+ Hardhat writes artifacts to:
44
+
45
+ `artifacts/contracts/<FileName>.sol/<ContractName>.json`
46
+
47
+ Example:
48
+
49
+ `artifacts/contracts/Unidirectional.sol/Unidirectional.json`
50
+
51
+ ### 3. Extract ABI JSON
52
+
53
+ Hardhat artifact already contains `abi` field:
54
+
55
+ ```json
56
+ {
57
+ "abi": [ ... ]
58
+ }
59
+ ```
60
+
61
+ You can pass this artifact directly to `iohtee-abi-wrapper`.
62
+
63
+
64
+ ### 4. Generate wrappers
65
+
66
+ From artifact:
67
+
68
+ ```bash
69
+ iohtee-abi-wrapper -o ./generated -b viem artifacts/contracts/Unidirectional.sol/Unidirectional.json
70
+ ```
71
+
72
+ From pure ABI folder:
73
+
74
+ ```bash
75
+ iohtee-abi-wrapper -o ./generated -b viem ./abi
76
+ ```
77
+
24
78
  ## CLI usage
25
79
 
26
80
  ```bash
@@ -71,3 +125,80 @@ pnpm --filter @riaskov/iohtee-abi-wrapper run build
71
125
  ## Output
72
126
 
73
127
  For `Unidirectional.json`, generator emits `UnidirectionalContract` wrapper and typings.
128
+
129
+ ## Usage examples
130
+
131
+ ### Unidirectional + viem backend
132
+
133
+ ```ts
134
+ // generated with:
135
+ // iohtee-abi-wrapper -o ./generated-viem -b viem ./abi/Unidirectional.json
136
+ import {
137
+ UnidirectionalContract,
138
+ UnidirectionalEventName,
139
+ } from './generated-viem/UnidirectionalContract.js'
140
+
141
+ const contract = new UnidirectionalContract(
142
+ '0x1111111111111111111111111111111111111111',
143
+ {
144
+ httpRpcUrl: 'http://127.0.0.1:8545',
145
+ networkId: 31337,
146
+ mnemonic: 'test test test test test test test test test test test junk',
147
+ hdPath: "m/44'/60'/0'/0/0",
148
+ },
149
+ )
150
+
151
+ const channelId =
152
+ '0xaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa',
153
+
154
+ // view call
155
+ const canDeposit = await contract.canDeposit(
156
+ channelId,
157
+ '0x2222222222222222222222222222222222222222',
158
+ )
159
+ console.log('canDeposit:', canDeposit)
160
+
161
+ // state-changing call
162
+ const receipt = await contract.deposit(channelId, { value: 1_000_000_000_000n })
163
+ const hasDepositEvent = UnidirectionalContract.hasEvent(
164
+ receipt,
165
+ UnidirectionalEventName.DidDeposit,
166
+ )
167
+ console.log('DidDeposit emitted:', hasDepositEvent)
168
+ ```
169
+
170
+ ### Unidirectional + ethers backend
171
+
172
+ ```ts
173
+ // generated with:
174
+ // iohtee-abi-wrapper -o ./generated-ethers -b ethers ./abi/Unidirectional.json
175
+ import {
176
+ UnidirectionalContract,
177
+ UnidirectionalEventName,
178
+ } from './generated-ethers/UnidirectionalContract.js'
179
+
180
+ const contract = new UnidirectionalContract(
181
+ '0x1111111111111111111111111111111111111111',
182
+ {
183
+ httpRpcUrl: 'http://127.0.0.1:8545',
184
+ networkId: 31337,
185
+ mnemonic: 'test test test test test test test test test test test junk',
186
+ hdPath: "m/44'/60'/0'/0/0",
187
+ },
188
+ )
189
+
190
+ const channelId =
191
+ '0xaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa',
192
+
193
+ // view call
194
+ const digest = await contract.paymentDigest(channelId, 10n)
195
+ console.log('paymentDigest:', digest)
196
+
197
+ // state-changing call
198
+ const receipt = await contract.deposit(channelId, { value: 1_000_000_000_000n })
199
+ const hasDepositEvent = UnidirectionalContract.hasEvent(
200
+ receipt,
201
+ UnidirectionalEventName.DidDeposit,
202
+ )
203
+ console.log('DidDeposit emitted:', hasDepositEvent)
204
+ ```
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@riaskov/iohtee-abi-wrapper",
3
- "version": "3.0.1",
3
+ "version": "3.0.3",
4
4
  "description": "Generate TypeScript wrapper class for Solidity smart contract ABI",
5
5
  "license": "Apache-2.0",
6
6
  "author": "Machinomy Team <hello@machinomy.com>",
@@ -36,6 +36,14 @@
36
36
  "main": "dist/index.js",
37
37
  "types": "dist/index.d.ts",
38
38
  "bin": "dist/bin/iohtee-abi-wrapper.js",
39
+ "exports": {
40
+ ".": {
41
+ "types": "./dist/index.d.ts",
42
+ "import": "./dist/index.js",
43
+ "require": "./dist/index.js",
44
+ "default": "./dist/index.js"
45
+ }
46
+ },
39
47
  "files": [
40
48
  "dist/",
41
49
  "templates/"
@@ -1,3 +1,5 @@
1
+ /* eslint-disable */
2
+ /* tslint:disable */
1
3
  import { Interface, TransactionReceipt, type InterfaceAbi } from 'ethers'
2
4
  import {
3
5
  BaseContractEthers,
@@ -1,3 +1,5 @@
1
+ /* eslint-disable */
2
+ /* tslint:disable */
1
3
  import {
2
4
  TransactionReceipt,
3
5
  parseEventLogs,