quantumcoin 7.0.1 → 7.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/.gitignore +3 -0
- package/README-SDK.md +64 -10
- package/README.md +27 -4
- package/SPEC.md +3843 -0
- package/examples/AllSolidityTypes.sol +184 -0
- package/examples/SimpleIERC20.sol +74 -0
- package/examples/example-generator-sdk-js.js +95 -0
- package/examples/example-generator-sdk-ts.js +95 -0
- package/examples/example.js +2 -2
- package/examples/offline-signing.js +73 -0
- package/examples/package-lock.json +10 -1103
- package/examples/package.json +1 -2
- package/examples/read-operations.js +1 -2
- package/examples/sdk-generator-erc20.inline.json +251 -0
- package/examples/solidity-types.ts +43 -0
- package/generate-sdk.js +689 -87
- package/package.json +30 -9
- package/src/abi/interface.d.ts +18 -0
- package/src/abi/interface.js +247 -9
- package/src/abi/js-abi-coder.js +474 -0
- package/src/contract/contract-factory.d.ts +1 -1
- package/src/contract/contract-factory.js +14 -2
- package/src/contract/contract.d.ts +10 -1
- package/src/contract/contract.js +42 -0
- package/src/generator/index.js +1041 -63
- package/src/index.d.ts +16 -0
- package/src/providers/provider.d.ts +20 -11
- package/src/providers/provider.js +12 -0
- package/src/types/index.d.ts +462 -0
- package/src/types/index.js +9 -0
- package/test/e2e/all-solidity-types.dynamic.test.js +200 -0
- package/test/e2e/all-solidity-types.fixtures.js +231 -0
- package/test/e2e/all-solidity-types.generated-sdks.e2e.test.js +368 -0
- package/test/e2e/simple-erc20.generated-sdks.e2e.test.js +151 -0
- package/test/e2e/transactional.test.js +4 -4
- package/test/e2e/typed-generator.e2e.test.js +8 -6
- package/test/integration/ws-provider.test.js +1 -1
- package/test/unit/generate-contract-cli.test.js +2 -1
- package/test/unit/generate-sdk-artifacts-json.test.js +45 -0
- package/test/unit/generator.test.js +1 -0
- package/test/unit/populate-transaction.test.js +62 -0
- package/test/unit/solidity-types.test.js +46 -0
- package/test/unit/utils.test.js +1 -1
package/SPEC.md
ADDED
|
@@ -0,0 +1,3843 @@
|
|
|
1
|
+
> **CAUTION:** This is an experimental SDK. Use at your own risk.
|
|
2
|
+
|
|
3
|
+
# QuantumCoin.js - Ethers.js v6 Compatible API Specification
|
|
4
|
+
|
|
5
|
+
## Overview
|
|
6
|
+
|
|
7
|
+
This specification defines the requirements for implementing a QuantumCoin SDK that provides an ethers.js v6-compatible API. The implementation should follow the same object model pattern as ethers.js v6, while using quantum-coin-js-sdk for underlying functionality (ABI encoding/decoding, signing, address validation, etc.).
|
|
8
|
+
|
|
9
|
+
## Key Differences from Ethereum
|
|
10
|
+
|
|
11
|
+
1. **Address Format**: QuantumCoin addresses are 32 bytes (66 hex characters including 0x), not 20 bytes like Ethereum
|
|
12
|
+
2. **No HDWallet Support**: HDWallet functionality is not applicable for QuantumCoin
|
|
13
|
+
3. **RPC Endpoint**: Uses custom RPC endpoint format (stored in Config.rpcEndpoint)
|
|
14
|
+
4. **Chain ID**: Default chain ID is 123123 (mainnet)
|
|
15
|
+
|
|
16
|
+
## Core Principles
|
|
17
|
+
|
|
18
|
+
- Use only built-in JavaScript/Node.js libraries (no external dependencies except quantum-coin-js-sdk)
|
|
19
|
+
- Follow ethers.js v6 object model and API patterns
|
|
20
|
+
- All cryptographic operations, signing, and address validation must use quantum-coin-js-sdk
|
|
21
|
+
- Maintain compatibility with ethers.js v6 patterns for ease of migration
|
|
22
|
+
|
|
23
|
+
---
|
|
24
|
+
|
|
25
|
+
## Constants
|
|
26
|
+
|
|
27
|
+
### `version: string`
|
|
28
|
+
The current version of the QuantumCoin.js library.
|
|
29
|
+
- Type: `string`
|
|
30
|
+
- Example: `"1.0.0"`
|
|
31
|
+
|
|
32
|
+
### `ZeroAddress: string`
|
|
33
|
+
The zero address (all zeros).
|
|
34
|
+
- Type: `string`
|
|
35
|
+
- Value: `"0x0000000000000000000000000000000000000000000000000000000000000000"` (32 bytes, 66 hex characters)
|
|
36
|
+
- **Note**: The API matches ethers.js v6 ZeroAddress. For QuantumCoin, this is a 32-byte address.
|
|
37
|
+
|
|
38
|
+
### `ZeroHash: string`
|
|
39
|
+
The zero hash (all zeros).
|
|
40
|
+
- Type: `string`
|
|
41
|
+
- Value: `"0x0000000000000000000000000000000000000000000000000000000000000000"` (32 bytes, 66 hex characters)
|
|
42
|
+
- **Note**: The API matches ethers.js v6 ZeroHash.
|
|
43
|
+
|
|
44
|
+
### `MaxUint256: bigint`
|
|
45
|
+
The maximum value for a uint256.
|
|
46
|
+
- Type: `bigint`
|
|
47
|
+
- Value: `2n ** 256n - 1n`
|
|
48
|
+
- **Note**: The API matches ethers.js v6 MaxUint256.
|
|
49
|
+
|
|
50
|
+
### `MaxUint160: bigint`
|
|
51
|
+
The maximum value for a uint160.
|
|
52
|
+
- Type: `bigint`
|
|
53
|
+
- Value: `2n ** 160n - 1n`
|
|
54
|
+
- **Note**: The API matches ethers.js v6 MaxUint160.
|
|
55
|
+
|
|
56
|
+
### `MinInt256: bigint`
|
|
57
|
+
The minimum value for an int256.
|
|
58
|
+
- Type: `bigint`
|
|
59
|
+
- Value: `-(2n ** 255n)`
|
|
60
|
+
- **Note**: The API matches ethers.js v6 MinInt256.
|
|
61
|
+
|
|
62
|
+
### `MaxInt256: bigint`
|
|
63
|
+
The maximum value for an int256.
|
|
64
|
+
- Type: `bigint`
|
|
65
|
+
- Value: `2n ** 255n - 1n`
|
|
66
|
+
- **Note**: The API matches ethers.js v6 MaxInt256.
|
|
67
|
+
|
|
68
|
+
### `NumericFault: string`
|
|
69
|
+
Error code for numeric faults.
|
|
70
|
+
- Type: `string`
|
|
71
|
+
- Value: `"NUMERIC_FAULT"`
|
|
72
|
+
- **Note**: The API matches ethers.js v6 NumericFault.
|
|
73
|
+
|
|
74
|
+
### `NumericFaultCode: string`
|
|
75
|
+
Error code for numeric faults (alias).
|
|
76
|
+
- Type: `string`
|
|
77
|
+
- Value: `"NUMERIC_FAULT"`
|
|
78
|
+
- **Note**: The API matches ethers.js v6 NumericFaultCode.
|
|
79
|
+
|
|
80
|
+
### `WeiPerEther: bigint`
|
|
81
|
+
Wei per ether constant.
|
|
82
|
+
- Type: `bigint`
|
|
83
|
+
- Value: `1000000000000000000n` (1e18)
|
|
84
|
+
- **Note**: The API matches ethers.js v6 WeiPerEther.
|
|
85
|
+
|
|
86
|
+
### `EtherSymbol: string`
|
|
87
|
+
Symbol for Ether currency.
|
|
88
|
+
- Type: `string`
|
|
89
|
+
- Value: `"Ξ"`
|
|
90
|
+
- **Note**: The API matches ethers.js v6 EtherSymbol.
|
|
91
|
+
|
|
92
|
+
### `N: bigint`
|
|
93
|
+
BigNumber constant (exported as `N`).
|
|
94
|
+
- Type: `bigint`
|
|
95
|
+
- **Note**: The API matches ethers.js v6 N constant.
|
|
96
|
+
|
|
97
|
+
---
|
|
98
|
+
|
|
99
|
+
## Table of Contents
|
|
100
|
+
|
|
101
|
+
- [Overview](#overview)
|
|
102
|
+
- [Key Differences from Ethereum](#key-differences-from-ethereum)
|
|
103
|
+
- [Core Principles](#core-principles)
|
|
104
|
+
- [Constants](#constants)
|
|
105
|
+
- [1. Provider Classes](#1-provider-classes)
|
|
106
|
+
- [1.1 AbstractProvider](#11-abstractprovider)
|
|
107
|
+
- [1.2 JsonRpcProvider](#12-jsonrpcprovider)
|
|
108
|
+
- [1.3 Block](#13-block)
|
|
109
|
+
- [1.4 TransactionRequest](#14-transactionrequest)
|
|
110
|
+
- [1.5 TransactionResponse](#15-transactionresponse)
|
|
111
|
+
- [1.6 TransactionReceipt](#16-transactionreceipt)
|
|
112
|
+
- [1.7 Log](#17-log)
|
|
113
|
+
- [1.8 Filter](#18-filter)
|
|
114
|
+
- [1.9 PollingBlockTagSubscriber](#19-pollingblocktagsubscriber)
|
|
115
|
+
- [1.10 WebSocketProvider](#110-websocketprovider)
|
|
116
|
+
- [1.11 IpcSocketProvider](#111-ipcsocketprovider)
|
|
117
|
+
- [1.12 FallbackProvider](#112-fallbackprovider)
|
|
118
|
+
- [1.13 BrowserProvider](#113-browserprovider)
|
|
119
|
+
- [1.14 FilterByBlockHash](#114-filterbyblockhash)
|
|
120
|
+
- [2. Wallet Classes](#2-wallet-classes)
|
|
121
|
+
- [2.1 AbstractSigner](#21-abstractsigner)
|
|
122
|
+
- [2.2 BaseWallet](#22-basewallet)
|
|
123
|
+
- [2.3 NonceManager](#23-noncemanager)
|
|
124
|
+
- [2.4 Wallet](#24-wallet)
|
|
125
|
+
- [2.5 JsonRpcSigner](#25-jsonrpcsigner)
|
|
126
|
+
- [2.6 VoidSigner](#26-voidsigner)
|
|
127
|
+
- [3. Contract Classes](#3-contract-classes)
|
|
128
|
+
- [3.1 BaseContract](#31-basecontract)
|
|
129
|
+
- [3.2 Contract](#32-contract)
|
|
130
|
+
- [3.3 ContractFactory](#33-contractfactory)
|
|
131
|
+
- [3.4 ContractTransactionResponse](#34-contracttransactionresponse)
|
|
132
|
+
- [3.5 ContractTransactionReceipt](#35-contracttransactionreceipt)
|
|
133
|
+
- [3.6 EventLog](#36-eventlog)
|
|
134
|
+
- [4. Interface and ABI Classes](#4-interface-and-abi-classes)
|
|
135
|
+
- [4.1 Interface](#41-interface)
|
|
136
|
+
- [4.2 Fragment (Base Class)](#42-fragment-base-class)
|
|
137
|
+
- [4.3 AbiFragment](#43-abifragment)
|
|
138
|
+
- [4.4 FunctionFragment](#44-functionfragment)
|
|
139
|
+
- [4.5 EventFragment](#45-eventfragment)
|
|
140
|
+
- [4.6 AbiParameter](#46-abiparameter)
|
|
141
|
+
- [4.7 TransactionDescription](#47-transactiondescription)
|
|
142
|
+
- [4.8 LogDescription](#48-logdescription)
|
|
143
|
+
- [4.9 ErrorFragment](#49-errorfragment)
|
|
144
|
+
- [4.10 ErrorDescription](#410-errordescription)
|
|
145
|
+
- [4.11 ConstructorFragment](#411-constructorfragment)
|
|
146
|
+
- [4.12 ParamType](#412-paramtype)
|
|
147
|
+
- [4.13 AbiCoder](#413-abicoder)
|
|
148
|
+
- [4.14 StructFragment](#414-structfragment)
|
|
149
|
+
- [4.15 FallbackFragment](#415-fallbackfragment)
|
|
150
|
+
- [5. Utility Classes and Functions](#5-utility-classes-and-functions)
|
|
151
|
+
- [5.1 Result](#51-result)
|
|
152
|
+
- [5.2 BytesLike](#52-byteslike)
|
|
153
|
+
- [5.3 BigNumberish](#53-bignumberish)
|
|
154
|
+
- [5.3.1 AddressLike](#531-addresslike)
|
|
155
|
+
- [5.3.2 Typed Values](#532-typed-values)
|
|
156
|
+
- [5.3.3 BlockTag](#533-blocktag)
|
|
157
|
+
- [5.3.4 ProviderEventFilter](#534-providereventfilter)
|
|
158
|
+
- [5.3.5 EventFilter](#535-eventfilter)
|
|
159
|
+
- [5.3.6 SigningKey](#536-signingkey)
|
|
160
|
+
- [5.3.7 Signature](#537-signature)
|
|
161
|
+
- [5.3.8 Transaction](#538-transaction)
|
|
162
|
+
- [5.3.9 Indexed](#539-indexed)
|
|
163
|
+
- [5.3.10 KeystoreAccount](#5310-keystoreaccount)
|
|
164
|
+
- [5.4 Address Utilities](#54-address-utilities)
|
|
165
|
+
- [5.4.1 Addressable Interface](#541-addressable-interface)
|
|
166
|
+
- [5.5 Encoding/Decoding Utilities](#55-encodingdecoding-utilities)
|
|
167
|
+
- [5.6 BigNumber Utilities](#56-bignumber-utilities)
|
|
168
|
+
- [5.7 Hash Utilities](#57-hash-utilities)
|
|
169
|
+
- [5.8 Random Utilities](#58-random-utilities)
|
|
170
|
+
- [5.9 RLP Encoding](#59-rlp-encoding)
|
|
171
|
+
- [5.10 Provider Utility Functions](#510-provider-utility-functions)
|
|
172
|
+
- [5.11 JSON Wallet Utilities](#511-json-wallet-utilities)
|
|
173
|
+
- [5.12 Mnemonic](#512-mnemonic)
|
|
174
|
+
- [5.13 Wordlist](#513-wordlist)
|
|
175
|
+
- [6. Network and Plugins](#6-network-and-plugins)
|
|
176
|
+
- [6.1 Network](#61-network)
|
|
177
|
+
- [6.2 Networkish](#62-networkish)
|
|
178
|
+
- [6.3 NetworkPlugin (Base Interface)](#63-networkplugin-base-interface)
|
|
179
|
+
- [6.4 GasCostPlugin](#64-gascostplugin)
|
|
180
|
+
- [7. Error Classes](#7-error-classes)
|
|
181
|
+
- [7.1 Error](#71-error)
|
|
182
|
+
- [7.2 ProviderError](#72-providererror)
|
|
183
|
+
- [7.3 TransactionError](#73-transactionerror)
|
|
184
|
+
- [7.4 ContractError](#74-contracterror)
|
|
185
|
+
- [8. Provider Types and Interfaces](#8-provider-types-and-interfaces)
|
|
186
|
+
- [8.1 PreparedTransactionRequest](#81-preparedtransactionrequest)
|
|
187
|
+
- [8.2 MinedBlock](#82-minedblock)
|
|
188
|
+
- [8.3 MinedTransactionResponse](#83-minedtransactionresponse)
|
|
189
|
+
- [8.4 FeeData](#84-feedata)
|
|
190
|
+
- [8.5 WebSocketLike](#85-websocketlike)
|
|
191
|
+
- [8.6 ProviderEvent](#86-providerevent)
|
|
192
|
+
- [8.7 TopicFilter](#87-topicfilter)
|
|
193
|
+
- [9. Provider Interface](#9-provider-interface)
|
|
194
|
+
- [9.1 Provider (Abstract Base Class)](#91-provider-abstract-base-class)
|
|
195
|
+
- [9.2 ContractRunner (Abstract Base Class/Interface)](#92-contractrunner-abstract-base-classinterface)
|
|
196
|
+
- [9.3 Signer (Abstract Base Class)](#93-signer-abstract-base-class)
|
|
197
|
+
- [10. Implementation Requirements](#10-implementation-requirements)
|
|
198
|
+
- [10.1 Quantum-Coin-JS-SDK Integration](#101-quantum-coin-js-sdk-integration)
|
|
199
|
+
- [10.2 Built-in Libraries Only](#102-built-in-libraries-only)
|
|
200
|
+
- [10.3 Address Format Handling](#103-address-format-handling)
|
|
201
|
+
- [10.4 Error Handling](#104-error-handling)
|
|
202
|
+
- [10.5 Event Handling](#105-event-handling)
|
|
203
|
+
- [10.6 Transaction Handling](#106-transaction-handling)
|
|
204
|
+
- [10.7 ABI Handling](#107-abi-handling)
|
|
205
|
+
- [10.8 Async/Await Pattern](#108-asyncawait-pattern)
|
|
206
|
+
- [10.9 Type Safety](#109-type-safety)
|
|
207
|
+
- [11. File Structure](#11-file-structure)
|
|
208
|
+
- [12. Example Usage Patterns](#12-example-usage-patterns)
|
|
209
|
+
- [12.1 Provider Usage](#121-provider-usage)
|
|
210
|
+
- [12.2 Wallet Usage](#122-wallet-usage)
|
|
211
|
+
- [12.3 Contract Usage](#123-contract-usage)
|
|
212
|
+
- [12.4 Contract Deployment](#124-contract-deployment)
|
|
213
|
+
- [13. Testing Requirements](#13-testing-requirements)
|
|
214
|
+
- [14. Documentation Requirements](#14-documentation-requirements)
|
|
215
|
+
- [15. Typed Contract Generator](#15-typed-contract-generator)
|
|
216
|
+
- [Notes](#notes)
|
|
217
|
+
|
|
218
|
+
---
|
|
219
|
+
|
|
220
|
+
## 1. Provider Classes
|
|
221
|
+
|
|
222
|
+
### 1.1 AbstractProvider
|
|
223
|
+
|
|
224
|
+
**Purpose**: Abstract base class for all providers
|
|
225
|
+
|
|
226
|
+
**Extends**: Provider
|
|
227
|
+
|
|
228
|
+
**Note**: This is an internal base class. All concrete providers (JsonRpcProvider, WebSocketProvider, etc.) extend this class. The API matches ethers.js v6 AbstractProvider.
|
|
229
|
+
|
|
230
|
+
---
|
|
231
|
+
|
|
232
|
+
### 1.2 JsonRpcProvider
|
|
233
|
+
|
|
234
|
+
**Purpose**: Provides JSON-RPC interface to QuantumCoin blockchain
|
|
235
|
+
|
|
236
|
+
**Extends**: AbstractProvider
|
|
237
|
+
|
|
238
|
+
**Note**: The API matches ethers.js v6 JsonRpcProvider. All methods, properties, and behavior follow the same patterns as ethers.js v6.
|
|
239
|
+
|
|
240
|
+
**Constructor**:
|
|
241
|
+
```javascript
|
|
242
|
+
constructor(url?: string, chainId?: number)
|
|
243
|
+
```
|
|
244
|
+
- `url`: RPC endpoint URL (defaults to Config.rpcEndpoint or "https://public.rpc.quantumcoinapi.com")
|
|
245
|
+
- `chainId`: Chain ID (defaults to 123123)
|
|
246
|
+
|
|
247
|
+
**Properties**:
|
|
248
|
+
- `url`: string - RPC endpoint URL
|
|
249
|
+
- `chainId`: number - Chain ID
|
|
250
|
+
|
|
251
|
+
**Methods**:
|
|
252
|
+
|
|
253
|
+
#### `getBlockNumber(): Promise<number>`
|
|
254
|
+
Returns the latest block number.
|
|
255
|
+
|
|
256
|
+
#### `getBlock(blockNumber: number | "latest"): Promise<Block>`
|
|
257
|
+
Returns block information.
|
|
258
|
+
- `blockNumber`: Block number or "latest"
|
|
259
|
+
|
|
260
|
+
#### `getTransaction(txHash: string): Promise<TransactionResponse>`
|
|
261
|
+
Returns transaction details.
|
|
262
|
+
- `txHash`: Transaction hash (66 hex characters)
|
|
263
|
+
|
|
264
|
+
#### `getTransactionReceipt(txHash: string): Promise<TransactionReceipt>`
|
|
265
|
+
Returns transaction receipt.
|
|
266
|
+
- `txHash`: Transaction hash
|
|
267
|
+
|
|
268
|
+
#### `getBalance(address: string): Promise<bigint>`
|
|
269
|
+
Returns account balance in wei.
|
|
270
|
+
- `address`: 32-byte address (66 hex characters)
|
|
271
|
+
|
|
272
|
+
#### `getTransactionCount(address: string, blockTag?: string): Promise<number>`
|
|
273
|
+
Returns account nonce.
|
|
274
|
+
- `address`: 32-byte address
|
|
275
|
+
- `blockTag`: Optional block tag (default: "latest")
|
|
276
|
+
|
|
277
|
+
#### `sendTransaction(tx: TransactionRequest): Promise<TransactionResponse>`
|
|
278
|
+
Sends a signed transaction.
|
|
279
|
+
- `tx`: Transaction request object
|
|
280
|
+
|
|
281
|
+
#### `call(tx: TransactionRequest, blockTag?: string): Promise<string>`
|
|
282
|
+
Executes a call without creating a transaction.
|
|
283
|
+
- `tx`: Transaction request
|
|
284
|
+
- `blockTag`: Optional block tag
|
|
285
|
+
|
|
286
|
+
#### `estimateGas(tx: TransactionRequest): Promise<bigint>`
|
|
287
|
+
Estimates gas for a transaction.
|
|
288
|
+
- `tx`: Transaction request
|
|
289
|
+
|
|
290
|
+
#### `getCode(address: string, blockTag?: string): Promise<string>`
|
|
291
|
+
Returns contract bytecode.
|
|
292
|
+
- `address`: Contract address
|
|
293
|
+
- `blockTag`: Optional block tag
|
|
294
|
+
|
|
295
|
+
#### `getStorageAt(address: string, position: bigint, blockTag?: string): Promise<string>`
|
|
296
|
+
Returns storage value at position.
|
|
297
|
+
- `address`: Contract address
|
|
298
|
+
- `position`: Storage position
|
|
299
|
+
- `blockTag`: Optional block tag
|
|
300
|
+
|
|
301
|
+
#### `getLogs(filter: Filter): Promise<Log[]>`
|
|
302
|
+
Returns event logs matching filter.
|
|
303
|
+
- `filter`: Event filter object
|
|
304
|
+
|
|
305
|
+
#### `on(event: string, callback: Function): void`
|
|
306
|
+
Subscribes to events (block, pending, etc.).
|
|
307
|
+
- `event`: Event name
|
|
308
|
+
- `callback`: Callback function
|
|
309
|
+
|
|
310
|
+
#### `once(event: string, callback: Function): void`
|
|
311
|
+
Subscribes to event once.
|
|
312
|
+
- `event`: Event name
|
|
313
|
+
- `callback`: Callback function
|
|
314
|
+
|
|
315
|
+
#### `removeListener(event: string, callback: Function): void`
|
|
316
|
+
Removes event listener.
|
|
317
|
+
- `event`: Event name
|
|
318
|
+
- `callback`: Callback function
|
|
319
|
+
|
|
320
|
+
#### `removeAllListeners(event?: string): void`
|
|
321
|
+
Removes all listeners for event.
|
|
322
|
+
- `event`: Optional event name
|
|
323
|
+
|
|
324
|
+
---
|
|
325
|
+
|
|
326
|
+
### 1.2.1 JsonRpcApiProvider
|
|
327
|
+
|
|
328
|
+
**Purpose**: Base class for JSON-RPC API providers
|
|
329
|
+
|
|
330
|
+
**Extends**: AbstractProvider
|
|
331
|
+
|
|
332
|
+
**Note**: This is an internal base class that provides the core JSON-RPC API functionality. JsonRpcProvider extends this class. The API matches ethers.js v6 JsonRpcApiProvider.
|
|
333
|
+
|
|
334
|
+
---
|
|
335
|
+
|
|
336
|
+
### 1.3 Block
|
|
337
|
+
|
|
338
|
+
**Properties**:
|
|
339
|
+
- `number`: number - Block number
|
|
340
|
+
- `hash`: string | null - Block hash (66 hex characters, null for pending blocks)
|
|
341
|
+
- `timestamp`: number - Block timestamp
|
|
342
|
+
- `transactions`: string[] | TransactionResponse[] - Array of transaction hashes or full transaction objects
|
|
343
|
+
- `parentHash`: string - Parent block hash
|
|
344
|
+
- `gasLimit`: bigint - Gas limit
|
|
345
|
+
- `gasUsed`: bigint - Gas used
|
|
346
|
+
- `miner`: string - Miner coinbase address (32 bytes, 66 hex characters)
|
|
347
|
+
- `difficulty`: bigint - Difficulty target
|
|
348
|
+
- `nonce`: string - Block nonce
|
|
349
|
+
- `extraData`: string - Extra data included by validator
|
|
350
|
+
- `receiptsRoot`: string | null - Hash of the transaction receipts trie
|
|
351
|
+
- `date`: Date | null - Date object for block timestamp
|
|
352
|
+
- `length`: number - Number of transactions in block
|
|
353
|
+
- `provider: Provider | null` - Provider instance
|
|
354
|
+
|
|
355
|
+
**Methods**:
|
|
356
|
+
|
|
357
|
+
#### `getTransaction(indexOrHash: number | string): Promise<TransactionResponse | null>`
|
|
358
|
+
Gets a transaction from the block.
|
|
359
|
+
- `indexOrHash`: Transaction index or hash
|
|
360
|
+
- Returns: TransactionResponse or null if not found
|
|
361
|
+
|
|
362
|
+
#### `getTransactionReceipt(indexOrHash: number | string): Promise<TransactionReceipt | null>`
|
|
363
|
+
Gets a transaction receipt from the block.
|
|
364
|
+
- `indexOrHash`: Transaction index or hash
|
|
365
|
+
- Returns: TransactionReceipt or null if not found
|
|
366
|
+
|
|
367
|
+
#### `getPrefetchedTransactions(): TransactionResponse[]`
|
|
368
|
+
Returns prefetched transaction objects (if available).
|
|
369
|
+
- Returns: Array of TransactionResponse objects
|
|
370
|
+
|
|
371
|
+
**Note**: Some properties may be null for pending blocks. The `transactions` property can be either an array of hashes (when fetched with `getBlock(blockNumber)`) or full transaction objects (when fetched with `getBlock(blockNumber, true)`).
|
|
372
|
+
|
|
373
|
+
---
|
|
374
|
+
|
|
375
|
+
### 1.4 TransactionRequest
|
|
376
|
+
|
|
377
|
+
**Properties**:
|
|
378
|
+
- `to`: string | null - Recipient address (null for contract creation)
|
|
379
|
+
- `from`: string - Sender address
|
|
380
|
+
- `value`: bigint | string - Value in wei
|
|
381
|
+
- `data`: string - Transaction data (hex string)
|
|
382
|
+
- `gasLimit`: bigint | string - Gas limit
|
|
383
|
+
- `gasPrice`: bigint | string - Gas price
|
|
384
|
+
- `nonce`: number - Transaction nonce
|
|
385
|
+
- `chainId`: number - Chain ID
|
|
386
|
+
- `remarks`: string | null - Optional hex string (including 0x) that represents a remark/comment. Maximum 32 bytes length (in bytes). Warning: do not store any sensitive information in this field as it will be public on the blockchain.
|
|
387
|
+
- `type?: number` - Transaction type
|
|
388
|
+
- `accessList?: Array<{address: string, storageKeys: string[]}>` - Access list (EIP-2930)
|
|
389
|
+
|
|
390
|
+
---
|
|
391
|
+
|
|
392
|
+
### 1.5 TransactionResponse
|
|
393
|
+
|
|
394
|
+
**Properties**:
|
|
395
|
+
- `hash`: string - Transaction hash
|
|
396
|
+
- `to`: string | null - Recipient address
|
|
397
|
+
- `from`: string - Sender address
|
|
398
|
+
- `value`: bigint - Value in wei
|
|
399
|
+
- `data`: string - Transaction data
|
|
400
|
+
- `gasLimit`: bigint - Gas limit
|
|
401
|
+
- `gasPrice`: bigint | null - Gas price
|
|
402
|
+
- `nonce`: number - Nonce
|
|
403
|
+
- `chainId`: number - Chain ID
|
|
404
|
+
- `remarks`: string | null - Optional hex string (including 0x) that represents a remark/comment. Maximum 32 bytes length (in bytes). Warning: do not store any sensitive information in this field as it will be public on the blockchain.
|
|
405
|
+
- `blockNumber`: number | null - Block number
|
|
406
|
+
- `blockHash`: string | null - Block hash
|
|
407
|
+
- `provider: Provider | null` - Provider instance
|
|
408
|
+
- `index: number | null` - Transaction index in block
|
|
409
|
+
- `type: number | null` - Transaction type
|
|
410
|
+
- `accessList: Array<{address: string, storageKeys: string[]}> | null` - Access list
|
|
411
|
+
|
|
412
|
+
**Methods**:
|
|
413
|
+
|
|
414
|
+
#### `wait(confirmations?: number, timeout?: number): Promise<TransactionReceipt>`
|
|
415
|
+
Waits for transaction confirmation.
|
|
416
|
+
- `confirmations`: Optional number of confirmations to wait for
|
|
417
|
+
- `timeout`: Optional timeout in milliseconds
|
|
418
|
+
|
|
419
|
+
---
|
|
420
|
+
|
|
421
|
+
### 1.6 TransactionReceipt
|
|
422
|
+
|
|
423
|
+
**Properties**:
|
|
424
|
+
- `hash`: string - Transaction hash
|
|
425
|
+
- `blockNumber`: number - Block number
|
|
426
|
+
- `blockHash`: string - Block hash
|
|
427
|
+
- `transactionIndex`: number - Transaction index in block
|
|
428
|
+
- `from`: string - Sender address
|
|
429
|
+
- `to`: string | null - Recipient address
|
|
430
|
+
- `gasUsed`: bigint - Gas used
|
|
431
|
+
- `effectiveGasPrice`: bigint - Effective gas price
|
|
432
|
+
- `status`: number - Transaction status (1 = success, 0 = failure)
|
|
433
|
+
- `remarks`: string | null - Optional hex string (including 0x) that represents a remark/comment from the transaction. Maximum 32 bytes length (in bytes). Warning: do not store any sensitive information in this field as it will be public on the blockchain.
|
|
434
|
+
- `logs`: Log[] - Event logs
|
|
435
|
+
- `logsBloom`: string - Logs bloom filter
|
|
436
|
+
- `provider: Provider | null` - Provider instance
|
|
437
|
+
- `contractAddress: string | null` - Contract address if transaction created a contract
|
|
438
|
+
- `type: number | null` - Transaction type
|
|
439
|
+
- `root: string | null` - State root (pre-Byzantium)
|
|
440
|
+
- `cumulativeGasUsed: bigint` - Cumulative gas used in block
|
|
441
|
+
|
|
442
|
+
---
|
|
443
|
+
|
|
444
|
+
### 1.7 Log
|
|
445
|
+
|
|
446
|
+
**Properties**:
|
|
447
|
+
- `address`: string - Contract address
|
|
448
|
+
- `topics`: string[] - Event topics
|
|
449
|
+
- `data`: string - Log data
|
|
450
|
+
- `blockNumber`: number - Block number
|
|
451
|
+
- `blockHash`: string - Block hash
|
|
452
|
+
- `transactionHash`: string - Transaction hash
|
|
453
|
+
- `transactionIndex`: number - Transaction index
|
|
454
|
+
- `logIndex`: number - Log index
|
|
455
|
+
- `removed`: boolean - Whether log was removed
|
|
456
|
+
- `provider: Provider | null` - Provider instance
|
|
457
|
+
|
|
458
|
+
**Methods**:
|
|
459
|
+
|
|
460
|
+
#### `getBlock(): Promise<Block | null>`
|
|
461
|
+
Gets block containing log.
|
|
462
|
+
- Returns: Block or null
|
|
463
|
+
|
|
464
|
+
#### `getTransaction(): Promise<TransactionResponse | null>`
|
|
465
|
+
Gets transaction containing log.
|
|
466
|
+
- Returns: TransactionResponse or null
|
|
467
|
+
|
|
468
|
+
#### `getTransactionReceipt(): Promise<TransactionReceipt | null>`
|
|
469
|
+
Gets transaction receipt.
|
|
470
|
+
- Returns: TransactionReceipt or null
|
|
471
|
+
|
|
472
|
+
---
|
|
473
|
+
|
|
474
|
+
### 1.8 Filter
|
|
475
|
+
|
|
476
|
+
**Properties**:
|
|
477
|
+
- `address`: string | string[] - Contract address(es)
|
|
478
|
+
- `topics`: (string | string[] | null)[] - Event topics
|
|
479
|
+
- `fromBlock`: number | string - Start block
|
|
480
|
+
- `toBlock`: number | string - End block
|
|
481
|
+
|
|
482
|
+
---
|
|
483
|
+
|
|
484
|
+
### 1.9 PollingBlockTagSubscriber
|
|
485
|
+
|
|
486
|
+
**Purpose**: Subscribes to block updates by polling the provider at regular intervals
|
|
487
|
+
|
|
488
|
+
**Extends**: OnBlockSubscriber, Subscriber
|
|
489
|
+
|
|
490
|
+
**Constructor**:
|
|
491
|
+
```javascript
|
|
492
|
+
constructor(provider: Provider, tag: string)
|
|
493
|
+
```
|
|
494
|
+
- `provider`: Provider instance
|
|
495
|
+
- `tag`: Block tag to poll ("latest", "pending", etc.)
|
|
496
|
+
|
|
497
|
+
**Methods**:
|
|
498
|
+
|
|
499
|
+
#### `start(): void`
|
|
500
|
+
Starts polling for block updates.
|
|
501
|
+
|
|
502
|
+
#### `stop(): void`
|
|
503
|
+
Stops polling for block updates.
|
|
504
|
+
|
|
505
|
+
**Note**: This class provides a polling-based alternative to event subscriptions for environments where WebSocket subscriptions are not available.
|
|
506
|
+
|
|
507
|
+
---
|
|
508
|
+
|
|
509
|
+
### 1.9.1 SocketBlockSubscriber
|
|
510
|
+
|
|
511
|
+
**Purpose**: Subscribes to block updates via WebSocket
|
|
512
|
+
|
|
513
|
+
**Note**: This class is exported from ethers.js but not implemented in quantumcoin.js. It is listed here for API compatibility reference.
|
|
514
|
+
|
|
515
|
+
---
|
|
516
|
+
|
|
517
|
+
### 1.9.2 SocketEventSubscriber
|
|
518
|
+
|
|
519
|
+
**Purpose**: Subscribes to event logs via WebSocket
|
|
520
|
+
|
|
521
|
+
**Note**: This class is exported from ethers.js but not implemented in quantumcoin.js. It is listed here for API compatibility reference.
|
|
522
|
+
|
|
523
|
+
---
|
|
524
|
+
|
|
525
|
+
### 1.9.3 SocketPendingSubscriber
|
|
526
|
+
|
|
527
|
+
**Purpose**: Subscribes to pending transactions via WebSocket
|
|
528
|
+
|
|
529
|
+
**Note**: This class is exported from ethers.js but not implemented in quantumcoin.js. It is listed here for API compatibility reference.
|
|
530
|
+
|
|
531
|
+
---
|
|
532
|
+
|
|
533
|
+
### 1.9.4 SocketSubscriber
|
|
534
|
+
|
|
535
|
+
**Purpose**: Base class for WebSocket subscribers
|
|
536
|
+
|
|
537
|
+
**Note**: This class is exported from ethers.js but not implemented in quantumcoin.js. It is listed here for API compatibility reference.
|
|
538
|
+
|
|
539
|
+
---
|
|
540
|
+
|
|
541
|
+
### 1.9.5 UnmanagedSubscriber
|
|
542
|
+
|
|
543
|
+
**Purpose**: Represents an unmanaged subscriber
|
|
544
|
+
|
|
545
|
+
**Note**: This class is exported from ethers.js but not implemented in quantumcoin.js. It is listed here for API compatibility reference.
|
|
546
|
+
|
|
547
|
+
---
|
|
548
|
+
|
|
549
|
+
### 1.10 WebSocketProvider
|
|
550
|
+
|
|
551
|
+
**Purpose**: JSON-RPC provider backed by a WebSocket connection
|
|
552
|
+
|
|
553
|
+
**Extends**: SocketProvider, JsonRpcProvider
|
|
554
|
+
|
|
555
|
+
**Constructor**:
|
|
556
|
+
```javascript
|
|
557
|
+
constructor(url: string | WebSocketLike | WebSocketCreator, chainId?: number, options?: JsonRpcApiProviderOptions)
|
|
558
|
+
```
|
|
559
|
+
- `url`: WebSocket URL, WebSocketLike instance, or WebSocketCreator function
|
|
560
|
+
- `chainId`: Chain ID (defaults to 123123)
|
|
561
|
+
- `options`: Optional provider options
|
|
562
|
+
|
|
563
|
+
**Properties**:
|
|
564
|
+
- `websocket`: WebSocketLike - The WebSocket connection
|
|
565
|
+
- `url`: string - WebSocket URL
|
|
566
|
+
- `chainId`: number - Chain ID
|
|
567
|
+
|
|
568
|
+
**Methods**:
|
|
569
|
+
- Inherits all methods from JsonRpcProvider
|
|
570
|
+
- Provides real-time event subscriptions via WebSocket
|
|
571
|
+
|
|
572
|
+
**Note**: WebSockets provide instant access to events but require a persistent connection. Many third-party services charge additional fees for WebSocket endpoints.
|
|
573
|
+
|
|
574
|
+
---
|
|
575
|
+
|
|
576
|
+
### 1.11 IpcSocketProvider
|
|
577
|
+
|
|
578
|
+
**Purpose**: JSON-RPC provider backed by an IPC socket (for local nodes)
|
|
579
|
+
|
|
580
|
+
**Extends**: SocketProvider, JsonRpcProvider
|
|
581
|
+
|
|
582
|
+
**Constructor**:
|
|
583
|
+
```javascript
|
|
584
|
+
constructor(path: string, chainId?: number)
|
|
585
|
+
```
|
|
586
|
+
- `path`: Path to IPC socket
|
|
587
|
+
- `chainId`: Chain ID (defaults to 123123)
|
|
588
|
+
|
|
589
|
+
**Properties**:
|
|
590
|
+
- `path`: string - IPC socket path
|
|
591
|
+
- `chainId`: number - Chain ID
|
|
592
|
+
|
|
593
|
+
**Methods**:
|
|
594
|
+
- Inherits all methods from JsonRpcProvider
|
|
595
|
+
- Provides real-time event subscriptions via IPC
|
|
596
|
+
|
|
597
|
+
**Note**: Used for connecting to local QuantumCoin nodes running on the same machine.
|
|
598
|
+
|
|
599
|
+
---
|
|
600
|
+
|
|
601
|
+
### 1.12 FallbackProvider
|
|
602
|
+
|
|
603
|
+
**Purpose**: Provider that falls back to multiple providers for redundancy and reliability
|
|
604
|
+
|
|
605
|
+
**Extends**: Provider
|
|
606
|
+
|
|
607
|
+
**Constructor**:
|
|
608
|
+
```javascript
|
|
609
|
+
constructor(providers: Array<{ provider: Provider, priority?: number, weight?: number }>, quorum?: number)
|
|
610
|
+
```
|
|
611
|
+
- `providers`: Array of provider configurations with optional priority and weight
|
|
612
|
+
- `quorum`: Optional quorum number (default: 1) - number of providers that must agree
|
|
613
|
+
|
|
614
|
+
**Properties**:
|
|
615
|
+
- `providers`: Provider[] - Array of providers
|
|
616
|
+
- `quorum`: number - Quorum number
|
|
617
|
+
|
|
618
|
+
**Methods**:
|
|
619
|
+
- Inherits all methods from Provider
|
|
620
|
+
- Automatically falls back to next provider on failure
|
|
621
|
+
- For methods requiring quorum, waits for multiple providers to agree
|
|
622
|
+
|
|
623
|
+
**Note**: Useful for high-availability applications where multiple RPC endpoints are available.
|
|
624
|
+
|
|
625
|
+
---
|
|
626
|
+
|
|
627
|
+
### 1.13 BrowserProvider
|
|
628
|
+
|
|
629
|
+
**Purpose**: JSON-RPC provider backed by a browser-based EIP-1193 compatible provider (e.g., MetaMask, WalletConnect)
|
|
630
|
+
|
|
631
|
+
**Extends**: JsonRpcProvider
|
|
632
|
+
|
|
633
|
+
**Note**: The API matches ethers.js v6 BrowserProvider. This provider wraps EIP-1193 compatible providers that are injected into the browser (typically via `window.ethereum` or similar).
|
|
634
|
+
|
|
635
|
+
**Constructor**:
|
|
636
|
+
```javascript
|
|
637
|
+
constructor(ethereum: Eip1193Provider, chainId?: number)
|
|
638
|
+
```
|
|
639
|
+
- `ethereum`: EIP-1193 compatible provider object (must implement the EIP-1193 interface)
|
|
640
|
+
- `chainId`: Chain ID (defaults to 123123)
|
|
641
|
+
|
|
642
|
+
**Properties**:
|
|
643
|
+
- `provider`: Eip1193Provider - The wrapped EIP-1193 provider
|
|
644
|
+
- `chainId`: number - Chain ID
|
|
645
|
+
|
|
646
|
+
**Methods**:
|
|
647
|
+
- Inherits all methods from JsonRpcProvider
|
|
648
|
+
- Provides browser-based wallet integration
|
|
649
|
+
- Automatically handles account changes and chain changes via EIP-1193 events
|
|
650
|
+
|
|
651
|
+
**EIP-1193 Provider Interface**:
|
|
652
|
+
The `ethereum` parameter must implement the EIP-1193 interface with the following methods:
|
|
653
|
+
- `request({ method: string, params?: any[] }): Promise<any>` - Main RPC request method
|
|
654
|
+
- `on(event: string, callback: Function): void` - Event subscription
|
|
655
|
+
- `removeListener(event: string, callback: Function): void` - Event unsubscription
|
|
656
|
+
|
|
657
|
+
**Events**:
|
|
658
|
+
The BrowserProvider automatically listens to EIP-1193 events:
|
|
659
|
+
- `accountsChanged` - Emitted when accounts change
|
|
660
|
+
- `chainChanged` - Emitted when chain ID changes
|
|
661
|
+
- `disconnect` - Emitted when provider disconnects
|
|
662
|
+
|
|
663
|
+
**Note**: BrowserProvider is designed for browser environments. For Node.js environments, use JsonRpcProvider, WebSocketProvider, or IpcSocketProvider instead.
|
|
664
|
+
|
|
665
|
+
---
|
|
666
|
+
|
|
667
|
+
### 1.14 FilterByBlockHash
|
|
668
|
+
|
|
669
|
+
**Properties**:
|
|
670
|
+
- `blockHash`: string - Block hash to filter by (66 hex characters)
|
|
671
|
+
- `address`: string | string[] - Contract address(es)
|
|
672
|
+
- `topics`: (string | string[] | null)[] - Event topics
|
|
673
|
+
|
|
674
|
+
**Note**: Alternative to Filter for querying logs by block hash instead of block number range. Allows querying potentially orphaned blocks without ambiguity.
|
|
675
|
+
|
|
676
|
+
---
|
|
677
|
+
|
|
678
|
+
## 2. Wallet Classes
|
|
679
|
+
|
|
680
|
+
### 2.1 AbstractSigner
|
|
681
|
+
|
|
682
|
+
**Purpose**: Abstract base class for all signers
|
|
683
|
+
|
|
684
|
+
**Extends**: Signer
|
|
685
|
+
|
|
686
|
+
**Note**: This is an internal base class. All concrete signers (BaseWallet, Wallet, JsonRpcSigner, VoidSigner, etc.) extend this class. The API matches ethers.js v6 AbstractSigner.
|
|
687
|
+
|
|
688
|
+
---
|
|
689
|
+
|
|
690
|
+
### 2.2 BaseWallet
|
|
691
|
+
|
|
692
|
+
**Purpose**: Streamlined implementation of a Signer that operates with a private key
|
|
693
|
+
|
|
694
|
+
**Extends**: AbstractSigner
|
|
695
|
+
|
|
696
|
+
**Constructor**:
|
|
697
|
+
```javascript
|
|
698
|
+
constructor(privateKey: SigningKey, provider?: null | Provider)
|
|
699
|
+
```
|
|
700
|
+
- `privateKey`: SigningKey instance
|
|
701
|
+
- `provider`: Optional provider instance
|
|
702
|
+
|
|
703
|
+
**Properties**:
|
|
704
|
+
- `address`: string (read-only) - The wallet address
|
|
705
|
+
- `privateKey`: string (read-only) - The private key for this wallet
|
|
706
|
+
- `signingKey`: SigningKey (read-only) - The SigningKey used for signing payloads
|
|
707
|
+
- `provider`: Provider | null - Provider instance
|
|
708
|
+
|
|
709
|
+
**Methods**:
|
|
710
|
+
|
|
711
|
+
#### `getAddress(): Promise<string>`
|
|
712
|
+
Returns the wallet address.
|
|
713
|
+
- Returns: Address string
|
|
714
|
+
|
|
715
|
+
#### `signMessageSync(message: string | Uint8Array): string`
|
|
716
|
+
Returns the signature for message signed with this wallet (synchronous).
|
|
717
|
+
- `message`: Message to sign (string or bytes)
|
|
718
|
+
- Returns: Signature string
|
|
719
|
+
- **Implementation**: Uses quantum-coin-js-sdk for message signing
|
|
720
|
+
|
|
721
|
+
#### `signTransaction(tx: TransactionRequest): Promise<string>`
|
|
722
|
+
Signs a transaction and returns the signed transaction data.
|
|
723
|
+
- `tx`: Transaction request
|
|
724
|
+
- Returns: Signed transaction data
|
|
725
|
+
- **Implementation**: Uses `signRawTransaction()` from quantum-coin-js-sdk
|
|
726
|
+
|
|
727
|
+
#### `sendTransaction(tx: TransactionRequest): Promise<TransactionResponse>`
|
|
728
|
+
Signs and sends a transaction.
|
|
729
|
+
- `tx`: Transaction request
|
|
730
|
+
- Returns: TransactionResponse
|
|
731
|
+
- **Requires provider**: Throws error if `provider` is `null`.
|
|
732
|
+
|
|
733
|
+
**Note**: BaseWallet provides the core signing functionality. Wallet extends BaseWallet and adds additional convenience methods.
|
|
734
|
+
|
|
735
|
+
---
|
|
736
|
+
|
|
737
|
+
### 2.3 NonceManager
|
|
738
|
+
|
|
739
|
+
**Purpose**: Manages nonces for transactions to prevent conflicts and ensure proper ordering
|
|
740
|
+
|
|
741
|
+
**Extends**: Signer
|
|
742
|
+
|
|
743
|
+
**Constructor**:
|
|
744
|
+
```javascript
|
|
745
|
+
constructor(signer: Signer)
|
|
746
|
+
```
|
|
747
|
+
- `signer`: Signer instance to wrap
|
|
748
|
+
|
|
749
|
+
**Properties**:
|
|
750
|
+
- `signer`: Signer - The wrapped signer
|
|
751
|
+
- `provider`: Provider | null - Provider instance (from wrapped signer)
|
|
752
|
+
|
|
753
|
+
**Methods**:
|
|
754
|
+
|
|
755
|
+
#### `getAddress(): Promise<string>`
|
|
756
|
+
Returns the signer address.
|
|
757
|
+
- Returns: Address string
|
|
758
|
+
|
|
759
|
+
#### `getTransactionCount(blockTag?: string): Promise<number>`
|
|
760
|
+
Gets the current transaction count (nonce).
|
|
761
|
+
- `blockTag`: Optional block tag
|
|
762
|
+
- Returns: Current nonce
|
|
763
|
+
|
|
764
|
+
#### `sendTransaction(tx: TransactionRequest): Promise<TransactionResponse>`
|
|
765
|
+
Sends a transaction with managed nonce.
|
|
766
|
+
- `tx`: Transaction request (nonce will be auto-managed)
|
|
767
|
+
- Returns: TransactionResponse
|
|
768
|
+
|
|
769
|
+
#### `reset(): void`
|
|
770
|
+
Resets the nonce manager, clearing cached nonce.
|
|
771
|
+
|
|
772
|
+
#### `increment(): void`
|
|
773
|
+
Increments the internal nonce counter.
|
|
774
|
+
|
|
775
|
+
**Note**: NonceManager automatically manages nonces to prevent conflicts when sending multiple transactions. It tracks the nonce internally and increments it for each transaction.
|
|
776
|
+
|
|
777
|
+
---
|
|
778
|
+
|
|
779
|
+
### 2.4 Wallet
|
|
780
|
+
|
|
781
|
+
**Purpose**: Represents a QuantumCoin wallet with signing capabilities
|
|
782
|
+
|
|
783
|
+
**Extends**: BaseWallet
|
|
784
|
+
|
|
785
|
+
**Constructor**:
|
|
786
|
+
```javascript
|
|
787
|
+
constructor(key: string | Uint8Array | SigningKey, provider?: Provider)
|
|
788
|
+
```
|
|
789
|
+
- `key`: Private key as hex string, byte array, or SigningKey instance
|
|
790
|
+
- `provider`: Optional provider instance
|
|
791
|
+
|
|
792
|
+
**Implementation Notes**:
|
|
793
|
+
- The constructor should use quantum-coin-js-sdk functions to derive the wallet's public key and address:
|
|
794
|
+
- Use `publicKeyFromPrivateKey()` from quantum-coin-js-sdk to get the public key from the private key
|
|
795
|
+
- Use `addressFromPublicKey()` from quantum-coin-js-sdk to get the address from the public key
|
|
796
|
+
- If either function returns null, throw an error
|
|
797
|
+
- The private key should be converted to a byte array (number[]) if provided as a hex string for use with quantum-coin-js-sdk functions
|
|
798
|
+
- If a SigningKey is provided, use it directly
|
|
799
|
+
|
|
800
|
+
**Properties**:
|
|
801
|
+
- `address`: string (read-only) - Wallet address (32 bytes, 66 hex characters)
|
|
802
|
+
- `provider`: Provider | null - Provider instance (null if not provided in constructor)
|
|
803
|
+
- `privateKey`: string (read-only) - Private key as hex string
|
|
804
|
+
- `signingKey`: SigningKey (read-only) - The SigningKey used for signing payloads
|
|
805
|
+
|
|
806
|
+
**Static Methods**:
|
|
807
|
+
|
|
808
|
+
#### `createRandom(provider?: Provider): Wallet`
|
|
809
|
+
Creates a new random wallet.
|
|
810
|
+
- `provider`: Optional provider instance
|
|
811
|
+
- Returns: New Wallet instance
|
|
812
|
+
- **Implementation**: Uses `newWallet()` from quantum-coin-js-sdk internally. If `newWallet()` returns null, throw an error.
|
|
813
|
+
|
|
814
|
+
#### `fromEncryptedJsonSync(json: string, password: string, provider?: Provider): Wallet`
|
|
815
|
+
Creates a wallet from an encrypted JSON string (synchronous).
|
|
816
|
+
- `json`: Encrypted wallet JSON string
|
|
817
|
+
- `password`: Passphrase used to encrypt the wallet
|
|
818
|
+
- `provider`: Optional provider instance
|
|
819
|
+
- Returns: Wallet instance
|
|
820
|
+
- **Implementation**: Uses `deserializeEncryptedWallet()` from quantum-coin-js-sdk internally. If `deserializeEncryptedWallet()` returns null, throw an error.
|
|
821
|
+
- **Note**: This function can take up to a minute or so to execute. You should open wallets only from trusted sources.
|
|
822
|
+
|
|
823
|
+
#### `fromPhrase(phrase: string | string[], provider?: Provider): Wallet`
|
|
824
|
+
Creates a wallet from a seed phrase.
|
|
825
|
+
- `phrase`: Either:
|
|
826
|
+
- An array of seed words (string[])
|
|
827
|
+
- A space or comma delimited string containing seed words
|
|
828
|
+
- `provider`: Optional provider instance
|
|
829
|
+
- Returns: Wallet instance
|
|
830
|
+
- **Implementation**:
|
|
831
|
+
- If `phrase` is a string, split it by spaces or commas to create an array of words
|
|
832
|
+
- The resulting array must contain exactly 48 words
|
|
833
|
+
- Uses `openWalletFromSeedWords()` from quantum-coin-js-sdk internally with the array
|
|
834
|
+
- If `openWalletFromSeedWords()` returns null, throw an error
|
|
835
|
+
|
|
836
|
+
**Provider Usage**:
|
|
837
|
+
- The provider is optional in the constructor. If not provided, `provider` will be `null`.
|
|
838
|
+
- Methods that require blockchain access (`getBalance()`, `getTransactionCount()`, `sendTransaction()`) will throw an error if `provider` is `null`.
|
|
839
|
+
- Methods that only require signing (`signTransaction()`, `signMessageSync()`, `signTypedData()`) can work without a provider.
|
|
840
|
+
- The provider can be set later using the `connect(provider)` method.
|
|
841
|
+
|
|
842
|
+
**Methods**:
|
|
843
|
+
|
|
844
|
+
#### `getAddress(): string`
|
|
845
|
+
Returns the wallet address.
|
|
846
|
+
- Does not require a provider.
|
|
847
|
+
|
|
848
|
+
#### `getBalance(blockTag?: string): Promise<bigint>`
|
|
849
|
+
Returns wallet balance.
|
|
850
|
+
- `blockTag`: Optional block tag
|
|
851
|
+
- **Requires provider**: Throws error if `provider` is `null`.
|
|
852
|
+
|
|
853
|
+
#### `getTransactionCount(blockTag?: string): Promise<number>`
|
|
854
|
+
Returns wallet nonce.
|
|
855
|
+
- `blockTag`: Optional block tag
|
|
856
|
+
- **Requires provider**: Throws error if `provider` is `null`.
|
|
857
|
+
|
|
858
|
+
#### `sendTransaction(tx: TransactionRequest): Promise<TransactionResponse>`
|
|
859
|
+
Signs and sends a transaction.
|
|
860
|
+
- `tx`: Transaction request (from, nonce, gasLimit will be auto-filled if not provided)
|
|
861
|
+
- **Requires provider**: Throws error if `provider` is `null`.
|
|
862
|
+
- Note: The `remarks` field in TransactionRequest is optional and can be used to include a comment (max 32 bytes). Do not store sensitive information in remarks.
|
|
863
|
+
|
|
864
|
+
#### `signTransaction(tx: TransactionRequest): Promise<string>`
|
|
865
|
+
Signs a transaction and returns the signed transaction data.
|
|
866
|
+
- `tx`: Transaction request
|
|
867
|
+
- **Does not require provider**: Can sign transactions offline.
|
|
868
|
+
- Note: The `remarks` field in TransactionRequest is optional and can be used to include a comment (max 32 bytes). Do not store sensitive information in remarks.
|
|
869
|
+
|
|
870
|
+
#### `signMessageSync(message: string | Uint8Array): string`
|
|
871
|
+
Signs a message and returns the signature (synchronous).
|
|
872
|
+
- `message`: Message to sign (string or bytes)
|
|
873
|
+
- Returns: Signature string
|
|
874
|
+
- **Does not require provider**: Can sign messages offline.
|
|
875
|
+
- **Implementation**: Uses quantum-coin-js-sdk for message signing
|
|
876
|
+
|
|
877
|
+
#### `encryptSync(password: string | Uint8Array): string`
|
|
878
|
+
Encrypts and serializes this wallet to a JSON string (synchronous).
|
|
879
|
+
- `password`: Passphrase used to encrypt the wallet (should be at least 12 characters long)
|
|
880
|
+
- Returns: Encrypted wallet JSON string
|
|
881
|
+
- **Implementation**: Uses `serializeEncryptedWallet()` from quantum-coin-js-sdk internally. If `serializeEncryptedWallet()` returns null, throw an error.
|
|
882
|
+
- **Note**: This method will block the event loop (freezing all UI) until it is complete, which may be a non-trivial duration. The encrypted JSON string is readable by Desktop/Mobile/Web/CLI wallet applications.
|
|
883
|
+
|
|
884
|
+
#### `connect(provider: Provider): Wallet`
|
|
885
|
+
Returns a new wallet instance connected to the provider.
|
|
886
|
+
- `provider`: Provider instance
|
|
887
|
+
|
|
888
|
+
---
|
|
889
|
+
|
|
890
|
+
## 3. Contract Classes
|
|
891
|
+
|
|
892
|
+
### 3.2 Contract
|
|
893
|
+
|
|
894
|
+
**Purpose**: Represents a smart contract instance
|
|
895
|
+
|
|
896
|
+
**Extends**: BaseContract
|
|
897
|
+
|
|
898
|
+
**Note**: The API matches ethers.js v6 Contract. All methods, properties, and behavior follow the same patterns as ethers.js v6.
|
|
899
|
+
|
|
900
|
+
**Constructor**:
|
|
901
|
+
```javascript
|
|
902
|
+
constructor(address: string, abi: Interface | AbiFragment[], providerOrSigner?: Provider | Signer, bytecode?: string)
|
|
903
|
+
```
|
|
904
|
+
- `address`: Contract address (32 bytes)
|
|
905
|
+
- `abi`: Contract ABI (Interface or array of fragments)
|
|
906
|
+
- `providerOrSigner`: Provider or signer instance
|
|
907
|
+
- `bytecode`: Optional contract bytecode
|
|
908
|
+
|
|
909
|
+
**Properties**:
|
|
910
|
+
- `address`: string - Contract address
|
|
911
|
+
- `interface`: Interface - Contract interface
|
|
912
|
+
- `provider`: Provider | null - Provider instance
|
|
913
|
+
- `signer`: Signer | null - Signer instance
|
|
914
|
+
- `target: string | Addressable` - Contract target (address or addressable)
|
|
915
|
+
- `runner: ContractRunner | null` - Contract runner (provider or signer)
|
|
916
|
+
- `deployTransaction: ContractTransactionResponse | null` - Deployment transaction
|
|
917
|
+
|
|
918
|
+
**Methods**:
|
|
919
|
+
|
|
920
|
+
#### `getAddress(): string`
|
|
921
|
+
Returns contract address.
|
|
922
|
+
|
|
923
|
+
#### `[methodName](...args): Promise<any>`
|
|
924
|
+
Dynamic methods for each contract function.
|
|
925
|
+
- For view functions: Returns decoded return values
|
|
926
|
+
- For state-changing functions: Returns ContractTransactionResponse
|
|
927
|
+
|
|
928
|
+
#### `queryFilter(event: EventFragment, fromBlock?: number | string, toBlock?: number | string): Promise<EventLog[]>`
|
|
929
|
+
Queries event logs.
|
|
930
|
+
- `event`: Event fragment
|
|
931
|
+
- `fromBlock`: Start block
|
|
932
|
+
- `toBlock`: End block
|
|
933
|
+
|
|
934
|
+
#### `on(event: EventFragment | string, callback: Function): Contract`
|
|
935
|
+
Subscribes to contract events.
|
|
936
|
+
- `event`: Event fragment or name
|
|
937
|
+
- `callback`: Callback function
|
|
938
|
+
|
|
939
|
+
#### `once(event: EventFragment | string, callback: Function): Contract`
|
|
940
|
+
Subscribes to event once.
|
|
941
|
+
- `event`: Event fragment or name
|
|
942
|
+
- `callback`: Callback function
|
|
943
|
+
|
|
944
|
+
#### `removeListener(event: EventFragment | string, callback: Function): Contract`
|
|
945
|
+
Removes event listener.
|
|
946
|
+
- `event`: Event fragment or name
|
|
947
|
+
- `callback`: Callback function
|
|
948
|
+
|
|
949
|
+
#### `removeAllListeners(event?: EventFragment | string): Contract`
|
|
950
|
+
Removes all listeners.
|
|
951
|
+
- `event`: Optional event name
|
|
952
|
+
|
|
953
|
+
#### `connect(signerOrProvider: Signer | Provider): Contract`
|
|
954
|
+
Returns new contract instance connected to signer/provider.
|
|
955
|
+
- `signerOrProvider`: Signer or provider
|
|
956
|
+
|
|
957
|
+
#### `attach(address: string): Contract`
|
|
958
|
+
Returns new contract instance at different address.
|
|
959
|
+
- `address`: New contract address
|
|
960
|
+
|
|
961
|
+
#### `deployTransaction(): TransactionResponse | null`
|
|
962
|
+
Returns deployment transaction (if contract was deployed).
|
|
963
|
+
|
|
964
|
+
#### `getTransactionReceipt(hash: string): Promise<ContractTransactionReceipt | null>`
|
|
965
|
+
Gets contract transaction receipt.
|
|
966
|
+
- `hash`: Transaction hash
|
|
967
|
+
- Returns: ContractTransactionReceipt or null
|
|
968
|
+
|
|
969
|
+
#### `waitForDeployment(): Promise<this>`
|
|
970
|
+
Waits for contract deployment.
|
|
971
|
+
- Returns: Contract instance (this)
|
|
972
|
+
|
|
973
|
+
#### `getDeployedCode(): Promise<string | null>`
|
|
974
|
+
Gets deployed contract code.
|
|
975
|
+
- Returns: Contract bytecode or null if not deployed
|
|
976
|
+
|
|
977
|
+
#### `static from(target: string | Addressable, abi: Interface | AbiFragment[], runner?: ContractRunner): Contract`
|
|
978
|
+
Creates contract from target.
|
|
979
|
+
- `target`: Contract address or addressable
|
|
980
|
+
- `abi`: Contract ABI
|
|
981
|
+
- `runner`: Optional contract runner
|
|
982
|
+
- Returns: Contract instance
|
|
983
|
+
|
|
984
|
+
---
|
|
985
|
+
|
|
986
|
+
### 3.3 ContractFactory
|
|
987
|
+
|
|
988
|
+
**Purpose**: Factory for deploying contracts
|
|
989
|
+
|
|
990
|
+
**Note**: The API matches ethers.js v6 ContractFactory. All methods, properties, and behavior follow the same patterns as ethers.js v6.
|
|
991
|
+
|
|
992
|
+
**Constructor**:
|
|
993
|
+
```javascript
|
|
994
|
+
constructor(abi: Interface | AbiFragment[], bytecode: string | BytesLike, signer?: Signer)
|
|
995
|
+
```
|
|
996
|
+
- `abi`: Contract ABI
|
|
997
|
+
- `bytecode`: Contract bytecode
|
|
998
|
+
- `signer`: Optional signer for deployment
|
|
999
|
+
|
|
1000
|
+
**Methods**:
|
|
1001
|
+
|
|
1002
|
+
#### `getDeployTransaction(...args): TransactionRequest`
|
|
1003
|
+
Returns deployment transaction request.
|
|
1004
|
+
- `args`: Constructor arguments
|
|
1005
|
+
|
|
1006
|
+
#### `deploy(...args): Promise<Contract>`
|
|
1007
|
+
Deploys the contract.
|
|
1008
|
+
- `args`: Constructor arguments
|
|
1009
|
+
- Returns: Contract instance
|
|
1010
|
+
|
|
1011
|
+
#### `attach(address: string): Contract`
|
|
1012
|
+
Returns contract instance at address.
|
|
1013
|
+
- `address`: Contract address
|
|
1014
|
+
|
|
1015
|
+
#### `connect(signer: Signer): ContractFactory`
|
|
1016
|
+
Returns new factory connected to signer.
|
|
1017
|
+
- `signer`: Signer instance
|
|
1018
|
+
|
|
1019
|
+
---
|
|
1020
|
+
|
|
1021
|
+
### 3.4 ContractTransactionResponse
|
|
1022
|
+
|
|
1023
|
+
**Extends**: TransactionResponse
|
|
1024
|
+
|
|
1025
|
+
**Additional Methods**:
|
|
1026
|
+
|
|
1027
|
+
#### `wait(confirmations?: number): Promise<ContractTransactionReceipt>`
|
|
1028
|
+
Waits for transaction confirmation.
|
|
1029
|
+
- `confirmations`: Optional confirmations to wait for
|
|
1030
|
+
|
|
1031
|
+
---
|
|
1032
|
+
|
|
1033
|
+
### 3.5 ContractTransactionReceipt
|
|
1034
|
+
|
|
1035
|
+
**Extends**: TransactionReceipt
|
|
1036
|
+
|
|
1037
|
+
**Additional Methods**:
|
|
1038
|
+
|
|
1039
|
+
#### `getEvent(eventName: string): EventLog | null`
|
|
1040
|
+
Gets event log by name.
|
|
1041
|
+
- `eventName`: Event name
|
|
1042
|
+
|
|
1043
|
+
#### `getEvents(eventName: string): EventLog[]`
|
|
1044
|
+
Gets all event logs by name.
|
|
1045
|
+
- `eventName`: Event name
|
|
1046
|
+
|
|
1047
|
+
---
|
|
1048
|
+
|
|
1049
|
+
### 3.6 EventLog
|
|
1050
|
+
|
|
1051
|
+
**Extends**: Log
|
|
1052
|
+
|
|
1053
|
+
**Additional Properties**:
|
|
1054
|
+
- `eventName`: string - Event name
|
|
1055
|
+
- `args`: Result - Decoded event arguments
|
|
1056
|
+
- `fragment`: EventFragment - Event fragment
|
|
1057
|
+
|
|
1058
|
+
---
|
|
1059
|
+
|
|
1060
|
+
### 3.7 ContractEventPayload
|
|
1061
|
+
|
|
1062
|
+
**Purpose**: Represents a contract event payload
|
|
1063
|
+
|
|
1064
|
+
**Note**: This class is exported from ethers.js but not implemented in quantumcoin.js. It is listed here for API compatibility reference.
|
|
1065
|
+
|
|
1066
|
+
---
|
|
1067
|
+
|
|
1068
|
+
### 3.8 ContractUnknownEventPayload
|
|
1069
|
+
|
|
1070
|
+
**Purpose**: Represents an unknown contract event payload
|
|
1071
|
+
|
|
1072
|
+
**Note**: This class is exported from ethers.js but not implemented in quantumcoin.js. It is listed here for API compatibility reference.
|
|
1073
|
+
|
|
1074
|
+
---
|
|
1075
|
+
|
|
1076
|
+
### 3.9 EventPayload
|
|
1077
|
+
|
|
1078
|
+
**Purpose**: Base class for event payloads
|
|
1079
|
+
|
|
1080
|
+
**Note**: This class is exported from ethers.js but not implemented in quantumcoin.js. It is listed here for API compatibility reference.
|
|
1081
|
+
|
|
1082
|
+
---
|
|
1083
|
+
|
|
1084
|
+
### 3.10 UndecodedEventLog
|
|
1085
|
+
|
|
1086
|
+
**Purpose**: Represents an undecoded event log
|
|
1087
|
+
|
|
1088
|
+
**Extends**: Log
|
|
1089
|
+
|
|
1090
|
+
**Note**: This class is exported from ethers.js but not implemented in quantumcoin.js. It is listed here for API compatibility reference.
|
|
1091
|
+
|
|
1092
|
+
---
|
|
1093
|
+
|
|
1094
|
+
## 4. Interface and ABI Classes
|
|
1095
|
+
|
|
1096
|
+
### 4.0 Fragment
|
|
1097
|
+
|
|
1098
|
+
**Purpose**: Base class for ABI fragments
|
|
1099
|
+
|
|
1100
|
+
**Note**: This class is exported from ethers.js but not implemented in quantumcoin.js. It is listed here for API compatibility reference. In quantumcoin.js, `AbiFragment` serves as the base fragment class.
|
|
1101
|
+
|
|
1102
|
+
---
|
|
1103
|
+
|
|
1104
|
+
### 4.0.1 NamedFragment
|
|
1105
|
+
|
|
1106
|
+
**Purpose**: Base class for named ABI fragments
|
|
1107
|
+
|
|
1108
|
+
**Extends**: Fragment
|
|
1109
|
+
|
|
1110
|
+
**Note**: This class is exported from ethers.js but not implemented in quantumcoin.js. It is listed here for API compatibility reference.
|
|
1111
|
+
|
|
1112
|
+
---
|
|
1113
|
+
|
|
1114
|
+
### 4.1 Interface
|
|
1115
|
+
|
|
1116
|
+
**Purpose**: Represents contract ABI interface
|
|
1117
|
+
|
|
1118
|
+
**Note**: The API matches ethers.js v6 Interface. All methods, properties, and behavior follow the same patterns as ethers.js v6.
|
|
1119
|
+
|
|
1120
|
+
**Constructor**:
|
|
1121
|
+
```javascript
|
|
1122
|
+
constructor(fragments: AbiFragment[] | string)
|
|
1123
|
+
```
|
|
1124
|
+
- `fragments`: ABI fragments array or JSON string
|
|
1125
|
+
|
|
1126
|
+
**Properties**:
|
|
1127
|
+
- `fragments`: readonly AbiFragment[] - ABI fragments
|
|
1128
|
+
|
|
1129
|
+
**Methods**:
|
|
1130
|
+
|
|
1131
|
+
#### `getFunction(nameOrSignature: string): FunctionFragment`
|
|
1132
|
+
Gets function fragment by name or signature.
|
|
1133
|
+
- `nameOrSignature`: Function name or signature
|
|
1134
|
+
|
|
1135
|
+
#### `getEvent(nameOrSignature: string): EventFragment`
|
|
1136
|
+
Gets event fragment by name or signature.
|
|
1137
|
+
- `nameOrSignature`: Event name or signature
|
|
1138
|
+
|
|
1139
|
+
#### `encodeFunctionData(functionFragment: FunctionFragment | string, values: any[]): string`
|
|
1140
|
+
Encodes function call data.
|
|
1141
|
+
- `functionFragment`: Function fragment or signature
|
|
1142
|
+
- `values`: Function arguments
|
|
1143
|
+
|
|
1144
|
+
#### `decodeFunctionResult(functionFragment: FunctionFragment | string, data: string): Result`
|
|
1145
|
+
Decodes function result.
|
|
1146
|
+
- `functionFragment`: Function fragment or signature
|
|
1147
|
+
- `data`: Encoded result data
|
|
1148
|
+
|
|
1149
|
+
#### `encodeEventLog(eventFragment: EventFragment, values: any[]): { topics: string[], data: string }`
|
|
1150
|
+
Encodes event log.
|
|
1151
|
+
- `eventFragment`: Event fragment
|
|
1152
|
+
- `values`: Event values
|
|
1153
|
+
- **Implementation**: Uses `encodeEventLog()` from quantum-coin-js-sdk internally
|
|
1154
|
+
- Returns: Object with `topics` (string[]) and `data` (string)
|
|
1155
|
+
|
|
1156
|
+
#### `decodeEventLog(eventFragment: EventFragment, topics: string[], data: string): Result`
|
|
1157
|
+
Decodes event log.
|
|
1158
|
+
- `eventFragment`: Event fragment
|
|
1159
|
+
- `topics`: Event topics
|
|
1160
|
+
- `data`: Event data
|
|
1161
|
+
- **Implementation**: Uses `decodeEventLog()` from quantum-coin-js-sdk internally
|
|
1162
|
+
- Returns: Result object with decoded event arguments
|
|
1163
|
+
|
|
1164
|
+
#### `parseTransaction(data: string): TransactionDescription`
|
|
1165
|
+
Parses transaction data.
|
|
1166
|
+
- `data`: Transaction data
|
|
1167
|
+
|
|
1168
|
+
#### `parseLog(log: Log): LogDescription`
|
|
1169
|
+
Parses log data.
|
|
1170
|
+
- `log`: Log object
|
|
1171
|
+
- Returns: LogDescription with decoded event information
|
|
1172
|
+
|
|
1173
|
+
#### `getError(nameOrSignature: string): ErrorFragment`
|
|
1174
|
+
Gets error fragment by name or signature.
|
|
1175
|
+
- `nameOrSignature`: Error name or signature
|
|
1176
|
+
- Returns: ErrorFragment instance
|
|
1177
|
+
|
|
1178
|
+
#### `getConstructor(): ConstructorFragment | null`
|
|
1179
|
+
Gets constructor fragment.
|
|
1180
|
+
- Returns: ConstructorFragment instance or null if no constructor
|
|
1181
|
+
|
|
1182
|
+
#### `getFallback(): FunctionFragment | null`
|
|
1183
|
+
Gets fallback function fragment.
|
|
1184
|
+
- Returns: FunctionFragment instance or null if no fallback function
|
|
1185
|
+
|
|
1186
|
+
#### `getReceive(): FunctionFragment | null`
|
|
1187
|
+
Gets receive function fragment.
|
|
1188
|
+
- Returns: FunctionFragment instance or null if no receive function
|
|
1189
|
+
|
|
1190
|
+
#### `parseError(data: string): ErrorDescription`
|
|
1191
|
+
Parses error data.
|
|
1192
|
+
- `data`: Error data (hex string)
|
|
1193
|
+
- Returns: ErrorDescription with decoded error information
|
|
1194
|
+
|
|
1195
|
+
#### `getSighash(fragment: FunctionFragment | ErrorFragment | string): string`
|
|
1196
|
+
Gets function/error selector.
|
|
1197
|
+
- `fragment`: Function or error fragment or signature string
|
|
1198
|
+
- Returns: Function/error selector (4 bytes, 10 hex characters including 0x)
|
|
1199
|
+
|
|
1200
|
+
#### `getEventTopic(fragment: EventFragment | string): string`
|
|
1201
|
+
Gets event topic hash.
|
|
1202
|
+
- `fragment`: Event fragment or signature string
|
|
1203
|
+
- Returns: Event topic hash (32 bytes, 66 hex characters including 0x)
|
|
1204
|
+
|
|
1205
|
+
#### `format(format?: string): string`
|
|
1206
|
+
Formats interface as string.
|
|
1207
|
+
- `format`: Optional format type
|
|
1208
|
+
- Returns: Formatted interface string
|
|
1209
|
+
|
|
1210
|
+
#### `formatJson(): string`
|
|
1211
|
+
Formats interface as JSON string.
|
|
1212
|
+
- Returns: JSON string representation of interface
|
|
1213
|
+
|
|
1214
|
+
**Additional Properties**:
|
|
1215
|
+
- `deploy: ConstructorFragment | null` - Constructor fragment
|
|
1216
|
+
- `fallback: FallbackFragment | null` - Fallback function fragment
|
|
1217
|
+
- `receive: boolean` - Whether contract has receive function
|
|
1218
|
+
|
|
1219
|
+
---
|
|
1220
|
+
|
|
1221
|
+
### 4.2 AbiFragment
|
|
1222
|
+
|
|
1223
|
+
**Base Properties**:
|
|
1224
|
+
- `type`: string - Fragment type ("function", "event", "constructor", "fallback", "receive", "error")
|
|
1225
|
+
- `name`: string - Fragment name
|
|
1226
|
+
- `inputs`: AbiParameter[] - Input parameters
|
|
1227
|
+
- `outputs`: AbiParameter[] - Output parameters (for functions, not applicable for errors)
|
|
1228
|
+
- `signature`: string - Full signature of the fragment (e.g., "transfer(address,uint256)")
|
|
1229
|
+
|
|
1230
|
+
---
|
|
1231
|
+
|
|
1232
|
+
### 4.4 FunctionFragment
|
|
1233
|
+
|
|
1234
|
+
**Extends**: AbiFragment
|
|
1235
|
+
|
|
1236
|
+
**Note**: The API matches ethers.js v6 FunctionFragment.
|
|
1237
|
+
|
|
1238
|
+
**Additional Properties**:
|
|
1239
|
+
- `stateMutability`: string - "pure", "view", "nonpayable", "payable"
|
|
1240
|
+
- `constant`: boolean - Whether function is constant
|
|
1241
|
+
- `payable`: boolean - Whether function is payable
|
|
1242
|
+
- `selector`: string - Function selector (4 bytes, 10 hex characters including 0x)
|
|
1243
|
+
|
|
1244
|
+
**Methods**:
|
|
1245
|
+
|
|
1246
|
+
#### `format(format?: string): string`
|
|
1247
|
+
Formats fragment as string.
|
|
1248
|
+
- `format`: Optional format type
|
|
1249
|
+
|
|
1250
|
+
---
|
|
1251
|
+
|
|
1252
|
+
### 4.5 EventFragment
|
|
1253
|
+
|
|
1254
|
+
**Extends**: AbiFragment
|
|
1255
|
+
|
|
1256
|
+
**Note**: The API matches ethers.js v6 EventFragment.
|
|
1257
|
+
|
|
1258
|
+
**Additional Properties**:
|
|
1259
|
+
- `anonymous`: boolean - Whether event is anonymous
|
|
1260
|
+
- `topicHash`: string - Event topic hash (32 bytes, 66 hex characters including 0x)
|
|
1261
|
+
|
|
1262
|
+
**Methods**:
|
|
1263
|
+
|
|
1264
|
+
#### `format(format?: string): string`
|
|
1265
|
+
Formats fragment as string.
|
|
1266
|
+
- `format`: Optional format type
|
|
1267
|
+
|
|
1268
|
+
---
|
|
1269
|
+
|
|
1270
|
+
### 4.6 AbiParameter
|
|
1271
|
+
|
|
1272
|
+
**Note**: The API matches ethers.js v6 AbiParameter.
|
|
1273
|
+
|
|
1274
|
+
**Properties**:
|
|
1275
|
+
- `name`: string - Parameter name
|
|
1276
|
+
- `type`: string - Parameter type
|
|
1277
|
+
- `indexed`: boolean - Whether parameter is indexed (for events)
|
|
1278
|
+
- `components`: AbiParameter[] - Components (for structs/tuples)
|
|
1279
|
+
|
|
1280
|
+
---
|
|
1281
|
+
|
|
1282
|
+
### 4.7 TransactionDescription
|
|
1283
|
+
|
|
1284
|
+
**Note**: The API matches ethers.js v6 TransactionDescription.
|
|
1285
|
+
|
|
1286
|
+
**Properties**:
|
|
1287
|
+
- `name`: string - Function name
|
|
1288
|
+
- `signature`: string - Function signature
|
|
1289
|
+
- `args`: Result - Decoded arguments
|
|
1290
|
+
- `fragment`: FunctionFragment - Function fragment
|
|
1291
|
+
|
|
1292
|
+
---
|
|
1293
|
+
|
|
1294
|
+
### 4.8 LogDescription
|
|
1295
|
+
|
|
1296
|
+
**Note**: The API matches ethers.js v6 LogDescription.
|
|
1297
|
+
|
|
1298
|
+
**Properties**:
|
|
1299
|
+
- `name`: string - Event name
|
|
1300
|
+
- `signature`: string - Event signature
|
|
1301
|
+
- `args`: Result - Decoded arguments
|
|
1302
|
+
- `fragment`: EventFragment - Event fragment
|
|
1303
|
+
|
|
1304
|
+
---
|
|
1305
|
+
|
|
1306
|
+
### 4.9 ErrorFragment
|
|
1307
|
+
|
|
1308
|
+
**Extends**: AbiFragment
|
|
1309
|
+
|
|
1310
|
+
**Note**: The API matches ethers.js v6 ErrorFragment.
|
|
1311
|
+
|
|
1312
|
+
**Additional Properties**:
|
|
1313
|
+
- `type`: "error" - Fragment type
|
|
1314
|
+
|
|
1315
|
+
**Methods**:
|
|
1316
|
+
|
|
1317
|
+
#### `format(format?: string): string`
|
|
1318
|
+
Formats fragment as string.
|
|
1319
|
+
- `format`: Optional format type
|
|
1320
|
+
|
|
1321
|
+
---
|
|
1322
|
+
|
|
1323
|
+
### 4.10 ErrorDescription
|
|
1324
|
+
|
|
1325
|
+
**Note**: The API matches ethers.js v6 ErrorDescription.
|
|
1326
|
+
|
|
1327
|
+
**Properties**:
|
|
1328
|
+
- `name`: string - Error name
|
|
1329
|
+
- `signature`: string - Error signature
|
|
1330
|
+
- `args`: Result - Decoded error arguments
|
|
1331
|
+
- `fragment`: ErrorFragment - Error fragment
|
|
1332
|
+
|
|
1333
|
+
---
|
|
1334
|
+
|
|
1335
|
+
### 4.11 ConstructorFragment
|
|
1336
|
+
|
|
1337
|
+
**Extends**: AbiFragment
|
|
1338
|
+
|
|
1339
|
+
**Note**: The API matches ethers.js v6 ConstructorFragment.
|
|
1340
|
+
|
|
1341
|
+
**Additional Properties**:
|
|
1342
|
+
- `type`: "constructor" - Fragment type
|
|
1343
|
+
- `payable`: boolean - Whether constructor is payable
|
|
1344
|
+
|
|
1345
|
+
**Methods**:
|
|
1346
|
+
|
|
1347
|
+
#### `format(format?: string): string`
|
|
1348
|
+
Formats fragment as string.
|
|
1349
|
+
- `format`: Optional format type
|
|
1350
|
+
|
|
1351
|
+
---
|
|
1352
|
+
|
|
1353
|
+
### 4.11 ParamType
|
|
1354
|
+
|
|
1355
|
+
**Purpose**: Represents a parameter type in an ABI
|
|
1356
|
+
|
|
1357
|
+
**Constructor**:
|
|
1358
|
+
```javascript
|
|
1359
|
+
constructor(fragment: string | ParamTypeLike)
|
|
1360
|
+
```
|
|
1361
|
+
- `fragment`: Type string or ParamType-like object
|
|
1362
|
+
|
|
1363
|
+
**Properties**:
|
|
1364
|
+
- `type`: string - The base type (e.g., "uint256", "address", "tuple")
|
|
1365
|
+
- `baseType`: string - The base type without array or tuple components
|
|
1366
|
+
- `name`: string | null - Parameter name (if named)
|
|
1367
|
+
- `indexed`: boolean - Whether parameter is indexed (for events)
|
|
1368
|
+
- `components`: ParamType[] | null - Components for tuples/structs
|
|
1369
|
+
- `arrayLength`: number | null - Array length (null for dynamic arrays)
|
|
1370
|
+
- `arrayChildren`: ParamType | null - Type of array elements
|
|
1371
|
+
|
|
1372
|
+
**Methods**:
|
|
1373
|
+
|
|
1374
|
+
#### `format(format?: string): string`
|
|
1375
|
+
Formats the type as a string.
|
|
1376
|
+
- `format`: Optional format type ("full", "minimal", etc.)
|
|
1377
|
+
|
|
1378
|
+
#### `walk(fn: (type: ParamType) => void): void`
|
|
1379
|
+
Recursively walks the type tree, calling fn for each ParamType.
|
|
1380
|
+
|
|
1381
|
+
---
|
|
1382
|
+
|
|
1383
|
+
### 4.13 AbiCoder
|
|
1384
|
+
|
|
1385
|
+
**Note**: The API matches ethers.js v6 AbiCoder.
|
|
1386
|
+
|
|
1387
|
+
**Purpose**: Low-level ABI encoding and decoding utility
|
|
1388
|
+
|
|
1389
|
+
**Constructor**:
|
|
1390
|
+
```javascript
|
|
1391
|
+
constructor()
|
|
1392
|
+
```
|
|
1393
|
+
|
|
1394
|
+
**Methods**:
|
|
1395
|
+
|
|
1396
|
+
#### `encode(types: (string | ParamType)[], values: any[]): string`
|
|
1397
|
+
Encodes an array of values according to their types.
|
|
1398
|
+
- `types`: Array of type strings or ParamType instances
|
|
1399
|
+
- `values`: Array of values to encode
|
|
1400
|
+
- Returns: Encoded hex string
|
|
1401
|
+
- **Implementation**: Uses `packMethodData()` from quantum-coin-js-sdk internally
|
|
1402
|
+
|
|
1403
|
+
#### `decode(types: (string | ParamType)[], data: string, loose?: boolean): Result`
|
|
1404
|
+
Decodes encoded data according to types.
|
|
1405
|
+
- `types`: Array of type strings or ParamType instances
|
|
1406
|
+
- `data`: Encoded hex string
|
|
1407
|
+
- `loose`: Optional flag for loose decoding (handles older Solidity padding issues)
|
|
1408
|
+
- Returns: Result object with decoded values
|
|
1409
|
+
- **Implementation**: Uses `unpackMethodData()` from quantum-coin-js-sdk internally
|
|
1410
|
+
|
|
1411
|
+
#### `getDefaultValue(types: (string | ParamType)[]): Result`
|
|
1412
|
+
Returns the default values for the given types.
|
|
1413
|
+
- `types`: Array of type strings or ParamType instances
|
|
1414
|
+
- Returns: Result object with default values for each type
|
|
1415
|
+
|
|
1416
|
+
---
|
|
1417
|
+
|
|
1418
|
+
## 5. Utility Classes and Functions
|
|
1419
|
+
|
|
1420
|
+
### 5.1 Result
|
|
1421
|
+
|
|
1422
|
+
**Purpose**: Represents decoded ABI data (array-like object with named properties)
|
|
1423
|
+
|
|
1424
|
+
**Extends**: Array
|
|
1425
|
+
|
|
1426
|
+
**Properties**:
|
|
1427
|
+
- Array indices for positional access
|
|
1428
|
+
- Named properties for named parameters
|
|
1429
|
+
|
|
1430
|
+
**Static Methods**:
|
|
1431
|
+
|
|
1432
|
+
#### `Result.fromItems(items: Array<any>, keys?: Array<null | string>): Result`
|
|
1433
|
+
Creates a new Result for items with each entry also accessible by its corresponding name in keys.
|
|
1434
|
+
- `items`: Array of values
|
|
1435
|
+
- `keys`: Optional array of keys (null for unnamed entries)
|
|
1436
|
+
- Returns: Result instance
|
|
1437
|
+
|
|
1438
|
+
**Methods**:
|
|
1439
|
+
|
|
1440
|
+
#### `getValue(name: string): any`
|
|
1441
|
+
Returns the value for name.
|
|
1442
|
+
- `name`: Property name
|
|
1443
|
+
- Returns: The value for the named property
|
|
1444
|
+
- **Note**: This method ensures all named values are accessible even if they conflict with Result methods or JavaScript keywords
|
|
1445
|
+
|
|
1446
|
+
#### `toArray(deep?: boolean): any[]`
|
|
1447
|
+
Converts to array.
|
|
1448
|
+
- `deep`: Optional flag to recursively convert nested Result objects
|
|
1449
|
+
- Returns: Normal array
|
|
1450
|
+
- **Note**: Throws if there are any outstanding deferred errors
|
|
1451
|
+
|
|
1452
|
+
#### `toObject(deep?: boolean): Record<string, any>`
|
|
1453
|
+
Converts to object.
|
|
1454
|
+
- `deep`: Optional flag to recursively convert nested Result objects
|
|
1455
|
+
- Returns: Object with name-value pairs
|
|
1456
|
+
- **Note**: Throws if any value is unnamed or if there are outstanding deferred errors
|
|
1457
|
+
|
|
1458
|
+
#### `checkResultErrors(result: Result): Array<{ error: Error, path: Array<string | number> }>`
|
|
1459
|
+
Returns all errors found in a Result.
|
|
1460
|
+
- `result`: Result instance to check
|
|
1461
|
+
- Returns: Array of error objects with error and path information
|
|
1462
|
+
- **Note**: Certain errors encountered when creating a Result are deferred until accessed. This function allows checking for all errors upfront.
|
|
1463
|
+
|
|
1464
|
+
---
|
|
1465
|
+
|
|
1466
|
+
### 5.2 BytesLike
|
|
1467
|
+
|
|
1468
|
+
**Type**: `string | Uint8Array | ArrayLike<number>`
|
|
1469
|
+
|
|
1470
|
+
---
|
|
1471
|
+
|
|
1472
|
+
### 5.3 BigNumberish
|
|
1473
|
+
|
|
1474
|
+
**Type**: `string | number | bigint`
|
|
1475
|
+
|
|
1476
|
+
---
|
|
1477
|
+
|
|
1478
|
+
### 5.3.1 AddressLike
|
|
1479
|
+
|
|
1480
|
+
**Type**: `string | Promise<string> | Addressable`
|
|
1481
|
+
|
|
1482
|
+
**Purpose**: Anything that can be used to return or resolve an address.
|
|
1483
|
+
|
|
1484
|
+
**Note**: For QuantumCoin, ENS (Ethereum Naming Service) is not applicable, so address resolution is limited to direct addresses and Addressable objects.
|
|
1485
|
+
|
|
1486
|
+
---
|
|
1487
|
+
|
|
1488
|
+
### 5.3.2 Typed Values
|
|
1489
|
+
|
|
1490
|
+
**Purpose**: Typed values provide type-safe encoding and validation for ABI parameters.
|
|
1491
|
+
|
|
1492
|
+
#### Typed (Base Class/Interface)
|
|
1493
|
+
|
|
1494
|
+
**Purpose**: Base class for all typed values.
|
|
1495
|
+
|
|
1496
|
+
**Static Methods**:
|
|
1497
|
+
|
|
1498
|
+
#### `Typed.isTyped(value: any): boolean`
|
|
1499
|
+
Returns true only if value is a Typed instance.
|
|
1500
|
+
- `value`: Value to check
|
|
1501
|
+
- Returns: `true` if value is a Typed instance
|
|
1502
|
+
|
|
1503
|
+
#### `Typed.dereference(value: Typed | T, type: string): T`
|
|
1504
|
+
If the value is a Typed instance, validates the underlying value and returns it, otherwise returns value directly.
|
|
1505
|
+
- `value`: Typed instance or value
|
|
1506
|
+
- `type`: Expected type string
|
|
1507
|
+
- Returns: The underlying value if Typed, otherwise the value itself
|
|
1508
|
+
- **Note**: Useful for functions that accept either a Typed object or values
|
|
1509
|
+
|
|
1510
|
+
**Methods**:
|
|
1511
|
+
|
|
1512
|
+
#### `format(): string`
|
|
1513
|
+
Format the type as a Human-Readable type.
|
|
1514
|
+
- Returns: Formatted type string
|
|
1515
|
+
|
|
1516
|
+
#### `defaultValue(): string | number | bigint | Result`
|
|
1517
|
+
The default value returned by this type.
|
|
1518
|
+
- Returns: Default value for the type
|
|
1519
|
+
|
|
1520
|
+
#### `isBigInt(): boolean`
|
|
1521
|
+
Returns true and provides a type guard if this is a TypedBigInt.
|
|
1522
|
+
- Returns: `true` if this is a TypedBigInt
|
|
1523
|
+
|
|
1524
|
+
#### `isData(): boolean`
|
|
1525
|
+
Returns true and provides a type guard if this is a TypedData.
|
|
1526
|
+
- Returns: `true` if this is a TypedData
|
|
1527
|
+
|
|
1528
|
+
#### `isString(): boolean`
|
|
1529
|
+
Returns true and provides a type guard if this is a TypedString.
|
|
1530
|
+
- Returns: `true` if this is a TypedString
|
|
1531
|
+
|
|
1532
|
+
#### TypedBigInt Interface
|
|
1533
|
+
|
|
1534
|
+
**Extends**: Typed
|
|
1535
|
+
|
|
1536
|
+
**Purpose**: A Typed that represents a numeric value.
|
|
1537
|
+
|
|
1538
|
+
**Properties**:
|
|
1539
|
+
- `value`: bigint - The numeric value
|
|
1540
|
+
|
|
1541
|
+
**Methods**:
|
|
1542
|
+
|
|
1543
|
+
#### `defaultValue(): bigint`
|
|
1544
|
+
The default value for all numeric types is 0.
|
|
1545
|
+
|
|
1546
|
+
#### `maxValue(): bigint`
|
|
1547
|
+
The maximum value for this type, accounting for bit-width.
|
|
1548
|
+
|
|
1549
|
+
#### `minValue(): bigint`
|
|
1550
|
+
The minimum value for this type, accounting for bit-width and signed-ness.
|
|
1551
|
+
|
|
1552
|
+
**Static Methods**: Typed provides static methods for creating typed values:
|
|
1553
|
+
|
|
1554
|
+
**Numeric Types**:
|
|
1555
|
+
- `Typed.uint8(v: BigNumberish): Typed`
|
|
1556
|
+
- `Typed.uint256(v: BigNumberish): Typed`
|
|
1557
|
+
- `Typed.int8(v: BigNumberish): Typed`
|
|
1558
|
+
- `Typed.int256(v: BigNumberish): Typed`
|
|
1559
|
+
- And all other uint/int variants (uint8 through uint256, int8 through int256)
|
|
1560
|
+
|
|
1561
|
+
**Other Types**:
|
|
1562
|
+
- `Typed.address(v: string): Typed` - Creates a typed address
|
|
1563
|
+
- `Typed.bool(v: boolean): Typed` - Creates a typed boolean
|
|
1564
|
+
- `Typed.bytes(v: BytesLike, length?: number): Typed` - Creates typed bytes (length optional for dynamic bytes)
|
|
1565
|
+
- `Typed.string(v: string): Typed` - Creates a typed string
|
|
1566
|
+
- `Typed.array(v: any[], type: string): Typed` - Creates a typed array
|
|
1567
|
+
- `Typed.tuple(v: any[], types: string[]): Typed` - Creates a typed tuple
|
|
1568
|
+
|
|
1569
|
+
#### TypedData Interface
|
|
1570
|
+
|
|
1571
|
+
**Extends**: Typed
|
|
1572
|
+
|
|
1573
|
+
**Purpose**: A Typed that represents a binary sequence of data as bytes.
|
|
1574
|
+
|
|
1575
|
+
**Properties**:
|
|
1576
|
+
- `value`: string - The hex string value
|
|
1577
|
+
|
|
1578
|
+
**Methods**:
|
|
1579
|
+
|
|
1580
|
+
#### `defaultValue(): string`
|
|
1581
|
+
The default value for this type (empty hex string "0x").
|
|
1582
|
+
|
|
1583
|
+
#### TypedString Interface
|
|
1584
|
+
|
|
1585
|
+
**Extends**: Typed
|
|
1586
|
+
|
|
1587
|
+
**Purpose**: A Typed that represents a UTF-8 sequence of bytes.
|
|
1588
|
+
|
|
1589
|
+
**Properties**:
|
|
1590
|
+
- `value`: string - The string value
|
|
1591
|
+
|
|
1592
|
+
**Methods**:
|
|
1593
|
+
|
|
1594
|
+
#### `defaultValue(): string`
|
|
1595
|
+
The default value for the string type is the empty string (i.e. "").
|
|
1596
|
+
|
|
1597
|
+
**Note**: Typed values are primarily used for type-safe ABI encoding. For QuantumCoin, these should work with quantum-coin-js-sdk's ABI encoding functions.
|
|
1598
|
+
|
|
1599
|
+
---
|
|
1600
|
+
|
|
1601
|
+
### 5.3.3 BlockTag
|
|
1602
|
+
|
|
1603
|
+
**Type**: `number | "latest" | "pending" | "earliest"`
|
|
1604
|
+
|
|
1605
|
+
**Purpose**: Represents a block identifier for queries.
|
|
1606
|
+
|
|
1607
|
+
**Values**:
|
|
1608
|
+
- `number`: Specific block number
|
|
1609
|
+
- `"latest"`: Latest block (default)
|
|
1610
|
+
- `"pending"`: Pending block (mempool)
|
|
1611
|
+
- `"earliest"`: Earliest block (genesis)
|
|
1612
|
+
|
|
1613
|
+
---
|
|
1614
|
+
|
|
1615
|
+
### 5.3.4 ProviderEventFilter
|
|
1616
|
+
|
|
1617
|
+
**Type**: `{ address?: string | string[], topics?: (string | string[] | null)[] }`
|
|
1618
|
+
|
|
1619
|
+
**Purpose**: Filter for provider events (blocks, transactions, logs).
|
|
1620
|
+
|
|
1621
|
+
**Properties**:
|
|
1622
|
+
- `address`: Optional contract address(es) to filter
|
|
1623
|
+
- `topics`: Optional event topics to filter
|
|
1624
|
+
|
|
1625
|
+
---
|
|
1626
|
+
|
|
1627
|
+
### 5.3.5 EventFilter
|
|
1628
|
+
|
|
1629
|
+
**Type**: `Filter`
|
|
1630
|
+
|
|
1631
|
+
**Purpose**: Alias for Filter type, used for event filtering.
|
|
1632
|
+
|
|
1633
|
+
**Note**: This is the same as the Filter type defined in Section 1.7.
|
|
1634
|
+
|
|
1635
|
+
---
|
|
1636
|
+
|
|
1637
|
+
### 5.3.6 SigningKey
|
|
1638
|
+
|
|
1639
|
+
**Purpose**: Represents a signing key used for cryptographic operations
|
|
1640
|
+
|
|
1641
|
+
**Constructor**:
|
|
1642
|
+
```javascript
|
|
1643
|
+
constructor(privateKey: string | Uint8Array)
|
|
1644
|
+
```
|
|
1645
|
+
- `privateKey`: Private key as hex string or byte array
|
|
1646
|
+
|
|
1647
|
+
**Properties**:
|
|
1648
|
+
- `privateKey`: string - Private key as hex string
|
|
1649
|
+
- `publicKey`: string - Public key
|
|
1650
|
+
|
|
1651
|
+
**Methods**:
|
|
1652
|
+
|
|
1653
|
+
#### `sign(digest: BytesLike): Signature`
|
|
1654
|
+
Signs a message digest.
|
|
1655
|
+
- `digest`: Message digest to sign
|
|
1656
|
+
- Returns: Signature object
|
|
1657
|
+
|
|
1658
|
+
**Note**: SigningKey is used internally by BaseWallet and Wallet for signing operations. Can be created from a private key and used in Wallet constructor. The API matches ethers.js v6 SigningKey.
|
|
1659
|
+
|
|
1660
|
+
---
|
|
1661
|
+
|
|
1662
|
+
### 5.3.7 Signature
|
|
1663
|
+
|
|
1664
|
+
**Purpose**: Represents a cryptographic signature
|
|
1665
|
+
|
|
1666
|
+
**Properties**:
|
|
1667
|
+
- `r`: string - R component of signature (hex string)
|
|
1668
|
+
- `s`: string - S component of signature (hex string)
|
|
1669
|
+
- `v`: number - Recovery ID (0 or 1)
|
|
1670
|
+
|
|
1671
|
+
**Methods**:
|
|
1672
|
+
|
|
1673
|
+
#### `serialize(): string`
|
|
1674
|
+
Serializes signature to compact format.
|
|
1675
|
+
- Returns: Serialized signature hex string
|
|
1676
|
+
|
|
1677
|
+
**Static Methods**:
|
|
1678
|
+
|
|
1679
|
+
#### `Signature.from(signature: string | SignatureLike): Signature`
|
|
1680
|
+
Creates a Signature from various formats.
|
|
1681
|
+
- `signature`: Signature string, object, or Signature instance
|
|
1682
|
+
- Returns: Signature instance
|
|
1683
|
+
|
|
1684
|
+
**Note**: The API matches ethers.js v6 Signature, with QuantumCoin-specific simplifications (removed network-specific fields and legacy conversion methods).
|
|
1685
|
+
|
|
1686
|
+
---
|
|
1687
|
+
|
|
1688
|
+
### 5.3.8 Transaction
|
|
1689
|
+
|
|
1690
|
+
**Purpose**: Represents a transaction object
|
|
1691
|
+
|
|
1692
|
+
**Type**: Interface/Class
|
|
1693
|
+
|
|
1694
|
+
**Properties**:
|
|
1695
|
+
- `to`: string | null - Recipient address (null for contract creation)
|
|
1696
|
+
- `from`: string | null - Sender address (null if not specified)
|
|
1697
|
+
- `nonce`: number | null - Transaction nonce
|
|
1698
|
+
- `gasLimit`: bigint | null - Gas limit
|
|
1699
|
+
- `gasPrice`: bigint | null - Gas price
|
|
1700
|
+
- `value`: bigint | null - Transaction value in wei
|
|
1701
|
+
- `data`: string | null - Transaction data (hex string)
|
|
1702
|
+
- `chainId`: bigint | null - Chain ID
|
|
1703
|
+
- `hash`: string | null - Transaction hash
|
|
1704
|
+
- `type`: number | null - Transaction type
|
|
1705
|
+
- `accessList`: Array<{ address: string, storageKeys: string[] }> | null - Access list (EIP-2930)
|
|
1706
|
+
|
|
1707
|
+
**Methods**:
|
|
1708
|
+
|
|
1709
|
+
#### `serialize(): string`
|
|
1710
|
+
Serializes transaction to hex string.
|
|
1711
|
+
- Returns: Serialized transaction hex string
|
|
1712
|
+
|
|
1713
|
+
#### `unsignedHash(): string`
|
|
1714
|
+
Computes hash of unsigned transaction.
|
|
1715
|
+
- Returns: Transaction hash (32 bytes, 66 hex characters including 0x)
|
|
1716
|
+
|
|
1717
|
+
**Static Methods**:
|
|
1718
|
+
|
|
1719
|
+
#### `Transaction.from(tx: string | TransactionLike): Transaction`
|
|
1720
|
+
Creates a Transaction from various formats.
|
|
1721
|
+
- `tx`: Transaction string, object, or Transaction instance
|
|
1722
|
+
- Returns: Transaction instance
|
|
1723
|
+
|
|
1724
|
+
**Note**: The API matches ethers.js v6 Transaction. For QuantumCoin, transaction structure follows QuantumCoin conventions.
|
|
1725
|
+
|
|
1726
|
+
---
|
|
1727
|
+
|
|
1728
|
+
### 5.3.9 Indexed
|
|
1729
|
+
|
|
1730
|
+
**Purpose**: Type guard/interface for indexed event parameters
|
|
1731
|
+
|
|
1732
|
+
**Note**: This interface/type is exported from ethers.js but not implemented in quantumcoin.js. It is listed here for API compatibility reference.
|
|
1733
|
+
|
|
1734
|
+
---
|
|
1735
|
+
|
|
1736
|
+
### 5.3.9.1 TypedDataEncoder
|
|
1737
|
+
|
|
1738
|
+
**Purpose**: Encoder for EIP-712 typed data
|
|
1739
|
+
|
|
1740
|
+
**Note**: This class is exported from ethers.js but not implemented in quantumcoin.js. It is listed here for API compatibility reference.
|
|
1741
|
+
|
|
1742
|
+
**Type**: `{ indexed: true, hash?: string }`
|
|
1743
|
+
|
|
1744
|
+
**Purpose**: Used to mark event parameters as indexed. When an event parameter is indexed, it is hashed and stored in the topics array of the log.
|
|
1745
|
+
|
|
1746
|
+
**Note**: The API matches ethers.js v6 Indexed type. This is used in event filtering and decoding.
|
|
1747
|
+
|
|
1748
|
+
---
|
|
1749
|
+
|
|
1750
|
+
### 5.3.10 KeystoreAccount
|
|
1751
|
+
|
|
1752
|
+
**Type**: `{ address: string, mnemonic?: { entropy: string }, privateKey: string }`
|
|
1753
|
+
|
|
1754
|
+
**Purpose**: Contents of a JSON Keystore Wallet
|
|
1755
|
+
|
|
1756
|
+
**Properties**:
|
|
1757
|
+
- `address`: string - Wallet address
|
|
1758
|
+
- `privateKey`: string - Private key as hex string
|
|
1759
|
+
- `mnemonic?`: Optional object containing:
|
|
1760
|
+
- `entropy`: string - Mnemonic entropy
|
|
1761
|
+
|
|
1762
|
+
**Note**: Used by `encryptKeystoreJsonSync()` and `decryptKeystoreJsonSync()` functions. For QuantumCoin, the mnemonic field is optional and may contain entropy for 48-word phrases.
|
|
1763
|
+
|
|
1764
|
+
---
|
|
1765
|
+
|
|
1766
|
+
### 5.4 Address Utilities
|
|
1767
|
+
|
|
1768
|
+
#### `isAddress(address: string): boolean`
|
|
1769
|
+
Checks if string is a valid address (32 bytes, 66 hex characters).
|
|
1770
|
+
- `address`: String to validate
|
|
1771
|
+
- Returns: `true` if valid address, `false` otherwise
|
|
1772
|
+
|
|
1773
|
+
#### `getAddress(address: string): string`
|
|
1774
|
+
Returns checksummed address (normalized for QuantumCoin).
|
|
1775
|
+
- `address`: Address string to normalize
|
|
1776
|
+
- Returns: Normalized and checksummed address (32 bytes, 66 hex characters)
|
|
1777
|
+
- **Note**: For QuantumCoin, address checksumming follows QuantumCoin conventions (not Ethereum EIP-55)
|
|
1778
|
+
|
|
1779
|
+
#### `isAddressable(value: any): boolean`
|
|
1780
|
+
Returns true if value is an object which implements the Addressable interface.
|
|
1781
|
+
- `value`: Value to check
|
|
1782
|
+
- Returns: `true` if value implements Addressable interface
|
|
1783
|
+
- **Note**: Wallets, Signers, and Contracts implement Addressable
|
|
1784
|
+
|
|
1785
|
+
#### `resolveAddress(target: AddressLike): string | Promise<string>`
|
|
1786
|
+
Resolves to an address for the target, which may be any supported address type, an Addressable or a Promise which resolves to an address.
|
|
1787
|
+
- `target`: Address string, Addressable object, or Promise resolving to address
|
|
1788
|
+
- Returns: Address string (synchronously) or Promise resolving to address string
|
|
1789
|
+
- **Note**: For QuantumCoin, ENS resolution is not supported. Only direct addresses and Addressable objects are supported.
|
|
1790
|
+
|
|
1791
|
+
#### `getContractAddress(tx: { from: string, nonce: number }): string`
|
|
1792
|
+
Calculates contract address from deployer and nonce.
|
|
1793
|
+
- **Implementation**: Uses `createAddress()` from quantum-coin-js-sdk internally
|
|
1794
|
+
- `tx.from`: Deployer address (32 bytes, 66 hex characters)
|
|
1795
|
+
- `tx.nonce`: Deployer nonce (number)
|
|
1796
|
+
- Returns: Contract address (32 bytes, 66 hex characters)
|
|
1797
|
+
|
|
1798
|
+
#### `getCreateAddress(tx: { from: string, nonce: number }): string`
|
|
1799
|
+
Gets CREATE address (alias for getContractAddress).
|
|
1800
|
+
- `tx.from`: Deployer address
|
|
1801
|
+
- `tx.nonce`: Deployer nonce
|
|
1802
|
+
- Returns: Contract address
|
|
1803
|
+
|
|
1804
|
+
#### `getCreate2Address(from: string, salt: string, initCodeHash: string): string`
|
|
1805
|
+
Calculates CREATE2 contract address.
|
|
1806
|
+
- **Implementation**: Uses `createAddress2()` from quantum-coin-js-sdk internally
|
|
1807
|
+
- `from`: Deployer address (32 bytes, 66 hex characters)
|
|
1808
|
+
- `salt`: Salt value (hex string)
|
|
1809
|
+
- `initCodeHash`: Hash of initialization code (hex string)
|
|
1810
|
+
- Returns: CREATE2 contract address (32 bytes, 66 hex characters)
|
|
1811
|
+
|
|
1812
|
+
#### `computeAddress(key: string | Uint8Array): string`
|
|
1813
|
+
Computes address from public key.
|
|
1814
|
+
- `key`: Public key as hex string or byte array
|
|
1815
|
+
- Returns: Computed address (32 bytes, 66 hex characters including 0x)
|
|
1816
|
+
- **Implementation**: Uses quantum-coin-js-sdk's `addressFromPublicKey()` internally
|
|
1817
|
+
|
|
1818
|
+
#### `verifyMessage(message: string | Uint8Array, signature: string): string`
|
|
1819
|
+
Verifies a message signature and recovers the address.
|
|
1820
|
+
- `message`: Message that was signed
|
|
1821
|
+
- `signature`: Signature to verify (hex string)
|
|
1822
|
+
- Returns: Address that signed the message
|
|
1823
|
+
- **Implementation**: Uses quantum-coin-js-sdk for signature verification
|
|
1824
|
+
|
|
1825
|
+
#### `recoverAddress(message: string | Uint8Array, signature: string): string`
|
|
1826
|
+
Recovers the address from a message signature.
|
|
1827
|
+
- `message`: Message that was signed
|
|
1828
|
+
- `signature`: Signature (hex string)
|
|
1829
|
+
- Returns: Address that signed the message
|
|
1830
|
+
- **Implementation**: Uses quantum-coin-js-sdk for signature recovery
|
|
1831
|
+
|
|
1832
|
+
### 5.4.1 Addressable Interface
|
|
1833
|
+
|
|
1834
|
+
**Purpose**: An interface for objects which have an address, and can resolve it asynchronously.
|
|
1835
|
+
|
|
1836
|
+
**Methods**:
|
|
1837
|
+
|
|
1838
|
+
#### `getAddress(): Promise<string>`
|
|
1839
|
+
Get the object address.
|
|
1840
|
+
- Returns: Promise resolving to the address string
|
|
1841
|
+
|
|
1842
|
+
**Note**: Wallets, Signers, and Contracts implement this interface, allowing them to be used anywhere an address is expected.
|
|
1843
|
+
|
|
1844
|
+
---
|
|
1845
|
+
|
|
1846
|
+
### 5.5 Encoding/Decoding Utilities
|
|
1847
|
+
|
|
1848
|
+
#### `toUtf8String(data: BytesLike): string`
|
|
1849
|
+
Converts bytes to UTF-8 string.
|
|
1850
|
+
|
|
1851
|
+
#### `toUtf8Bytes(str: string): Uint8Array`
|
|
1852
|
+
Converts string to UTF-8 bytes.
|
|
1853
|
+
|
|
1854
|
+
#### `toHex(data: BytesLike): string`
|
|
1855
|
+
Converts data to hex string.
|
|
1856
|
+
|
|
1857
|
+
#### `hexlify(data: BytesLike): string`
|
|
1858
|
+
Converts data to hex string (alias for toHex).
|
|
1859
|
+
|
|
1860
|
+
#### `arrayify(data: BytesLike): Uint8Array`
|
|
1861
|
+
Converts data to byte array.
|
|
1862
|
+
|
|
1863
|
+
#### `concat(items: BytesLike[]): string`
|
|
1864
|
+
Concatenates byte arrays.
|
|
1865
|
+
|
|
1866
|
+
#### `stripZerosLeft(data: BytesLike): string`
|
|
1867
|
+
Strips leading zeros from hex string.
|
|
1868
|
+
|
|
1869
|
+
#### `encodeBytes32String(text: string): string`
|
|
1870
|
+
Encodes text as a Bytes32 string.
|
|
1871
|
+
- `text`: Text string to encode
|
|
1872
|
+
- Returns: Hex string (32 bytes, 66 hex characters including 0x)
|
|
1873
|
+
- **Note**: Text is padded or truncated to exactly 32 bytes
|
|
1874
|
+
|
|
1875
|
+
#### `decodeBytes32String(bytes: BytesLike): string`
|
|
1876
|
+
Decodes the Bytes32-encoded bytes into a string.
|
|
1877
|
+
- `bytes`: Bytes32-encoded data (hex string or bytes)
|
|
1878
|
+
- Returns: Decoded text string
|
|
1879
|
+
- **Note**: Removes null padding from the decoded string
|
|
1880
|
+
|
|
1881
|
+
#### `decodeBase58(data: string): Uint8Array`
|
|
1882
|
+
Decodes Base58-encoded data.
|
|
1883
|
+
|
|
1884
|
+
**Note**: This function is exported from ethers.js but not implemented in quantumcoin.js. It is listed here for API compatibility reference.
|
|
1885
|
+
|
|
1886
|
+
---
|
|
1887
|
+
|
|
1888
|
+
#### `decodeBase64(data: string): Uint8Array`
|
|
1889
|
+
Decodes Base64-encoded data.
|
|
1890
|
+
|
|
1891
|
+
**Note**: This function is exported from ethers.js but not implemented in quantumcoin.js. It is listed here for API compatibility reference.
|
|
1892
|
+
|
|
1893
|
+
---
|
|
1894
|
+
|
|
1895
|
+
#### `encodeBase58(data: BytesLike): string`
|
|
1896
|
+
Encodes data to Base58 string.
|
|
1897
|
+
|
|
1898
|
+
**Note**: This function is exported from ethers.js but not implemented in quantumcoin.js. It is listed here for API compatibility reference.
|
|
1899
|
+
|
|
1900
|
+
---
|
|
1901
|
+
|
|
1902
|
+
#### `encodeBase64(data: BytesLike): string`
|
|
1903
|
+
Encodes data to Base64 string.
|
|
1904
|
+
|
|
1905
|
+
**Note**: This function is exported from ethers.js but not implemented in quantumcoin.js. It is listed here for API compatibility reference.
|
|
1906
|
+
|
|
1907
|
+
---
|
|
1908
|
+
|
|
1909
|
+
#### `toUtf8CodePoints(str: string): number[]`
|
|
1910
|
+
Converts string to UTF-8 code points array.
|
|
1911
|
+
|
|
1912
|
+
**Note**: This function is exported from ethers.js but not implemented in quantumcoin.js. It is listed here for API compatibility reference.
|
|
1913
|
+
|
|
1914
|
+
---
|
|
1915
|
+
|
|
1916
|
+
#### `isHexString(value: any, length?: number): boolean`
|
|
1917
|
+
Checks if value is a valid hex string.
|
|
1918
|
+
- `value`: Value to check
|
|
1919
|
+
- `length`: Optional expected length in bytes
|
|
1920
|
+
- Returns: `true` if value is a valid hex string, `false` otherwise
|
|
1921
|
+
|
|
1922
|
+
#### `isBytesLike(value: any): boolean`
|
|
1923
|
+
Checks if value is bytes-like (string, Uint8Array, or ArrayLike<number>).
|
|
1924
|
+
- `value`: Value to check
|
|
1925
|
+
- Returns: `true` if value is bytes-like, `false` otherwise
|
|
1926
|
+
|
|
1927
|
+
#### `zeroPad(value: BytesLike, length: number): string`
|
|
1928
|
+
Zero-pads a value to the specified length.
|
|
1929
|
+
- `value`: Value to pad
|
|
1930
|
+
- `length`: Target length in bytes
|
|
1931
|
+
- Returns: Zero-padded hex string
|
|
1932
|
+
|
|
1933
|
+
#### `zeroPadValue(value: BytesLike, length: number): string`
|
|
1934
|
+
Zero-pads a value to the specified length (left-pads).
|
|
1935
|
+
- `value`: Value to pad
|
|
1936
|
+
- `length`: Target length in bytes
|
|
1937
|
+
- Returns: Zero-padded hex string
|
|
1938
|
+
|
|
1939
|
+
#### `solidityPacked(types: string[], values: any[]): string`
|
|
1940
|
+
Encodes values using Solidity's packed encoding (no padding, tightly packed).
|
|
1941
|
+
- `types`: Array of Solidity type strings
|
|
1942
|
+
- `values`: Array of values to encode
|
|
1943
|
+
- Returns: Packed encoded hex string
|
|
1944
|
+
- **Note**: This is different from ABI encoding - values are tightly packed without padding
|
|
1945
|
+
|
|
1946
|
+
#### `solidityPackedKeccak256(types: string[], values: any[]): string`
|
|
1947
|
+
Encodes values using Solidity's packed encoding and computes keccak256 hash.
|
|
1948
|
+
- `types`: Array of Solidity type strings
|
|
1949
|
+
- `values`: Array of values to encode
|
|
1950
|
+
- Returns: Keccak256 hash of packed encoding (32 bytes, 66 hex characters including 0x)
|
|
1951
|
+
|
|
1952
|
+
#### `solidityPackedSha256(types: string[], values: any[]): string`
|
|
1953
|
+
Encodes values using Solidity's packed encoding and computes SHA-256 hash.
|
|
1954
|
+
- `types`: Array of Solidity type strings
|
|
1955
|
+
- `values`: Array of values to encode
|
|
1956
|
+
- Returns: SHA-256 hash of packed encoding (32 bytes, 66 hex characters including 0x)
|
|
1957
|
+
|
|
1958
|
+
---
|
|
1959
|
+
|
|
1960
|
+
### 5.6 BigNumber Utilities
|
|
1961
|
+
|
|
1962
|
+
#### `formatUnits(value: BigNumberish, decimals?: number): string`
|
|
1963
|
+
Formats value with decimals.
|
|
1964
|
+
|
|
1965
|
+
#### `parseUnits(value: string, decimals?: number): bigint`
|
|
1966
|
+
Parses value with decimals.
|
|
1967
|
+
|
|
1968
|
+
#### `formatEther(value: BigNumberish): string`
|
|
1969
|
+
Formats wei to ether (18 decimals).
|
|
1970
|
+
|
|
1971
|
+
#### `parseEther(value: string): bigint`
|
|
1972
|
+
Parses ether to wei (18 decimals).
|
|
1973
|
+
|
|
1974
|
+
---
|
|
1975
|
+
|
|
1976
|
+
### 5.7 Hash Utilities
|
|
1977
|
+
|
|
1978
|
+
#### `keccak256(data: BytesLike): string`
|
|
1979
|
+
Computes Keccak-256 hash.
|
|
1980
|
+
- `data`: Data to hash
|
|
1981
|
+
- Returns: Hex string (32 bytes, 66 hex characters including 0x)
|
|
1982
|
+
|
|
1983
|
+
#### `sha256(data: BytesLike): string`
|
|
1984
|
+
Computes SHA-256 hash.
|
|
1985
|
+
- `data`: Data to hash
|
|
1986
|
+
- Returns: Hex string (32 bytes, 66 hex characters including 0x)
|
|
1987
|
+
|
|
1988
|
+
#### `ripemd160(data: BytesLike): string`
|
|
1989
|
+
Computes RIPEMD-160 hash.
|
|
1990
|
+
- `data`: Data to hash
|
|
1991
|
+
- Returns: Hex string (20 bytes, 42 hex characters including 0x)
|
|
1992
|
+
|
|
1993
|
+
#### `id(text: string): string`
|
|
1994
|
+
Creates a keccak256 hash of a string (commonly used for function selectors).
|
|
1995
|
+
- `text`: Text string to hash
|
|
1996
|
+
- Returns: Hex string (32 bytes, 66 hex characters including 0x)
|
|
1997
|
+
- **Note**: This is equivalent to `keccak256(toUtf8Bytes(text))`
|
|
1998
|
+
|
|
1999
|
+
#### `sha512(data: BytesLike): string`
|
|
2000
|
+
Computes SHA-512 hash.
|
|
2001
|
+
- `data`: Data to hash
|
|
2002
|
+
- Returns: Hex string (64 bytes, 130 hex characters including 0x)
|
|
2003
|
+
|
|
2004
|
+
---
|
|
2005
|
+
|
|
2006
|
+
### 5.8 Random Utilities
|
|
2007
|
+
|
|
2008
|
+
#### `randomBytes(length: number): Uint8Array`
|
|
2009
|
+
Generates random bytes.
|
|
2010
|
+
- `length`: Number of random bytes to generate
|
|
2011
|
+
- Returns: Uint8Array containing random bytes
|
|
2012
|
+
- **Implementation**: Uses Node.js `crypto.randomBytes()` for Node.js environments. For browser environments, uses `crypto.getRandomValues()` from the Web Crypto API.
|
|
2013
|
+
|
|
2014
|
+
#### `computeHmac(algorithm: string, key: BytesLike, data: BytesLike): string`
|
|
2015
|
+
Computes HMAC (Hash-based Message Authentication Code).
|
|
2016
|
+
- `algorithm`: Hash algorithm to use (e.g., "sha256", "sha512")
|
|
2017
|
+
- `key`: Secret key for HMAC computation
|
|
2018
|
+
- `data`: Data to compute HMAC for
|
|
2019
|
+
- Returns: HMAC as hex string
|
|
2020
|
+
- **Implementation**: Uses Node.js `crypto.createHmac()` for Node.js environments. For browser environments, uses Web Crypto API's `crypto.subtle.sign()` with HMAC algorithm.
|
|
2021
|
+
- **Supported algorithms**: "sha256", "sha512" (and other algorithms supported by the underlying crypto implementation)
|
|
2022
|
+
|
|
2023
|
+
#### `pbkdf2(password: BytesLike, salt: BytesLike, iterations: number, keylen: number, algorithm?: string): string`
|
|
2024
|
+
Derives a key using PBKDF2 (Password-Based Key Derivation Function 2).
|
|
2025
|
+
- `password`: Password to derive key from
|
|
2026
|
+
- `salt`: Salt value (should be random bytes)
|
|
2027
|
+
- `iterations`: Number of iterations (higher is more secure but slower)
|
|
2028
|
+
- `keylen`: Desired key length in bytes
|
|
2029
|
+
- `algorithm`: Hash algorithm to use (default: "sha256")
|
|
2030
|
+
- Returns: Derived key as hex string
|
|
2031
|
+
- **Implementation**: Uses Node.js `crypto.pbkdf2Sync()` for Node.js environments. For browser environments, uses Web Crypto API's `crypto.subtle.deriveBits()` with PBKDF2 algorithm.
|
|
2032
|
+
- **Note**: This is a synchronous function that may block the event loop for a significant duration depending on the number of iterations.
|
|
2033
|
+
|
|
2034
|
+
#### `scrypt(password: BytesLike, salt: BytesLike, N: number, r: number, p: number, dkLen: number): string`
|
|
2035
|
+
Derives a key using scrypt key derivation function.
|
|
2036
|
+
- `password`: Password to derive key from
|
|
2037
|
+
- `salt`: Salt value (should be random bytes)
|
|
2038
|
+
- `N`: CPU/memory cost parameter (must be a power of 2, e.g., 16384, 32768)
|
|
2039
|
+
- `r`: Block size parameter (typically 8)
|
|
2040
|
+
- `p`: Parallelization parameter (typically 1)
|
|
2041
|
+
- `dkLen`: Desired key length in bytes
|
|
2042
|
+
- Returns: Derived key as hex string
|
|
2043
|
+
- **Implementation**: Uses Node.js `crypto.scryptSync()` for Node.js environments. For browser environments, may require a polyfill or WebAssembly implementation as Web Crypto API does not support scrypt natively.
|
|
2044
|
+
- **Note**: This is a synchronous function that may block the event loop for a significant duration depending on the parameters (especially N). scrypt is memory-hard and computationally expensive, making it resistant to hardware-accelerated attacks.
|
|
2045
|
+
|
|
2046
|
+
#### `scryptSync(password: BytesLike, salt: BytesLike, N: number, r: number, p: number, dkLen: number): string`
|
|
2047
|
+
Synchronous version of scrypt key derivation.
|
|
2048
|
+
|
|
2049
|
+
**Note**: This function is exported from ethers.js but not implemented in quantumcoin.js. It is listed here for API compatibility reference. The `scrypt()` function in quantumcoin.js is already synchronous.
|
|
2050
|
+
|
|
2051
|
+
---
|
|
2052
|
+
|
|
2053
|
+
### 5.9 RLP Encoding
|
|
2054
|
+
|
|
2055
|
+
#### `encodeRlp(value: any): string`
|
|
2056
|
+
Encodes value using RLP.
|
|
2057
|
+
|
|
2058
|
+
#### `decodeRlp(data: string): any`
|
|
2059
|
+
Decodes RLP data.
|
|
2060
|
+
|
|
2061
|
+
---
|
|
2062
|
+
|
|
2063
|
+
### 5.10 Provider Utility Functions
|
|
2064
|
+
|
|
2065
|
+
#### `copyRequest(req: TransactionRequest): PreparedTransactionRequest`
|
|
2066
|
+
Returns a copy of req with all properties coerced to their strict types.
|
|
2067
|
+
- `req`: Transaction request to copy
|
|
2068
|
+
- Returns: PreparedTransactionRequest with normalized properties
|
|
2069
|
+
|
|
2070
|
+
#### `getDefaultProvider(network?: Networkish, options?: any): FallbackProvider`
|
|
2071
|
+
Gets default provider.
|
|
2072
|
+
- `network`: Optional network identifier
|
|
2073
|
+
- `options`: Optional provider options
|
|
2074
|
+
- Returns: FallbackProvider instance
|
|
2075
|
+
|
|
2076
|
+
#### `showThrottleMessage(): void`
|
|
2077
|
+
Shows throttle message.
|
|
2078
|
+
- **Note**: Internal utility for rate limiting messages
|
|
2079
|
+
|
|
2080
|
+
#### `accessListify(accessList: any[]): Array<{address: string, storageKeys: string[]}>`
|
|
2081
|
+
Normalizes access list.
|
|
2082
|
+
- `accessList`: Access list to normalize
|
|
2083
|
+
- Returns: Normalized access list
|
|
2084
|
+
|
|
2085
|
+
---
|
|
2086
|
+
|
|
2087
|
+
### 5.11 JSON Wallet Utilities
|
|
2088
|
+
|
|
2089
|
+
#### `isKeystoreJson(json: string): boolean`
|
|
2090
|
+
Returns true if json is a valid JSON Keystore Wallet.
|
|
2091
|
+
- `json`: JSON string to validate
|
|
2092
|
+
- Returns: `true` if valid keystore JSON, `false` otherwise
|
|
2093
|
+
|
|
2094
|
+
#### `encryptKeystoreJsonSync(account: KeystoreAccount, password: string | Uint8Array): string`
|
|
2095
|
+
Returns a JSON Keystore Wallet for account encrypted with password (synchronous).
|
|
2096
|
+
- `account`: KeystoreAccount object with address, privateKey, and optional mnemonic
|
|
2097
|
+
- `password`: Password for encryption
|
|
2098
|
+
- Returns: Encrypted JSON Keystore Wallet string
|
|
2099
|
+
- **Implementation**: Uses `serializeEncryptedWallet()` from quantum-coin-js-sdk internally
|
|
2100
|
+
- **Note**: This method will block the event loop until encryption is complete. Uses default encryption parameters.
|
|
2101
|
+
|
|
2102
|
+
#### `decryptKeystoreJsonSync(json: string, password: string | Uint8Array): KeystoreAccount`
|
|
2103
|
+
Returns account details for JSON Keystore Wallet using password (synchronous).
|
|
2104
|
+
- `json`: JSON Keystore Wallet string
|
|
2105
|
+
- `password`: Password for decryption
|
|
2106
|
+
- Returns: KeystoreAccount object with address, privateKey, and optional mnemonic
|
|
2107
|
+
- **Implementation**: Uses `deserializeEncryptedWallet()` from quantum-coin-js-sdk internally
|
|
2108
|
+
- **Note**: This method will block the event loop until decryption is complete, which may take some time.
|
|
2109
|
+
|
|
2110
|
+
---
|
|
2111
|
+
|
|
2112
|
+
### 5.12 Mnemonic
|
|
2113
|
+
|
|
2114
|
+
**Purpose**: Wraps all properties required to compute seeds and convert between phrases and entropy
|
|
2115
|
+
|
|
2116
|
+
**Properties**:
|
|
2117
|
+
- `entropy`: string (read-only) - The underlying entropy which the mnemonic encodes
|
|
2118
|
+
- `password`: string (read-only) - The password used for this mnemonic (empty string if no password)
|
|
2119
|
+
- `phrase`: string (read-only) - The mnemonic phrase (48 words for QuantumCoin)
|
|
2120
|
+
- `wordlist`: Wordlist (read-only) - The wordlist for this mnemonic
|
|
2121
|
+
- **Note**: Wordlist is a type representing a list of words used for mnemonic generation. For QuantumCoin, a 48-word wordlist is used. The API matches ethers.js v6 Mnemonic, with QuantumCoin-specific simplifications (removed locale and path fields).
|
|
2122
|
+
|
|
2123
|
+
---
|
|
2124
|
+
|
|
2125
|
+
### 5.13 Wordlist
|
|
2126
|
+
|
|
2127
|
+
**Purpose**: Represents a wordlist for mnemonic phrase generation
|
|
2128
|
+
|
|
2129
|
+
**Note**: This is an abstract base class/interface. For QuantumCoin, the `seed-words` library (a dependency of quantum-coin-js-sdk) is used internally for wordlist operations.
|
|
2130
|
+
|
|
2131
|
+
**Properties**:
|
|
2132
|
+
- `locale`: string - Locale identifier for the wordlist
|
|
2133
|
+
|
|
2134
|
+
**Methods**:
|
|
2135
|
+
|
|
2136
|
+
#### `getWord(index: number): string`
|
|
2137
|
+
Returns the word at the specified index.
|
|
2138
|
+
- `index`: Word index (0-based)
|
|
2139
|
+
- Returns: Word string
|
|
2140
|
+
|
|
2141
|
+
#### `getWordIndex(word: string): number`
|
|
2142
|
+
Returns the index of the specified word.
|
|
2143
|
+
- `word`: Word to find
|
|
2144
|
+
- Returns: Word index, or -1 if not found
|
|
2145
|
+
|
|
2146
|
+
#### `split(mnemonic: string): Array<string>`
|
|
2147
|
+
Splits a mnemonic phrase into individual words.
|
|
2148
|
+
- `mnemonic`: Mnemonic phrase string
|
|
2149
|
+
- Returns: Array of word strings
|
|
2150
|
+
|
|
2151
|
+
#### `join(words: Array<string>): string`
|
|
2152
|
+
Joins words into a mnemonic phrase.
|
|
2153
|
+
- `words`: Array of word strings
|
|
2154
|
+
- Returns: Mnemonic phrase string
|
|
2155
|
+
|
|
2156
|
+
**Static Methods**:
|
|
2157
|
+
|
|
2158
|
+
#### `Wordlist.check(wordlist: Wordlist): Wordlist`
|
|
2159
|
+
Validates a wordlist.
|
|
2160
|
+
- `wordlist`: Wordlist instance to validate
|
|
2161
|
+
- Returns: Validated wordlist
|
|
2162
|
+
|
|
2163
|
+
**Note**: The API matches ethers.js v6 Wordlist. For QuantumCoin, the `seed-words` library is used internally for all wordlist operations, including word lookup, validation, and phrase generation/parsing.
|
|
2164
|
+
|
|
2165
|
+
---
|
|
2166
|
+
|
|
2167
|
+
### 5.14 Number Utilities
|
|
2168
|
+
|
|
2169
|
+
#### `fromTwos(value: bigint, width: number): bigint`
|
|
2170
|
+
Converts from two's complement.
|
|
2171
|
+
- `value`: Value to convert
|
|
2172
|
+
- `width`: Bit width
|
|
2173
|
+
- Returns: Converted value
|
|
2174
|
+
|
|
2175
|
+
#### `toTwos(value: bigint, width: number): bigint`
|
|
2176
|
+
Converts to two's complement.
|
|
2177
|
+
- `value`: Value to convert
|
|
2178
|
+
- `width`: Bit width
|
|
2179
|
+
- Returns: Converted value
|
|
2180
|
+
|
|
2181
|
+
#### `mask(value: bigint, bits: number): bigint`
|
|
2182
|
+
Masks bits.
|
|
2183
|
+
- `value`: Value to mask
|
|
2184
|
+
- `bits`: Number of bits
|
|
2185
|
+
- Returns: Masked value
|
|
2186
|
+
|
|
2187
|
+
#### `getBigInt(value: any, name?: string): bigint`
|
|
2188
|
+
Gets bigint value.
|
|
2189
|
+
- `value`: Value to convert
|
|
2190
|
+
- `name`: Optional parameter name for error messages
|
|
2191
|
+
- Returns: Bigint value
|
|
2192
|
+
|
|
2193
|
+
#### `getUint(value: any, name?: string): number`
|
|
2194
|
+
Gets uint value.
|
|
2195
|
+
- `value`: Value to convert
|
|
2196
|
+
- `name`: Optional parameter name for error messages
|
|
2197
|
+
- Returns: Unsigned integer value
|
|
2198
|
+
|
|
2199
|
+
#### `getNumber(value: any, name?: string): number`
|
|
2200
|
+
Gets number value.
|
|
2201
|
+
- `value`: Value to convert
|
|
2202
|
+
- `name`: Optional parameter name for error messages
|
|
2203
|
+
- Returns: Number value
|
|
2204
|
+
|
|
2205
|
+
#### `toBigInt(value: any): bigint`
|
|
2206
|
+
Converts to bigint.
|
|
2207
|
+
- `value`: Value to convert
|
|
2208
|
+
- Returns: Bigint value
|
|
2209
|
+
|
|
2210
|
+
#### `toNumber(value: any): number`
|
|
2211
|
+
Converts to number.
|
|
2212
|
+
- `value`: Value to convert
|
|
2213
|
+
- Returns: Number value
|
|
2214
|
+
|
|
2215
|
+
#### `toBeHex(value: any, width?: number): string`
|
|
2216
|
+
Converts to hex with width.
|
|
2217
|
+
- `value`: Value to convert
|
|
2218
|
+
- `width`: Optional byte width
|
|
2219
|
+
- Returns: Hex string
|
|
2220
|
+
|
|
2221
|
+
#### `toBeArray(value: any, width?: number): Uint8Array`
|
|
2222
|
+
Converts to array with width.
|
|
2223
|
+
- `value`: Value to convert
|
|
2224
|
+
- `width`: Optional byte width
|
|
2225
|
+
- Returns: Byte array
|
|
2226
|
+
|
|
2227
|
+
#### `toQuantity(value: any): string`
|
|
2228
|
+
Converts to quantity format.
|
|
2229
|
+
- `value`: Value to convert
|
|
2230
|
+
- Returns: Quantity string
|
|
2231
|
+
|
|
2232
|
+
---
|
|
2233
|
+
|
|
2234
|
+
### 5.15 Bytes Utilities
|
|
2235
|
+
|
|
2236
|
+
#### `getBytes(value: any, name?: string): Uint8Array`
|
|
2237
|
+
Gets bytes.
|
|
2238
|
+
- `value`: Value to convert
|
|
2239
|
+
- `name`: Optional parameter name for error messages
|
|
2240
|
+
- Returns: Byte array
|
|
2241
|
+
|
|
2242
|
+
#### `getBytesCopy(value: any, name?: string): Uint8Array`
|
|
2243
|
+
Gets bytes copy.
|
|
2244
|
+
- `value`: Value to convert
|
|
2245
|
+
- `name`: Optional parameter name for error messages
|
|
2246
|
+
- Returns: Copy of byte array
|
|
2247
|
+
|
|
2248
|
+
#### `dataLength(data: BytesLike): number`
|
|
2249
|
+
Gets data length.
|
|
2250
|
+
- `data`: Data to measure
|
|
2251
|
+
- Returns: Length in bytes
|
|
2252
|
+
|
|
2253
|
+
#### `dataSlice(data: BytesLike, start: number, end?: number): string`
|
|
2254
|
+
Slices data.
|
|
2255
|
+
- `data`: Data to slice
|
|
2256
|
+
- `start`: Start position
|
|
2257
|
+
- `end`: Optional end position
|
|
2258
|
+
- Returns: Sliced hex string
|
|
2259
|
+
|
|
2260
|
+
#### `zeroPadBytes(data: BytesLike, length: number): string`
|
|
2261
|
+
Zero pads bytes.
|
|
2262
|
+
- `data`: Data to pad
|
|
2263
|
+
- `length`: Target length in bytes
|
|
2264
|
+
- Returns: Zero-padded hex string
|
|
2265
|
+
|
|
2266
|
+
---
|
|
2267
|
+
|
|
2268
|
+
### 5.16 Error Utilities
|
|
2269
|
+
|
|
2270
|
+
#### `isError(error: any, code?: string): boolean`
|
|
2271
|
+
Checks if error with code.
|
|
2272
|
+
- `error`: Error to check
|
|
2273
|
+
- `code`: Optional error code to match
|
|
2274
|
+
- Returns: true if error matches
|
|
2275
|
+
|
|
2276
|
+
#### `isCallException(error: any): boolean`
|
|
2277
|
+
Checks if call exception.
|
|
2278
|
+
- `error`: Error to check
|
|
2279
|
+
- Returns: true if call exception
|
|
2280
|
+
|
|
2281
|
+
#### `makeError(message: string, code: string, info?: any): Error`
|
|
2282
|
+
Makes error.
|
|
2283
|
+
- `message`: Error message
|
|
2284
|
+
- `code`: Error code
|
|
2285
|
+
- `info`: Optional error info
|
|
2286
|
+
- Returns: Error instance
|
|
2287
|
+
|
|
2288
|
+
---
|
|
2289
|
+
|
|
2290
|
+
### 5.17 Assertion Utilities
|
|
2291
|
+
|
|
2292
|
+
#### `assert(check: boolean, message: string, code: string, info?: any): void`
|
|
2293
|
+
Asserts condition.
|
|
2294
|
+
- `check`: Condition to check
|
|
2295
|
+
- `message`: Error message
|
|
2296
|
+
- `code`: Error code
|
|
2297
|
+
- `info`: Optional error info
|
|
2298
|
+
- Throws: Error if check fails
|
|
2299
|
+
|
|
2300
|
+
#### `assertArgument(check: boolean, message: string, name: string, value: any): void`
|
|
2301
|
+
Asserts argument.
|
|
2302
|
+
- `check`: Condition to check
|
|
2303
|
+
- `message`: Error message
|
|
2304
|
+
- `name`: Argument name
|
|
2305
|
+
- `value`: Argument value
|
|
2306
|
+
- Throws: Error if check fails
|
|
2307
|
+
|
|
2308
|
+
#### `assertArgumentCount(count: number, expectedCount: number, message: string): void`
|
|
2309
|
+
Asserts argument count.
|
|
2310
|
+
- `count`: Actual count
|
|
2311
|
+
- `expectedCount`: Expected count
|
|
2312
|
+
- `message`: Error message
|
|
2313
|
+
- Throws: Error if counts don't match
|
|
2314
|
+
|
|
2315
|
+
#### `assertNormalize(form: string): void`
|
|
2316
|
+
Asserts normalize form.
|
|
2317
|
+
- `form`: Form to check
|
|
2318
|
+
- Throws: Error if form invalid
|
|
2319
|
+
|
|
2320
|
+
#### `assertPrivate(givenGuard: any, guard: symbol, className: string): void`
|
|
2321
|
+
Asserts private access.
|
|
2322
|
+
- `givenGuard`: Given guard value
|
|
2323
|
+
- `guard`: Expected guard symbol
|
|
2324
|
+
- `className`: Class name
|
|
2325
|
+
- Throws: Error if guard doesn't match
|
|
2326
|
+
|
|
2327
|
+
---
|
|
2328
|
+
|
|
2329
|
+
### 5.18 Other Utilities
|
|
2330
|
+
|
|
2331
|
+
#### `resolveProperties(value: Record<string, any>): Promise<Record<string, any>>`
|
|
2332
|
+
Resolves properties.
|
|
2333
|
+
- `value`: Object with potentially async values
|
|
2334
|
+
- Returns: Promise resolving to object with all values resolved
|
|
2335
|
+
|
|
2336
|
+
#### `defineProperties(target: any, values: Record<string, any>, types?: Record<string, string>): void`
|
|
2337
|
+
Defines properties.
|
|
2338
|
+
- `target`: Target object
|
|
2339
|
+
- `values`: Property values
|
|
2340
|
+
- `types`: Optional property types
|
|
2341
|
+
|
|
2342
|
+
#### `lock(value: any): any`
|
|
2343
|
+
Locks value.
|
|
2344
|
+
- `value`: Value to lock
|
|
2345
|
+
- Returns: Locked value
|
|
2346
|
+
|
|
2347
|
+
#### `uuidV4(randomBytes: (length: number) => Uint8Array): string`
|
|
2348
|
+
Generates UUID v4.
|
|
2349
|
+
- `randomBytes`: Random bytes function
|
|
2350
|
+
- Returns: UUID v4 string
|
|
2351
|
+
|
|
2352
|
+
---
|
|
2353
|
+
|
|
2354
|
+
### 5.19 Utility Classes (Not Implemented)
|
|
2355
|
+
|
|
2356
|
+
The following utility classes are exported from ethers.js but not implemented in quantumcoin.js. They are listed here for API compatibility reference:
|
|
2357
|
+
|
|
2358
|
+
#### `FixedNumber`
|
|
2359
|
+
|
|
2360
|
+
**Purpose**: Represents fixed-point decimal numbers
|
|
2361
|
+
|
|
2362
|
+
**Note**: This class is exported from ethers.js but not implemented in quantumcoin.js. Use `bigint` and `formatUnits`/`parseUnits` for decimal handling in quantumcoin.js.
|
|
2363
|
+
|
|
2364
|
+
---
|
|
2365
|
+
|
|
2366
|
+
#### `FetchRequest`
|
|
2367
|
+
|
|
2368
|
+
**Purpose**: Represents an HTTP fetch request
|
|
2369
|
+
|
|
2370
|
+
**Note**: This class is exported from ethers.js but not implemented in quantumcoin.js. It is listed here for API compatibility reference.
|
|
2371
|
+
|
|
2372
|
+
---
|
|
2373
|
+
|
|
2374
|
+
#### `FetchResponse`
|
|
2375
|
+
|
|
2376
|
+
**Purpose**: Represents an HTTP fetch response
|
|
2377
|
+
|
|
2378
|
+
**Note**: This class is exported from ethers.js but not implemented in quantumcoin.js. It is listed here for API compatibility reference.
|
|
2379
|
+
|
|
2380
|
+
---
|
|
2381
|
+
|
|
2382
|
+
#### `FetchCancelSignal`
|
|
2383
|
+
|
|
2384
|
+
**Purpose**: Represents a cancellation signal for fetch requests
|
|
2385
|
+
|
|
2386
|
+
**Note**: This class is exported from ethers.js but not implemented in quantumcoin.js. It is listed here for API compatibility reference.
|
|
2387
|
+
|
|
2388
|
+
---
|
|
2389
|
+
|
|
2390
|
+
**Static Methods**:
|
|
2391
|
+
|
|
2392
|
+
#### `Mnemonic.fromEntropy(entropy: BytesLike, password?: null | string, wordlist?: null | Wordlist): Mnemonic`
|
|
2393
|
+
Create a new Mnemonic from the entropy.
|
|
2394
|
+
- `entropy`: Entropy bytes
|
|
2395
|
+
- `password`: Optional password (default: empty string)
|
|
2396
|
+
- `wordlist`: Optional wordlist (default: QuantumCoin wordlist)
|
|
2397
|
+
- Returns: Mnemonic instance
|
|
2398
|
+
- **Note**: For QuantumCoin, the entropy should generate 48-word phrases
|
|
2399
|
+
|
|
2400
|
+
#### `Mnemonic.fromPhrase(phrase: string, password?: null | string, wordlist?: null | Wordlist): Mnemonic`
|
|
2401
|
+
Creates a new Mnemonic for the phrase.
|
|
2402
|
+
- `phrase`: Mnemonic phrase string (48 words for QuantumCoin)
|
|
2403
|
+
- `password`: Optional password (default: empty string)
|
|
2404
|
+
- `wordlist`: Optional wordlist (default: QuantumCoin wordlist)
|
|
2405
|
+
- Returns: Mnemonic instance
|
|
2406
|
+
|
|
2407
|
+
#### `Mnemonic.entropyToPhrase(entropy: BytesLike, wordlist?: null | Wordlist): string`
|
|
2408
|
+
Returns the phrase for the entropy.
|
|
2409
|
+
- `entropy`: Entropy bytes
|
|
2410
|
+
- `wordlist`: Optional wordlist (default: QuantumCoin wordlist)
|
|
2411
|
+
- Returns: Mnemonic phrase string
|
|
2412
|
+
|
|
2413
|
+
#### `Mnemonic.isValidMnemonic(phrase: string, wordlist?: null | Wordlist): boolean`
|
|
2414
|
+
Returns true if phrase is a valid mnemonic phrase.
|
|
2415
|
+
- `phrase`: Phrase to validate
|
|
2416
|
+
- `wordlist`: Optional wordlist (default: QuantumCoin wordlist)
|
|
2417
|
+
- Returns: `true` if valid mnemonic, `false` otherwise
|
|
2418
|
+
- **Note**: Checks that all words belong to the wordlist, length is valid, and checksum is correct. For QuantumCoin, validates 48-word phrases.
|
|
2419
|
+
|
|
2420
|
+
#### `Mnemonic.phraseToEntropy(phrase: string, wordlist?: null | Wordlist): string`
|
|
2421
|
+
Returns the entropy for the phrase.
|
|
2422
|
+
- `phrase`: Mnemonic phrase string
|
|
2423
|
+
- `wordlist`: Optional wordlist (default: QuantumCoin wordlist)
|
|
2424
|
+
- Returns: Entropy as hex string
|
|
2425
|
+
|
|
2426
|
+
**Methods**:
|
|
2427
|
+
|
|
2428
|
+
#### `computeSeed(): string`
|
|
2429
|
+
Returns the seed for the mnemonic.
|
|
2430
|
+
- Returns: Seed as hex string
|
|
2431
|
+
- **Note**: Computes the seed from the mnemonic and password. For QuantumCoin, uses quantum-coin-js-sdk's seed computation.
|
|
2432
|
+
|
|
2433
|
+
---
|
|
2434
|
+
|
|
2435
|
+
## 6. Network and Plugins
|
|
2436
|
+
|
|
2437
|
+
### 6.1 Network
|
|
2438
|
+
|
|
2439
|
+
**Purpose**: Encapsulates chain properties and allows plugin extensions
|
|
2440
|
+
|
|
2441
|
+
**Note**: The API matches ethers.js v6 Network. All methods, properties, and behavior follow the same patterns as ethers.js v6.
|
|
2442
|
+
|
|
2443
|
+
**Constructor**:
|
|
2444
|
+
```javascript
|
|
2445
|
+
constructor(name: string, chainId: BigNumberish)
|
|
2446
|
+
```
|
|
2447
|
+
- `name`: Network name
|
|
2448
|
+
- `chainId`: Chain ID
|
|
2449
|
+
|
|
2450
|
+
**Properties**:
|
|
2451
|
+
- `name`: string - Network common name
|
|
2452
|
+
- `chainId`: bigint - Network chain ID
|
|
2453
|
+
- `plugins`: NetworkPlugin[] - Array of attached plugins (read-only)
|
|
2454
|
+
|
|
2455
|
+
**Static Methods**:
|
|
2456
|
+
|
|
2457
|
+
#### `Network.from(network?: Networkish): Network`
|
|
2458
|
+
Returns a new Network for the network name or chainId.
|
|
2459
|
+
- `network`: Network name, chainId, or Network object
|
|
2460
|
+
- Returns: Network instance
|
|
2461
|
+
|
|
2462
|
+
#### `Network.register(nameOrChainId: string | number | bigint, networkFunc: () => Network): void`
|
|
2463
|
+
Registers a network name or chainId with a function that returns a Network instance.
|
|
2464
|
+
- `nameOrChainId`: Network name or chain ID to register
|
|
2465
|
+
- `networkFunc`: Function that returns a Network instance
|
|
2466
|
+
|
|
2467
|
+
**Methods**:
|
|
2468
|
+
|
|
2469
|
+
#### `attachPlugin(plugin: NetworkPlugin): this`
|
|
2470
|
+
Attach a new plugin to this Network.
|
|
2471
|
+
- `plugin`: NetworkPlugin instance
|
|
2472
|
+
- Returns: this
|
|
2473
|
+
|
|
2474
|
+
#### `clone(): Network`
|
|
2475
|
+
Create a copy of this Network.
|
|
2476
|
+
- Returns: New Network instance
|
|
2477
|
+
|
|
2478
|
+
#### `computeIntrinsicGas(tx: TransactionLike): number`
|
|
2479
|
+
Compute the intrinsic gas required for a transaction.
|
|
2480
|
+
- `tx`: Transaction-like object
|
|
2481
|
+
- Returns: Intrinsic gas amount
|
|
2482
|
+
- **Note**: A GasCostPlugin can be attached to override default values
|
|
2483
|
+
|
|
2484
|
+
#### `getPlugin<T extends NetworkPlugin>(name: string): null | T`
|
|
2485
|
+
Return the plugin matching name exactly.
|
|
2486
|
+
- `name`: Plugin name
|
|
2487
|
+
- Returns: Plugin instance or null
|
|
2488
|
+
|
|
2489
|
+
#### `getPlugins<T extends NetworkPlugin>(basename: string): T[]`
|
|
2490
|
+
Gets all plugins that match basename (with or without fragment).
|
|
2491
|
+
- `basename`: Plugin base name
|
|
2492
|
+
- Returns: Array of matching plugins
|
|
2493
|
+
|
|
2494
|
+
#### `matches(other: Networkish): boolean`
|
|
2495
|
+
Returns true if other matches this network.
|
|
2496
|
+
- `other`: Network name, chainId, or Network object
|
|
2497
|
+
- Returns: true if chain IDs match (or names match if no chain ID)
|
|
2498
|
+
|
|
2499
|
+
#### `toJSON(): any`
|
|
2500
|
+
Returns a JSON-compatible representation of the Network.
|
|
2501
|
+
|
|
2502
|
+
---
|
|
2503
|
+
|
|
2504
|
+
### 6.2 Networkish
|
|
2505
|
+
|
|
2506
|
+
**Type**: `Network | number | bigint | string | { chainId?: number, name?: string }`
|
|
2507
|
+
|
|
2508
|
+
**Purpose**: Anything that can be used to identify or create a Network.
|
|
2509
|
+
|
|
2510
|
+
---
|
|
2511
|
+
|
|
2512
|
+
### 6.3 NetworkPlugin (Base Interface)
|
|
2513
|
+
|
|
2514
|
+
**Purpose**: Base interface for network plugins
|
|
2515
|
+
|
|
2516
|
+
**Properties**:
|
|
2517
|
+
- `name`: string - Plugin name (must be unique per network)
|
|
2518
|
+
|
|
2519
|
+
**Note**: All network plugins must implement this interface. Plugins can extend network functionality (gas costs, fee data, etc.).
|
|
2520
|
+
|
|
2521
|
+
---
|
|
2522
|
+
|
|
2523
|
+
### 6.4 GasCostPlugin
|
|
2524
|
+
|
|
2525
|
+
**Extends**: NetworkPlugin
|
|
2526
|
+
|
|
2527
|
+
**Purpose**: Plugin for computing gas costs
|
|
2528
|
+
|
|
2529
|
+
**Properties**:
|
|
2530
|
+
- `name`: "org.ethers.plugins.network.GasCost" - Plugin name
|
|
2531
|
+
- `txAccessListAddress`: number - Gas cost for access list address
|
|
2532
|
+
- `txAccessListStorageKey`: number - Gas cost for access list storage key
|
|
2533
|
+
- `txBase`: number - Base transaction gas cost
|
|
2534
|
+
- `txCreate`: number - Gas cost for contract creation
|
|
2535
|
+
- `txDataNonzero`: number - Gas cost per non-zero data byte
|
|
2536
|
+
- `txDataZero`: number - Gas cost per zero data byte
|
|
2537
|
+
|
|
2538
|
+
**Methods**:
|
|
2539
|
+
|
|
2540
|
+
#### `computeIntrinsicGas(tx: TransactionLike): number`
|
|
2541
|
+
Compute the intrinsic gas required for a transaction using plugin parameters.
|
|
2542
|
+
- `tx`: Transaction-like object
|
|
2543
|
+
- Returns: Intrinsic gas amount
|
|
2544
|
+
|
|
2545
|
+
---
|
|
2546
|
+
|
|
2547
|
+
## 7. Error Classes
|
|
2548
|
+
|
|
2549
|
+
### 7.1 Error
|
|
2550
|
+
|
|
2551
|
+
**Base error class**
|
|
2552
|
+
|
|
2553
|
+
**Properties**:
|
|
2554
|
+
- `message`: string - Error message
|
|
2555
|
+
- `code`: string - Error code
|
|
2556
|
+
- `data`: any - Error data
|
|
2557
|
+
|
|
2558
|
+
---
|
|
2559
|
+
|
|
2560
|
+
### 7.2 ProviderError
|
|
2561
|
+
|
|
2562
|
+
**Extends**: Error
|
|
2563
|
+
|
|
2564
|
+
**Additional Properties**:
|
|
2565
|
+
- `statusCode`: number - HTTP status code
|
|
2566
|
+
- `request`: any - Request object
|
|
2567
|
+
- `response`: any - Response object
|
|
2568
|
+
|
|
2569
|
+
---
|
|
2570
|
+
|
|
2571
|
+
### 7.3 TransactionError
|
|
2572
|
+
|
|
2573
|
+
**Extends**: Error
|
|
2574
|
+
|
|
2575
|
+
**Additional Properties**:
|
|
2576
|
+
- `transaction`: TransactionRequest - Transaction that failed
|
|
2577
|
+
- `receipt`: TransactionReceipt | null - Transaction receipt (if available)
|
|
2578
|
+
|
|
2579
|
+
---
|
|
2580
|
+
|
|
2581
|
+
### 7.4 ContractError
|
|
2582
|
+
|
|
2583
|
+
**Extends**: Error
|
|
2584
|
+
|
|
2585
|
+
**Additional Properties**:
|
|
2586
|
+
- `contractAddress`: string - Contract address
|
|
2587
|
+
- `method`: string - Method name
|
|
2588
|
+
- `args`: any[] - Method arguments
|
|
2589
|
+
|
|
2590
|
+
---
|
|
2591
|
+
|
|
2592
|
+
## 8. Provider Types and Interfaces
|
|
2593
|
+
|
|
2594
|
+
### 8.1 PreparedTransactionRequest
|
|
2595
|
+
|
|
2596
|
+
**Purpose**: Transaction request with all properties coerced to strict types
|
|
2597
|
+
|
|
2598
|
+
**Properties**:
|
|
2599
|
+
- `to`: string | null - Recipient address
|
|
2600
|
+
- `from`: string - Sender address
|
|
2601
|
+
- `value`: bigint - Value in wei
|
|
2602
|
+
- `data`: string - Transaction data (hex string)
|
|
2603
|
+
- `gasLimit`: bigint - Gas limit
|
|
2604
|
+
- `gasPrice`: bigint | null - Gas price
|
|
2605
|
+
- `nonce`: number - Transaction nonce
|
|
2606
|
+
- `chainId`: number - Chain ID
|
|
2607
|
+
- `remarks`: string | null - Optional remarks field
|
|
2608
|
+
|
|
2609
|
+
**Note**: Created by `copyRequest(req: TransactionRequest): PreparedTransactionRequest` to normalize a transaction request.
|
|
2610
|
+
|
|
2611
|
+
---
|
|
2612
|
+
|
|
2613
|
+
### 8.2 MinedBlock
|
|
2614
|
+
|
|
2615
|
+
**Purpose**: Block that has been mined (extends Block)
|
|
2616
|
+
|
|
2617
|
+
**Extends**: Block
|
|
2618
|
+
|
|
2619
|
+
**Additional Properties**:
|
|
2620
|
+
- All Block properties are guaranteed to be non-null (hash, number, etc.)
|
|
2621
|
+
|
|
2622
|
+
**Note**: Type guard for blocks that have been mined. Pending blocks do not satisfy this type.
|
|
2623
|
+
|
|
2624
|
+
---
|
|
2625
|
+
|
|
2626
|
+
### 8.3 MinedTransactionResponse
|
|
2627
|
+
|
|
2628
|
+
**Purpose**: Transaction response that has been mined
|
|
2629
|
+
|
|
2630
|
+
**Extends**: TransactionResponse
|
|
2631
|
+
|
|
2632
|
+
**Additional Properties**:
|
|
2633
|
+
- `blockNumber`: number - Block number (guaranteed non-null)
|
|
2634
|
+
- `blockHash`: string - Block hash (guaranteed non-null)
|
|
2635
|
+
|
|
2636
|
+
**Methods**:
|
|
2637
|
+
|
|
2638
|
+
#### `isMined(): boolean`
|
|
2639
|
+
Returns true if this transaction has been mined.
|
|
2640
|
+
- Returns: true (always true for MinedTransactionResponse)
|
|
2641
|
+
|
|
2642
|
+
#### `getBlock(): Promise<Block>`
|
|
2643
|
+
Resolves to the Block that this transaction was included in.
|
|
2644
|
+
- Returns: Block instance
|
|
2645
|
+
|
|
2646
|
+
#### `confirmations(): Promise<number>`
|
|
2647
|
+
Resolves to the number of confirmations this transaction has.
|
|
2648
|
+
- Returns: Number of confirmations
|
|
2649
|
+
|
|
2650
|
+
**Note**: Type guard for transactions that have been included in a block.
|
|
2651
|
+
|
|
2652
|
+
---
|
|
2653
|
+
|
|
2654
|
+
### 8.4 FeeData
|
|
2655
|
+
|
|
2656
|
+
**Purpose**: Represents fee data for transactions
|
|
2657
|
+
|
|
2658
|
+
**Constructor**:
|
|
2659
|
+
```javascript
|
|
2660
|
+
constructor(gasPrice: bigint | null)
|
|
2661
|
+
```
|
|
2662
|
+
- `gasPrice`: Legacy gas price
|
|
2663
|
+
|
|
2664
|
+
**Properties**:
|
|
2665
|
+
- `gasPrice`: bigint | null - Gas price
|
|
2666
|
+
|
|
2667
|
+
**Methods**:
|
|
2668
|
+
|
|
2669
|
+
#### `toJSON(): any`
|
|
2670
|
+
Converts to JSON.
|
|
2671
|
+
- Returns: JSON representation of FeeData
|
|
2672
|
+
|
|
2673
|
+
**Note**: For QuantumCoin, only `gasPrice` is used (EIP-1559 style transactions are not applicable).
|
|
2674
|
+
|
|
2675
|
+
---
|
|
2676
|
+
|
|
2677
|
+
### 8.5 WebSocketLike
|
|
2678
|
+
|
|
2679
|
+
**Purpose**: Interface for WebSocket-like objects
|
|
2680
|
+
|
|
2681
|
+
**Properties**:
|
|
2682
|
+
- `readyState`: number - Connection state (0 = CONNECTING, 1 = OPEN, 2 = CLOSING, 3 = CLOSED)
|
|
2683
|
+
- `onopen`: ((event: any) => void) | null - Open event handler
|
|
2684
|
+
- `onmessage`: ((event: any) => void) | null - Message event handler
|
|
2685
|
+
- `onerror`: ((event: any) => void) | null - Error event handler
|
|
2686
|
+
|
|
2687
|
+
**Methods**:
|
|
2688
|
+
|
|
2689
|
+
#### `send(payload: any): void`
|
|
2690
|
+
Sends data through the WebSocket.
|
|
2691
|
+
- `payload`: Data to send
|
|
2692
|
+
|
|
2693
|
+
#### `close(code?: number, reason?: string): void`
|
|
2694
|
+
Closes the WebSocket connection.
|
|
2695
|
+
- `code`: Optional close code
|
|
2696
|
+
- `reason`: Optional close reason
|
|
2697
|
+
|
|
2698
|
+
**Note**: Generic interface for WebSocket compatibility, allowing different WebSocket implementations to be used.
|
|
2699
|
+
|
|
2700
|
+
---
|
|
2701
|
+
|
|
2702
|
+
### 8.6 ProviderEvent
|
|
2703
|
+
|
|
2704
|
+
**Type**: `string | Array<string | Array<string>> | EventFilter | FilterByBlockHash`
|
|
2705
|
+
|
|
2706
|
+
**Purpose**: Type for provider events that can be subscribed to
|
|
2707
|
+
|
|
2708
|
+
**Values**:
|
|
2709
|
+
- `"block"` - Emitted on each new block with block number
|
|
2710
|
+
- `"error"` - Emitted on async errors
|
|
2711
|
+
- `"debug"` - Emitted on debug events
|
|
2712
|
+
- Transaction hash (string) - Emitted when transaction is mined
|
|
2713
|
+
- Array of topics - Emitted on matching logs
|
|
2714
|
+
- EventFilter - Emitted on matching logs
|
|
2715
|
+
- FilterByBlockHash - Emitted on matching logs in specific block
|
|
2716
|
+
|
|
2717
|
+
**Note**: Each provider may support additional event types.
|
|
2718
|
+
|
|
2719
|
+
---
|
|
2720
|
+
|
|
2721
|
+
### 8.7 TopicFilter
|
|
2722
|
+
|
|
2723
|
+
**Type**: `Array<null | string | Array<string>>`
|
|
2724
|
+
|
|
2725
|
+
**Purpose**: Structure for bloom-filter queries on event topics
|
|
2726
|
+
|
|
2727
|
+
**Description**:
|
|
2728
|
+
- Each field can be:
|
|
2729
|
+
- `null` - Matches any value
|
|
2730
|
+
- `string` - Must match exactly that value
|
|
2731
|
+
- `Array<string>` - OR match (any one of those values must match)
|
|
2732
|
+
|
|
2733
|
+
**Example**:
|
|
2734
|
+
```javascript
|
|
2735
|
+
// Match any event from address 0x... with topic[0] = "0x123..." and any topic[1]
|
|
2736
|
+
["0x123...", null]
|
|
2737
|
+
|
|
2738
|
+
// Match events with topic[0] = "0x123..." OR "0x456..."
|
|
2739
|
+
[["0x123...", "0x456..."], null]
|
|
2740
|
+
```
|
|
2741
|
+
|
|
2742
|
+
---
|
|
2743
|
+
|
|
2744
|
+
## 9. Provider Interface
|
|
2745
|
+
|
|
2746
|
+
### 9.1 Provider (Abstract Base Class)
|
|
2747
|
+
|
|
2748
|
+
**Properties**:
|
|
2749
|
+
- `chainId`: Promise<number> - Chain ID
|
|
2750
|
+
|
|
2751
|
+
**Methods**:
|
|
2752
|
+
|
|
2753
|
+
#### `getBlockNumber(): Promise<number>`
|
|
2754
|
+
Returns latest block number.
|
|
2755
|
+
|
|
2756
|
+
#### `getBlock(blockNumber: number | string): Promise<Block>`
|
|
2757
|
+
Returns block information.
|
|
2758
|
+
|
|
2759
|
+
#### `getTransaction(txHash: string): Promise<TransactionResponse>`
|
|
2760
|
+
Returns transaction.
|
|
2761
|
+
|
|
2762
|
+
#### `getTransactionReceipt(txHash: string): Promise<TransactionReceipt>`
|
|
2763
|
+
Returns transaction receipt.
|
|
2764
|
+
|
|
2765
|
+
#### `getBalance(address: string, blockTag?: string): Promise<bigint>`
|
|
2766
|
+
Returns balance.
|
|
2767
|
+
|
|
2768
|
+
#### `getTransactionCount(address: string, blockTag?: string): Promise<number>`
|
|
2769
|
+
Returns nonce.
|
|
2770
|
+
|
|
2771
|
+
#### `sendTransaction(tx: string | TransactionRequest): Promise<TransactionResponse>`
|
|
2772
|
+
Sends transaction.
|
|
2773
|
+
- Note: If `tx` is a TransactionRequest, the `remarks` field is optional and can be used to include a comment (max 32 bytes). Do not store sensitive information in remarks.
|
|
2774
|
+
|
|
2775
|
+
#### `call(tx: TransactionRequest, blockTag?: string): Promise<string>`
|
|
2776
|
+
Executes call.
|
|
2777
|
+
|
|
2778
|
+
#### `estimateGas(tx: TransactionRequest): Promise<bigint>`
|
|
2779
|
+
Estimates gas.
|
|
2780
|
+
|
|
2781
|
+
#### `getCode(address: string, blockTag?: string): Promise<string>`
|
|
2782
|
+
Returns contract code.
|
|
2783
|
+
|
|
2784
|
+
#### `getStorageAt(address: string, position: bigint, blockTag?: string): Promise<string>`
|
|
2785
|
+
Returns storage value.
|
|
2786
|
+
|
|
2787
|
+
#### `getLogs(filter: Filter): Promise<Log[]>`
|
|
2788
|
+
Returns logs.
|
|
2789
|
+
|
|
2790
|
+
#### `on(event: string, callback: Function): void`
|
|
2791
|
+
Subscribes to events.
|
|
2792
|
+
|
|
2793
|
+
#### `once(event: string, callback: Function): void`
|
|
2794
|
+
Subscribes to event once.
|
|
2795
|
+
|
|
2796
|
+
#### `removeListener(event: string, callback: Function): void`
|
|
2797
|
+
Removes listener.
|
|
2798
|
+
|
|
2799
|
+
#### `removeAllListeners(event?: string): void`
|
|
2800
|
+
Removes all listeners.
|
|
2801
|
+
|
|
2802
|
+
---
|
|
2803
|
+
|
|
2804
|
+
## 9. Provider Interface
|
|
2805
|
+
|
|
2806
|
+
### 9.1 Provider (Abstract Base Class)
|
|
2807
|
+
|
|
2808
|
+
**Purpose**: Abstract base class for blockchain providers
|
|
2809
|
+
|
|
2810
|
+
**Note**: The API matches ethers.js v6 Provider. All methods, properties, and behavior follow the same patterns as ethers.js v6.
|
|
2811
|
+
|
|
2812
|
+
**Properties**:
|
|
2813
|
+
- `chainId`: Promise<number> - Chain ID
|
|
2814
|
+
- `network: Network` - Network instance (read-only)
|
|
2815
|
+
- `ready: Promise<Network>` - Promise that resolves when provider is ready
|
|
2816
|
+
|
|
2817
|
+
**Methods**:
|
|
2818
|
+
|
|
2819
|
+
#### `getBlockNumber(): Promise<number>`
|
|
2820
|
+
Returns latest block number.
|
|
2821
|
+
|
|
2822
|
+
#### `getBlock(blockTag: string | number): Promise<Block | null>`
|
|
2823
|
+
Returns block information.
|
|
2824
|
+
|
|
2825
|
+
#### `getTransaction(txHash: string): Promise<TransactionResponse | null>`
|
|
2826
|
+
Returns transaction.
|
|
2827
|
+
|
|
2828
|
+
#### `getTransactionReceipt(txHash: string): Promise<TransactionReceipt | null>`
|
|
2829
|
+
Returns transaction receipt.
|
|
2830
|
+
|
|
2831
|
+
#### `getBalance(address: string, blockTag?: string): Promise<bigint>`
|
|
2832
|
+
Returns balance.
|
|
2833
|
+
|
|
2834
|
+
#### `getTransactionCount(address: string, blockTag?: string): Promise<number>`
|
|
2835
|
+
Returns nonce.
|
|
2836
|
+
|
|
2837
|
+
#### `call(tx: TransactionRequest, blockTag?: string): Promise<string>`
|
|
2838
|
+
Executes a call without creating a transaction.
|
|
2839
|
+
- `tx`: Transaction request
|
|
2840
|
+
- `blockTag`: Optional block tag
|
|
2841
|
+
- Returns: Result data as hex string
|
|
2842
|
+
|
|
2843
|
+
#### `estimateGas(tx: TransactionRequest): Promise<bigint>`
|
|
2844
|
+
Estimates gas for a transaction.
|
|
2845
|
+
- `tx`: Transaction request
|
|
2846
|
+
- Returns: Estimated gas amount
|
|
2847
|
+
|
|
2848
|
+
#### `getTransactionResult(txHash: string): Promise<null | string>`
|
|
2849
|
+
Gets the result of a transaction execution.
|
|
2850
|
+
- `txHash`: Transaction hash
|
|
2851
|
+
- Returns: Result data or null if transaction failed
|
|
2852
|
+
|
|
2853
|
+
#### `getNetwork(): Promise<Network>`
|
|
2854
|
+
Gets network information.
|
|
2855
|
+
- Returns: Network instance
|
|
2856
|
+
|
|
2857
|
+
#### `getFeeData(): Promise<FeeData>`
|
|
2858
|
+
Gets fee data (gas prices).
|
|
2859
|
+
- Returns: FeeData instance
|
|
2860
|
+
|
|
2861
|
+
#### `broadcastTransaction(signedTx: string): Promise<TransactionResponse>`
|
|
2862
|
+
Broadcasts a signed transaction.
|
|
2863
|
+
- `signedTx`: Signed transaction hex string
|
|
2864
|
+
- Returns: TransactionResponse
|
|
2865
|
+
|
|
2866
|
+
#### `waitForTransaction(txHash: string, confirms?: number, timeout?: number): Promise<TransactionReceipt>`
|
|
2867
|
+
Waits for transaction confirmation.
|
|
2868
|
+
- `txHash`: Transaction hash
|
|
2869
|
+
- `confirms`: Optional number of confirmations to wait for
|
|
2870
|
+
- `timeout`: Optional timeout in milliseconds
|
|
2871
|
+
- Returns: TransactionReceipt
|
|
2872
|
+
|
|
2873
|
+
**Note**: Both Provider and Signer implement this interface, allowing them to be used interchangeably for contract calls and gas estimation.
|
|
2874
|
+
|
|
2875
|
+
---
|
|
2876
|
+
|
|
2877
|
+
### 9.2 ContractRunner (Abstract Base Class/Interface)
|
|
2878
|
+
|
|
2879
|
+
**Purpose**: Interface for contract execution (implemented by Provider and Signer)
|
|
2880
|
+
|
|
2881
|
+
**Note**: The API matches ethers.js v6 ContractRunner. All methods, properties, and behavior follow the same patterns as ethers.js v6.
|
|
2882
|
+
|
|
2883
|
+
**Properties**:
|
|
2884
|
+
- `provider`: Provider | null - Provider instance
|
|
2885
|
+
|
|
2886
|
+
**Methods**:
|
|
2887
|
+
|
|
2888
|
+
#### `call(tx: TransactionRequest, blockTag?: string): Promise<string>`
|
|
2889
|
+
Executes a call without creating a transaction.
|
|
2890
|
+
- `tx`: Transaction request
|
|
2891
|
+
- `blockTag`: Optional block tag
|
|
2892
|
+
- Returns: Result data as hex string
|
|
2893
|
+
|
|
2894
|
+
#### `estimateGas(tx: TransactionRequest): Promise<bigint>`
|
|
2895
|
+
Estimates gas for a transaction.
|
|
2896
|
+
- `tx`: Transaction request
|
|
2897
|
+
- Returns: Estimated gas amount
|
|
2898
|
+
|
|
2899
|
+
#### `getTransactionResult(txHash: string): Promise<null | string>`
|
|
2900
|
+
Gets the result of a transaction execution.
|
|
2901
|
+
- `txHash`: Transaction hash
|
|
2902
|
+
- Returns: Result data or null if transaction failed
|
|
2903
|
+
|
|
2904
|
+
**Note**: Both Provider and Signer implement this interface, allowing them to be used interchangeably for contract calls and gas estimation.
|
|
2905
|
+
|
|
2906
|
+
---
|
|
2907
|
+
|
|
2908
|
+
### 9.3 Signer (Abstract Base Class)
|
|
2909
|
+
|
|
2910
|
+
**Note**: The API matches ethers.js v6 Signer. All methods, properties, and behavior follow the same patterns as ethers.js v6, except `signMessage()` is replaced with `signMessageSync()` for synchronous operation.
|
|
2911
|
+
|
|
2912
|
+
**Properties**:
|
|
2913
|
+
- `provider`: Provider | null - Provider instance
|
|
2914
|
+
- `address: string` - Signer address (read-only)
|
|
2915
|
+
|
|
2916
|
+
**Methods**:
|
|
2917
|
+
|
|
2918
|
+
#### `getAddress(): Promise<string>`
|
|
2919
|
+
Returns signer address.
|
|
2920
|
+
|
|
2921
|
+
#### `getBalance(blockTag?: string): Promise<bigint>`
|
|
2922
|
+
Returns balance.
|
|
2923
|
+
|
|
2924
|
+
#### `getTransactionCount(blockTag?: string): Promise<number>`
|
|
2925
|
+
Returns nonce.
|
|
2926
|
+
|
|
2927
|
+
#### `sendTransaction(tx: TransactionRequest): Promise<TransactionResponse>`
|
|
2928
|
+
Signs and sends transaction.
|
|
2929
|
+
- Note: The `remarks` field in TransactionRequest is optional and can be used to include a comment (max 32 bytes). Do not store sensitive information in remarks.
|
|
2930
|
+
|
|
2931
|
+
#### `signTransaction(tx: TransactionRequest): Promise<string>`
|
|
2932
|
+
Signs transaction.
|
|
2933
|
+
- Note: The `remarks` field in TransactionRequest is optional and can be used to include a comment (max 32 bytes). Do not store sensitive information in remarks.
|
|
2934
|
+
|
|
2935
|
+
#### `signMessageSync(message: string | Uint8Array): string`
|
|
2936
|
+
Signs message (synchronous).
|
|
2937
|
+
- `message`: Message to sign (string or bytes)
|
|
2938
|
+
- Returns: Signature string
|
|
2939
|
+
|
|
2940
|
+
#### `connect(provider: Provider): Signer`
|
|
2941
|
+
Connects to provider.
|
|
2942
|
+
|
|
2943
|
+
#### `populateTransaction(tx: TransactionRequest): Promise<TransactionRequest>`
|
|
2944
|
+
Populates transaction with defaults.
|
|
2945
|
+
- `tx`: Transaction request
|
|
2946
|
+
- Returns: Populated transaction request
|
|
2947
|
+
|
|
2948
|
+
#### `populateCall(tx: TransactionRequest): Promise<TransactionRequest>`
|
|
2949
|
+
Populates call transaction.
|
|
2950
|
+
- `tx`: Transaction request
|
|
2951
|
+
- Returns: Populated call transaction request
|
|
2952
|
+
|
|
2953
|
+
#### `call(tx: TransactionRequest, blockTag?: BlockTag): Promise<string>`
|
|
2954
|
+
Executes a call without creating a transaction.
|
|
2955
|
+
- `tx`: Transaction request
|
|
2956
|
+
- `blockTag`: Optional block tag
|
|
2957
|
+
- Returns: Result data as hex string
|
|
2958
|
+
|
|
2959
|
+
#### `estimateGas(tx: TransactionRequest): Promise<bigint>`
|
|
2960
|
+
Estimates gas for a transaction.
|
|
2961
|
+
- `tx`: Transaction request
|
|
2962
|
+
- Returns: Estimated gas amount
|
|
2963
|
+
|
|
2964
|
+
---
|
|
2965
|
+
|
|
2966
|
+
## 10. Implementation Requirements
|
|
2967
|
+
|
|
2968
|
+
### 10.1 Quantum-Coin-JS-SDK Integration
|
|
2969
|
+
|
|
2970
|
+
All implementations must use quantum-coin-js-sdk for:
|
|
2971
|
+
|
|
2972
|
+
1. **Address Validation**: Use `isAddressValid()` from quantum-coin-js-sdk
|
|
2973
|
+
2. **ABI Encoding/Decoding**: Use `packMethodData()` and `unpackMethodData()` from quantum-coin-js-sdk
|
|
2974
|
+
3. **Event Log Encoding/Decoding**: Use `encodeEventLog()` and `decodeEventLog()` from quantum-coin-js-sdk
|
|
2975
|
+
4. **Transaction Signing**: Use `signRawTransaction()` from quantum-coin-js-sdk (supports `remarks` field via TransactionSigningRequest)
|
|
2976
|
+
5. **Contract Address Calculation**: Use `createAddress()` and `createAddress2()` from quantum-coin-js-sdk
|
|
2977
|
+
6. **Wallet Operations**: Use Wallet class from quantum-coin-js-sdk for private key management
|
|
2978
|
+
7. **Wallet Address Derivation**: Use `publicKeyFromPrivateKey()` and `addressFromPublicKey()` from quantum-coin-js-sdk to derive the public key and address from the private key in the Wallet constructor
|
|
2979
|
+
8. **Random Wallet Creation**: Use `newWallet()` from quantum-coin-js-sdk in `Wallet.createRandom()` static method
|
|
2980
|
+
9. **Encrypted Wallet Deserialization**: Use `deserializeEncryptedWallet()` from quantum-coin-js-sdk in `Wallet.fromEncryptedJsonSync()` static method
|
|
2981
|
+
10. **Encrypted Wallet Serialization**: Use `serializeEncryptedWallet()` from quantum-coin-js-sdk in `Wallet.encryptSync()` instance method
|
|
2982
|
+
11. **Seed Words Wallet Creation**: Use `openWalletFromSeedWords()` from quantum-coin-js-sdk in `Wallet.fromPhrase()` static method (48 words required)
|
|
2983
|
+
12. **RPC Calls**: Use quantum-coin-js-sdk RPC functions (getAccountDetails, getTransactionDetails, etc.)
|
|
2984
|
+
13. **Transaction Remarks**: The `remarks` field is passed through to quantum-coin-js-sdk's TransactionSigningRequest.remarks field (optional, max 32 bytes, hex string with 0x prefix)
|
|
2985
|
+
|
|
2986
|
+
**SDK Source Reference (for implementers)**:
|
|
2987
|
+
- The `quantum-coin-js-sdk` code can be found under `node_modules/quantum-coin-js-sdk/`.
|
|
2988
|
+
- The SDK entrypoint and the `initialize(...)` function can be found in `node_modules/quantum-coin-js-sdk/index.js`.
|
|
2989
|
+
|
|
2990
|
+
### 10.2 Built-in Libraries Only
|
|
2991
|
+
|
|
2992
|
+
Use only built-in JavaScript/Node.js libraries:
|
|
2993
|
+
- `crypto` - For hashing (SHA-256, RIPEMD-160), random bytes
|
|
2994
|
+
- `Buffer` - For byte manipulation
|
|
2995
|
+
- `http`/`https` - For RPC requests (if not using quantum-coin-js-sdk RPC)
|
|
2996
|
+
- `util` - For utility functions
|
|
2997
|
+
- `events` - For event emitters
|
|
2998
|
+
|
|
2999
|
+
### 10.3 Address Format Handling
|
|
3000
|
+
|
|
3001
|
+
- All addresses must be validated as 32 bytes (66 hex characters including 0x)
|
|
3002
|
+
- Address normalization should use quantum-coin-js-sdk validation
|
|
3003
|
+
- Address checksumming (if applicable) should follow QuantumCoin conventions
|
|
3004
|
+
|
|
3005
|
+
### 10.4 Error Handling
|
|
3006
|
+
|
|
3007
|
+
- All errors should extend appropriate error classes
|
|
3008
|
+
- Error messages should be clear and descriptive
|
|
3009
|
+
- Error codes should follow ethers.js patterns where applicable
|
|
3010
|
+
|
|
3011
|
+
### 10.5 Event Handling
|
|
3012
|
+
|
|
3013
|
+
- Use Node.js EventEmitter for event subscriptions
|
|
3014
|
+
- Support block events, transaction events, and contract events
|
|
3015
|
+
- Implement proper cleanup for event listeners
|
|
3016
|
+
|
|
3017
|
+
### 10.6 Transaction Handling
|
|
3018
|
+
|
|
3019
|
+
- Support both legacy and EIP-1559 style transactions (if applicable)
|
|
3020
|
+
- Handle gas estimation and pricing
|
|
3021
|
+
- Support transaction replacement (nonce management)
|
|
3022
|
+
- Implement proper transaction confirmation waiting
|
|
3023
|
+
- Support `remarks` field in transactions (optional, max 32 bytes, public on blockchain)
|
|
3024
|
+
- Validate remarks field: must be hex string with 0x prefix, max 32 bytes when decoded
|
|
3025
|
+
- Use quantum-coin-js-sdk's `signRawTransaction()` which accepts `remarks` in TransactionSigningRequest
|
|
3026
|
+
|
|
3027
|
+
### 10.7 ABI Handling
|
|
3028
|
+
|
|
3029
|
+
- Support all Solidity types (as defined in types.js)
|
|
3030
|
+
- Handle complex types (arrays, structs, tuples)
|
|
3031
|
+
- Support function overloading
|
|
3032
|
+
- Support indexed and non-indexed event parameters
|
|
3033
|
+
|
|
3034
|
+
### 10.8 Async/Await Pattern
|
|
3035
|
+
|
|
3036
|
+
- All provider methods should return Promises
|
|
3037
|
+
- Use async/await throughout
|
|
3038
|
+
- Handle errors with try/catch
|
|
3039
|
+
|
|
3040
|
+
### 10.9 Type Safety
|
|
3041
|
+
|
|
3042
|
+
- Use JSDoc for type annotations
|
|
3043
|
+
- Provide clear parameter and return type documentation
|
|
3044
|
+
- Validate inputs at runtime
|
|
3045
|
+
|
|
3046
|
+
---
|
|
3047
|
+
|
|
3048
|
+
## 11. File Structure
|
|
3049
|
+
|
|
3050
|
+
```
|
|
3051
|
+
quantumcoin.js/
|
|
3052
|
+
├── src/
|
|
3053
|
+
│ ├── providers/
|
|
3054
|
+
│ │ ├── provider.js # Base Provider class
|
|
3055
|
+
│ │ ├── json-rpc-provider.js # JsonRpcProvider
|
|
3056
|
+
│ │ └── index.js
|
|
3057
|
+
│ ├── wallet/
|
|
3058
|
+
│ │ ├── wallet.js # Wallet class
|
|
3059
|
+
│ │ └── index.js
|
|
3060
|
+
│ ├── contract/
|
|
3061
|
+
│ │ ├── contract.js # Contract class
|
|
3062
|
+
│ │ ├── contract-factory.js # ContractFactory
|
|
3063
|
+
│ │ └── index.js
|
|
3064
|
+
│ ├── abi/
|
|
3065
|
+
│ │ ├── interface.js # Interface class
|
|
3066
|
+
│ │ ├── fragments.js # Fragment classes
|
|
3067
|
+
│ │ └── index.js
|
|
3068
|
+
│ ├── utils/
|
|
3069
|
+
│ │ ├── address.js # Address utilities
|
|
3070
|
+
│ │ ├── encoding.js # Encoding utilities
|
|
3071
|
+
│ │ ├── hashing.js # Hash utilities
|
|
3072
|
+
│ │ ├── units.js # Unit conversion
|
|
3073
|
+
│ │ └── index.js
|
|
3074
|
+
│ ├── errors/
|
|
3075
|
+
│ │ ├── index.js # Error classes
|
|
3076
|
+
│ │ └── ...
|
|
3077
|
+
│ └── index.js # Main entry point
|
|
3078
|
+
├── test/
|
|
3079
|
+
│ ├── unit/ # Unit tests (no blockchain connectivity)
|
|
3080
|
+
│ ├── integration/ # Integration tests (read-only blockchain)
|
|
3081
|
+
│ ├── e2e/ # End-to-end tests (write access)
|
|
3082
|
+
│ ├── security/ # Security tests (malformed input, etc.)
|
|
3083
|
+
│ └── fixtures/ # Test fixtures and data
|
|
3084
|
+
├── config.js # Existing config
|
|
3085
|
+
└── package.json
|
|
3086
|
+
```
|
|
3087
|
+
|
|
3088
|
+
---
|
|
3089
|
+
|
|
3090
|
+
## 12. Example Usage Patterns
|
|
3091
|
+
|
|
3092
|
+
### 12.1 Provider Usage
|
|
3093
|
+
|
|
3094
|
+
```javascript
|
|
3095
|
+
const { JsonRpcProvider } = require('quantumcoin');
|
|
3096
|
+
const provider = new JsonRpcProvider('https://public.rpc.quantumcoinapi.com', 123123);
|
|
3097
|
+
|
|
3098
|
+
const balance = await provider.getBalance('0x...');
|
|
3099
|
+
const blockNumber = await provider.getBlockNumber();
|
|
3100
|
+
```
|
|
3101
|
+
|
|
3102
|
+
### 12.2 Wallet Usage
|
|
3103
|
+
|
|
3104
|
+
```javascript
|
|
3105
|
+
const { Wallet } = require('quantumcoin');
|
|
3106
|
+
|
|
3107
|
+
// Create wallet from private key
|
|
3108
|
+
const wallet = new Wallet('0x...privateKey...', provider);
|
|
3109
|
+
|
|
3110
|
+
// Create random wallet
|
|
3111
|
+
const randomWallet = Wallet.createRandom(provider);
|
|
3112
|
+
|
|
3113
|
+
// Create wallet from encrypted JSON
|
|
3114
|
+
const encryptedJson = '{"address":"...","crypto":{...}}';
|
|
3115
|
+
const walletFromJson = Wallet.fromEncryptedJsonSync(encryptedJson, 'password123', provider);
|
|
3116
|
+
|
|
3117
|
+
// Create wallet from seed phrase (48 words) - can be array or string
|
|
3118
|
+
const seedPhraseArray = ['word1', 'word2', ..., 'word48'];
|
|
3119
|
+
const walletFromPhrase1 = Wallet.fromPhrase(seedPhraseArray, provider);
|
|
3120
|
+
|
|
3121
|
+
// Or as a space or comma delimited string
|
|
3122
|
+
const seedPhraseString = 'word1 word2 ... word48'; // or 'word1,word2,...,word48'
|
|
3123
|
+
const walletFromPhrase2 = Wallet.fromPhrase(seedPhraseString, provider);
|
|
3124
|
+
|
|
3125
|
+
// Encrypt wallet to JSON string (instance method)
|
|
3126
|
+
const encryptedJson = wallet.encryptSync('mySecurePassword123');
|
|
3127
|
+
// Can be saved to file and opened in Desktop/Mobile/Web/CLI wallet applications
|
|
3128
|
+
|
|
3129
|
+
// Sign message synchronously
|
|
3130
|
+
const signature = wallet.signMessageSync('Hello, QuantumCoin!');
|
|
3131
|
+
|
|
3132
|
+
const tx = await wallet.sendTransaction({
|
|
3133
|
+
to: '0x...',
|
|
3134
|
+
value: parseEther('1.0')
|
|
3135
|
+
});
|
|
3136
|
+
```
|
|
3137
|
+
|
|
3138
|
+
### 12.3 Contract Usage
|
|
3139
|
+
|
|
3140
|
+
```javascript
|
|
3141
|
+
const { Contract } = require('quantumcoin');
|
|
3142
|
+
const abi = [...]; // ABI array
|
|
3143
|
+
const contract = new Contract('0x...', abi, provider);
|
|
3144
|
+
|
|
3145
|
+
const result = await contract.balanceOf('0x...');
|
|
3146
|
+
const tx = await contract.transfer('0x...', parseEther('1.0'));
|
|
3147
|
+
```
|
|
3148
|
+
|
|
3149
|
+
### 12.4 Contract Deployment
|
|
3150
|
+
|
|
3151
|
+
```javascript
|
|
3152
|
+
const { ContractFactory } = require('quantumcoin');
|
|
3153
|
+
const factory = new ContractFactory(abi, bytecode, wallet);
|
|
3154
|
+
const contract = await factory.deploy(...args);
|
|
3155
|
+
```
|
|
3156
|
+
|
|
3157
|
+
---
|
|
3158
|
+
|
|
3159
|
+
## 13. Testing Requirements
|
|
3160
|
+
|
|
3161
|
+
### 13.1 Test Organization
|
|
3162
|
+
|
|
3163
|
+
Tests should be organized into the following folders:
|
|
3164
|
+
- **`test/unit/`**: Unit tests that don't require blockchain connectivity
|
|
3165
|
+
- **`test/integration/`**: Integration tests that require read-only blockchain connectivity
|
|
3166
|
+
- **`test/e2e/`**: End-to-end tests that require write access (sending transactions)
|
|
3167
|
+
- **`test/security/`**: Security tests with malformed input, edge cases, and attack vectors
|
|
3168
|
+
|
|
3169
|
+
### 13.2 Test Metadata
|
|
3170
|
+
|
|
3171
|
+
Each test file must include metadata to specify test categories:
|
|
3172
|
+
|
|
3173
|
+
```javascript
|
|
3174
|
+
/**
|
|
3175
|
+
* @testCategory unit|integration|e2e|security
|
|
3176
|
+
* @blockchainRequired false|readonly|write
|
|
3177
|
+
* @description Brief description of what this test suite covers
|
|
3178
|
+
*/
|
|
3179
|
+
```
|
|
3180
|
+
|
|
3181
|
+
**Test Categories:**
|
|
3182
|
+
- **`unit`**: Tests that don't need blockchain connectivity (pure functions, utilities, encoding/decoding, etc.)
|
|
3183
|
+
- **`integration`**: Tests that need read-only blockchain connectivity (querying blocks, transactions, contract reads, etc.)
|
|
3184
|
+
- **`e2e`**: Tests that need write access (sending transactions, deploying contracts, etc.)
|
|
3185
|
+
- **`security`**: Tests for security vulnerabilities, malformed input, edge cases, etc.
|
|
3186
|
+
|
|
3187
|
+
**Blockchain Requirements:**
|
|
3188
|
+
- **`false`**: No blockchain connectivity needed
|
|
3189
|
+
- **`readonly`**: Read-only blockchain access (queries only)
|
|
3190
|
+
- **`write`**: Write access required (sending transactions)
|
|
3191
|
+
|
|
3192
|
+
### 13.3 Test Configuration
|
|
3193
|
+
|
|
3194
|
+
**RPC Endpoint**: `https://public.rpc.quantumcoinapi.com`
|
|
3195
|
+
**Chain ID**: `123123`
|
|
3196
|
+
|
|
3197
|
+
**Test Data Requirements:**
|
|
3198
|
+
- For block-related tests: Use block numbers greater than `3000000`
|
|
3199
|
+
- For transaction read-only tests: Use transactions between blocks `3385844` to `3387473` (inclusive)
|
|
3200
|
+
- For smart contract read-only tests:
|
|
3201
|
+
- Contract Address: `0x0000000000000000000000000000000000000000000000000000000000001000`
|
|
3202
|
+
- ABI: Available at `https://raw.githubusercontent.com/quantumcoinproject/quantum-coin-go/refs/heads/dogep/systemcontracts/staking/stakingv2/StakingContract.abi`
|
|
3203
|
+
|
|
3204
|
+
### 13.4 Test Coverage Requirements
|
|
3205
|
+
|
|
3206
|
+
#### 13.4.1 Comprehensive Test Coverage
|
|
3207
|
+
|
|
3208
|
+
All tests must include:
|
|
3209
|
+
- **Positive test cases**: Valid inputs and expected successful outcomes
|
|
3210
|
+
- **Negative test cases**: Invalid inputs, error conditions, and edge cases
|
|
3211
|
+
- **Optional parameter coverage**: Tests must cover all combinations of optional parameters to achieve 100% code coverage of the SDK
|
|
3212
|
+
- Test with all optional parameters provided
|
|
3213
|
+
- Test with no optional parameters (using defaults)
|
|
3214
|
+
- Test with partial optional parameters (various combinations)
|
|
3215
|
+
|
|
3216
|
+
#### 13.4.2 Unit Tests (No Blockchain Connectivity)
|
|
3217
|
+
|
|
3218
|
+
Test areas:
|
|
3219
|
+
- Address validation and conversion (32-byte addresses)
|
|
3220
|
+
- Encoding/decoding utilities
|
|
3221
|
+
- Hash functions
|
|
3222
|
+
- Unit conversions
|
|
3223
|
+
- Error classes and error handling
|
|
3224
|
+
- Wallet creation and management (without sending transactions)
|
|
3225
|
+
- Message signing (offline)
|
|
3226
|
+
- ABI parsing and fragment handling
|
|
3227
|
+
- Data encoding/decoding
|
|
3228
|
+
|
|
3229
|
+
#### 13.4.3 Integration Tests (Read-Only Blockchain)
|
|
3230
|
+
|
|
3231
|
+
Test areas:
|
|
3232
|
+
- Provider initialization and connection
|
|
3233
|
+
- Block queries (`getBlock`, `getBlockNumber`, etc.)
|
|
3234
|
+
- Transaction queries (`getTransaction`, `getTransactionReceipt`, etc.)
|
|
3235
|
+
- Balance queries (`getBalance`)
|
|
3236
|
+
- Contract read operations (using the staking contract at `0x0000000000000000000000000000000000000000000000000000000000001000`)
|
|
3237
|
+
- Event filtering and querying (read-only)
|
|
3238
|
+
- Log queries
|
|
3239
|
+
- Gas estimation (read-only operation)
|
|
3240
|
+
- Network information queries
|
|
3241
|
+
|
|
3242
|
+
**Test Data:**
|
|
3243
|
+
- Blocks: Use block numbers > 3000000
|
|
3244
|
+
- Transactions: Use transactions from blocks 3385844 to 3387473
|
|
3245
|
+
- Contract: Use staking contract at `0x0000000000000000000000000000000000000000000000000000000000001000`
|
|
3246
|
+
|
|
3247
|
+
#### 13.4.4 End-to-End Tests (Write Access)
|
|
3248
|
+
|
|
3249
|
+
Test areas:
|
|
3250
|
+
- Sending standard transactions
|
|
3251
|
+
- Contract deployment
|
|
3252
|
+
- Contract write operations
|
|
3253
|
+
- Transaction confirmation and receipt handling
|
|
3254
|
+
- Event listening and subscription
|
|
3255
|
+
- Transaction replacement and cancellation
|
|
3256
|
+
|
|
3257
|
+
**Test Wallet:**
|
|
3258
|
+
- A hardcoded test wallet must be included in test files for sending transactions
|
|
3259
|
+
- The test wallet should have sufficient balance for testing
|
|
3260
|
+
- Private key should be stored securely in test configuration (not committed to version control in production)
|
|
3261
|
+
|
|
3262
|
+
**IERC20 Contract Tests:**
|
|
3263
|
+
- Deploy a standard IERC20 contract
|
|
3264
|
+
- Test all IERC20 operations:
|
|
3265
|
+
- `transfer(to, amount)`
|
|
3266
|
+
- `transferFrom(from, to, amount)`
|
|
3267
|
+
- `approve(spender, amount)`
|
|
3268
|
+
- `balanceOf(account)`
|
|
3269
|
+
- `allowance(owner, spender)`
|
|
3270
|
+
- `totalSupply()`
|
|
3271
|
+
- Test events: `Transfer`, `Approval`
|
|
3272
|
+
- Test with various parameter combinations and optional parameters
|
|
3273
|
+
|
|
3274
|
+
#### 13.4.5 Security Tests
|
|
3275
|
+
|
|
3276
|
+
Test areas:
|
|
3277
|
+
- **Malformed input handling**:
|
|
3278
|
+
- Invalid addresses (wrong length, invalid characters, etc.)
|
|
3279
|
+
- Invalid transaction data
|
|
3280
|
+
- Invalid ABI formats
|
|
3281
|
+
- Invalid block numbers and tags
|
|
3282
|
+
- Invalid hex strings
|
|
3283
|
+
- Invalid numeric values (negative, overflow, etc.)
|
|
3284
|
+
- **Edge cases**:
|
|
3285
|
+
- Empty strings and null/undefined values
|
|
3286
|
+
- Very large numbers (overflow scenarios)
|
|
3287
|
+
- Zero values
|
|
3288
|
+
- Boundary conditions
|
|
3289
|
+
- **Attack vectors**:
|
|
3290
|
+
- SQL injection attempts in string parameters
|
|
3291
|
+
- Buffer overflow attempts
|
|
3292
|
+
- Reentrancy scenarios (where applicable)
|
|
3293
|
+
- Invalid signature handling
|
|
3294
|
+
- Invalid transaction replay attempts
|
|
3295
|
+
|
|
3296
|
+
### 13.5 Code Coverage Goal
|
|
3297
|
+
|
|
3298
|
+
The test suite must achieve **100% code coverage** of the SDK. This includes:
|
|
3299
|
+
- All public methods
|
|
3300
|
+
- All private/internal methods
|
|
3301
|
+
- All error paths
|
|
3302
|
+
- All optional parameter combinations
|
|
3303
|
+
- All conditional branches
|
|
3304
|
+
- All edge cases
|
|
3305
|
+
|
|
3306
|
+
### 13.6 Test Examples
|
|
3307
|
+
|
|
3308
|
+
#### Example: Unit Test Structure
|
|
3309
|
+
|
|
3310
|
+
```javascript
|
|
3311
|
+
/**
|
|
3312
|
+
* @testCategory unit
|
|
3313
|
+
* @blockchainRequired false
|
|
3314
|
+
* @description Tests for address utilities
|
|
3315
|
+
*/
|
|
3316
|
+
describe('Address Utilities', () => {
|
|
3317
|
+
describe('isAddress', () => {
|
|
3318
|
+
it('should return true for valid 32-byte address', () => {
|
|
3319
|
+
// Positive test case
|
|
3320
|
+
});
|
|
3321
|
+
|
|
3322
|
+
it('should return false for invalid address', () => {
|
|
3323
|
+
// Negative test case
|
|
3324
|
+
});
|
|
3325
|
+
|
|
3326
|
+
it('should handle optional checksum parameter', () => {
|
|
3327
|
+
// Optional parameter test
|
|
3328
|
+
});
|
|
3329
|
+
});
|
|
3330
|
+
});
|
|
3331
|
+
```
|
|
3332
|
+
|
|
3333
|
+
#### Example: Integration Test Structure
|
|
3334
|
+
|
|
3335
|
+
```javascript
|
|
3336
|
+
/**
|
|
3337
|
+
* @testCategory integration
|
|
3338
|
+
* @blockchainRequired readonly
|
|
3339
|
+
* @description Tests for block queries
|
|
3340
|
+
*/
|
|
3341
|
+
describe('Block Queries', () => {
|
|
3342
|
+
const provider = new JsonRpcProvider('https://public.rpc.quantumcoinapi.com', 123123);
|
|
3343
|
+
|
|
3344
|
+
describe('getBlock', () => {
|
|
3345
|
+
it('should get block by number > 3000000', async () => {
|
|
3346
|
+
// Test with block number
|
|
3347
|
+
});
|
|
3348
|
+
|
|
3349
|
+
it('should get block with "latest" tag', async () => {
|
|
3350
|
+
// Test with optional block tag
|
|
3351
|
+
});
|
|
3352
|
+
|
|
3353
|
+
it('should get block without optional parameters', async () => {
|
|
3354
|
+
// Test default behavior
|
|
3355
|
+
});
|
|
3356
|
+
});
|
|
3357
|
+
});
|
|
3358
|
+
```
|
|
3359
|
+
|
|
3360
|
+
#### Example: E2E Test Structure
|
|
3361
|
+
|
|
3362
|
+
```javascript
|
|
3363
|
+
/**
|
|
3364
|
+
* @testCategory e2e
|
|
3365
|
+
* @blockchainRequired write
|
|
3366
|
+
* @description Tests for IERC20 contract deployment and interaction
|
|
3367
|
+
*/
|
|
3368
|
+
describe('IERC20 Contract', () => {
|
|
3369
|
+
const provider = new JsonRpcProvider('https://public.rpc.quantumcoinapi.com', 123123);
|
|
3370
|
+
const wallet = new Wallet(TEST_WALLET_PRIVATE_KEY, provider);
|
|
3371
|
+
|
|
3372
|
+
describe('Contract Deployment', () => {
|
|
3373
|
+
it('should deploy IERC20 contract', async () => {
|
|
3374
|
+
// Deploy contract
|
|
3375
|
+
});
|
|
3376
|
+
});
|
|
3377
|
+
|
|
3378
|
+
describe('Contract Interactions', () => {
|
|
3379
|
+
it('should transfer tokens', async () => {
|
|
3380
|
+
// Test transfer with all parameters
|
|
3381
|
+
});
|
|
3382
|
+
|
|
3383
|
+
it('should transfer tokens with default gas settings', async () => {
|
|
3384
|
+
// Test with optional parameters omitted
|
|
3385
|
+
});
|
|
3386
|
+
});
|
|
3387
|
+
});
|
|
3388
|
+
```
|
|
3389
|
+
|
|
3390
|
+
#### Example: Security Test Structure
|
|
3391
|
+
|
|
3392
|
+
```javascript
|
|
3393
|
+
/**
|
|
3394
|
+
* @testCategory security
|
|
3395
|
+
* @blockchainRequired false
|
|
3396
|
+
* @description Security tests for malformed input
|
|
3397
|
+
*/
|
|
3398
|
+
describe('Security: Malformed Input', () => {
|
|
3399
|
+
describe('Address Validation', () => {
|
|
3400
|
+
it('should reject addresses with invalid length', () => {
|
|
3401
|
+
// Security test
|
|
3402
|
+
});
|
|
3403
|
+
|
|
3404
|
+
it('should reject addresses with SQL injection attempts', () => {
|
|
3405
|
+
// Security test
|
|
3406
|
+
});
|
|
3407
|
+
});
|
|
3408
|
+
});
|
|
3409
|
+
```
|
|
3410
|
+
|
|
3411
|
+
### 13.7 Test Execution
|
|
3412
|
+
|
|
3413
|
+
Tests should be organized to allow selective execution:
|
|
3414
|
+
- Run only unit tests (fast, no network)
|
|
3415
|
+
- Run only integration tests (read-only, requires network)
|
|
3416
|
+
- Run only e2e tests (write access, requires network and test funds)
|
|
3417
|
+
- Run only security tests
|
|
3418
|
+
- Run all tests
|
|
3419
|
+
|
|
3420
|
+
### 13.8 Additional Requirements
|
|
3421
|
+
|
|
3422
|
+
- All tests must be deterministic and repeatable
|
|
3423
|
+
- Tests should clean up after themselves (where applicable)
|
|
3424
|
+
- Tests should not interfere with each other
|
|
3425
|
+
- Use appropriate test timeouts for network operations
|
|
3426
|
+
- Mock external dependencies where appropriate (for unit tests)
|
|
3427
|
+
- Use real blockchain data for integration and e2e tests
|
|
3428
|
+
|
|
3429
|
+
### 13.9 Implementation Gate: Non-Transaction Tests Must Pass
|
|
3430
|
+
|
|
3431
|
+
After the rest of this specification is implemented (i.e., once the SDK APIs described in this document exist), the implementation MUST run **all tests that do not require sending transactions** and ensure they succeed.
|
|
3432
|
+
|
|
3433
|
+
- **Included**: all test suites marked `@blockchainRequired false` or `@blockchainRequired readonly`
|
|
3434
|
+
- **Excluded**: any test suites marked `@blockchainRequired write` (i.e., tests that send transactions)
|
|
3435
|
+
|
|
3436
|
+
If any included test fails:
|
|
3437
|
+
- **Diagnose** whether the failure is due to a **test bug** or a **SDK implementation bug**
|
|
3438
|
+
- **Fix** the test (if the test is incorrect) or fix the SDK code (if the SDK is incorrect)
|
|
3439
|
+
- **Re-run** the included test set and **repeat** until all included tests pass
|
|
3440
|
+
|
|
3441
|
+
---
|
|
3442
|
+
|
|
3443
|
+
## 14. Documentation Requirements
|
|
3444
|
+
|
|
3445
|
+
- **Code and Documentation Comments**: All code must include detailed comments and documentation. Code comments should explain the logic, purpose, and implementation details. Documentation comments (JSDoc) should be comprehensive and clear, enabling both readers of the code and users of the SDK to understand functionality, parameters, return values, and usage patterns. Doc-level comments must appear in the SDK code itself (as JSDoc comments), not just in separate documentation files, so that they are available to SDK users through IDE tooltips and documentation generation tools.
|
|
3446
|
+
- JSDoc comments for all public methods
|
|
3447
|
+
- Usage examples for each major class
|
|
3448
|
+
- Migration guide from ethers.js
|
|
3449
|
+
- API reference documentation
|
|
3450
|
+
- Troubleshooting guide
|
|
3451
|
+
|
|
3452
|
+
---
|
|
3453
|
+
|
|
3454
|
+
## 15. Typed Contract Generator
|
|
3455
|
+
|
|
3456
|
+
### 15.1 Overview
|
|
3457
|
+
|
|
3458
|
+
A typed contract generator tool that creates fully-typed contract classes from ABI and bytecode. This generator produces TypeScript/JavaScript classes with proper types, methods, and deployment factories based on the provided contract ABI and binary code.
|
|
3459
|
+
|
|
3460
|
+
### 15.2 Generator Input
|
|
3461
|
+
|
|
3462
|
+
The generator accepts the following inputs:
|
|
3463
|
+
- **Contract ABI**: JSON array containing the contract's Application Binary Interface
|
|
3464
|
+
- **Contract Bytecode (bin)**: Hexadecimal string containing the compiled contract bytecode
|
|
3465
|
+
|
|
3466
|
+
### 15.3 Interactive Setup Process
|
|
3467
|
+
|
|
3468
|
+
#### 15.3.1 Package Creation Prompt
|
|
3469
|
+
|
|
3470
|
+
When invoked, the generator first asks:
|
|
3471
|
+
```
|
|
3472
|
+
Do you want to create a new package? (Y/N)
|
|
3473
|
+
```
|
|
3474
|
+
|
|
3475
|
+
#### 15.3.2 New Package Creation (Y)
|
|
3476
|
+
|
|
3477
|
+
If the user selects **Yes**, the generator prompts for:
|
|
3478
|
+
|
|
3479
|
+
1. **Package Location**:
|
|
3480
|
+
- Prompt: `Enter the folder path where the package should be created:`
|
|
3481
|
+
- User provides absolute or relative path
|
|
3482
|
+
|
|
3483
|
+
2. **Package Name**:
|
|
3484
|
+
- Prompt: `Enter package name:`
|
|
3485
|
+
- Must be valid npm package name
|
|
3486
|
+
|
|
3487
|
+
3. **Package Description**:
|
|
3488
|
+
- Prompt: `Enter package description:`
|
|
3489
|
+
- Brief description of the generated contract package
|
|
3490
|
+
|
|
3491
|
+
4. **Author**:
|
|
3492
|
+
- Prompt: `Enter author name:`
|
|
3493
|
+
- Author information for package.json
|
|
3494
|
+
|
|
3495
|
+
5. **License**:
|
|
3496
|
+
- Prompt: `Enter license (default: MIT):`
|
|
3497
|
+
- Default: `MIT` (if user presses Enter without input)
|
|
3498
|
+
- User can specify custom license
|
|
3499
|
+
|
|
3500
|
+
6. **Version**:
|
|
3501
|
+
- Prompt: `Enter version (default: 0.0.1):`
|
|
3502
|
+
- Default: `0.0.1` (if user presses Enter without input)
|
|
3503
|
+
- Must follow semantic versioning
|
|
3504
|
+
|
|
3505
|
+
**Dependencies**: The generator automatically adds all dependencies from `quantumcoin.js` package.json to the generated package's dependencies.
|
|
3506
|
+
|
|
3507
|
+
#### 15.3.3 Existing Package Integration (N)
|
|
3508
|
+
|
|
3509
|
+
If the user selects **No**, the generator prompts for:
|
|
3510
|
+
|
|
3511
|
+
1. **Target Location**:
|
|
3512
|
+
- Prompt: `Enter the location in your existing package (relative to package root):`
|
|
3513
|
+
- User provides path where contract files should be generated
|
|
3514
|
+
- Example: `src/contracts` or `contracts`
|
|
3515
|
+
|
|
3516
|
+
### 15.4 Generated Code Structure
|
|
3517
|
+
|
|
3518
|
+
#### 15.4.1 Contract Class
|
|
3519
|
+
|
|
3520
|
+
The generator creates a typed contract class with the following features:
|
|
3521
|
+
|
|
3522
|
+
**Class Name**: Based on contract name from ABI (if available) or derived from package name
|
|
3523
|
+
|
|
3524
|
+
**Constructor**:
|
|
3525
|
+
```typescript
|
|
3526
|
+
constructor(address: string, runner?: ContractRunner, _deployTx?: TransactionResponse)
|
|
3527
|
+
```
|
|
3528
|
+
- `address`: Contract address (32-byte QuantumCoin address)
|
|
3529
|
+
- `runner`: Optional ContractRunner (Provider or Signer)
|
|
3530
|
+
- `_deployTx`: Optional deployment transaction (for newly deployed contracts)
|
|
3531
|
+
|
|
3532
|
+
**Typed Methods**:
|
|
3533
|
+
- **Read-only functions**: Return typed results using types from quantumcoin.js
|
|
3534
|
+
- **State-changing functions**: Return `ContractTransactionResponse` from quantumcoin.js
|
|
3535
|
+
- **View functions**: Return typed values based on ABI return types
|
|
3536
|
+
- **Pure functions**: Return typed values based on ABI return types
|
|
3537
|
+
|
|
3538
|
+
**Method Signatures**:
|
|
3539
|
+
- All method parameters are typed based on ABI input types
|
|
3540
|
+
- All return types use quantumcoin.js types (e.g., `bigint`, `string`, `AddressLike`, etc.)
|
|
3541
|
+
- Optional parameters are properly marked
|
|
3542
|
+
- Overloads are generated for functions with optional parameters
|
|
3543
|
+
|
|
3544
|
+
**Event Handling**:
|
|
3545
|
+
- Typed event filters and listeners
|
|
3546
|
+
- Event types match quantumcoin.js `EventLog` structure
|
|
3547
|
+
- Indexed and non-indexed parameters are properly typed
|
|
3548
|
+
|
|
3549
|
+
**Error Handling**:
|
|
3550
|
+
- Custom error classes for contract-specific errors
|
|
3551
|
+
- Error types match quantumcoin.js error patterns
|
|
3552
|
+
|
|
3553
|
+
#### 15.4.2 Contract Factory
|
|
3554
|
+
|
|
3555
|
+
The generator creates a `ContractFactory` class for deployment:
|
|
3556
|
+
|
|
3557
|
+
**Class Name**: `{ContractName}__factory`
|
|
3558
|
+
|
|
3559
|
+
**Static Methods**:
|
|
3560
|
+
```typescript
|
|
3561
|
+
static connect(address: string, runner?: ContractRunner): {ContractName}
|
|
3562
|
+
```
|
|
3563
|
+
- Creates a contract instance at the given address
|
|
3564
|
+
|
|
3565
|
+
**Instance Methods**:
|
|
3566
|
+
```typescript
|
|
3567
|
+
deploy(...constructorArgs: TypedArgs[]): Promise<{ContractName}>
|
|
3568
|
+
```
|
|
3569
|
+
- Deploys the contract with typed constructor arguments
|
|
3570
|
+
- Returns a contract instance with the deployment transaction attached
|
|
3571
|
+
|
|
3572
|
+
**Properties**:
|
|
3573
|
+
- `bytecode`: The contract bytecode
|
|
3574
|
+
- `interface`: The contract ABI interface
|
|
3575
|
+
- `abi`: The contract ABI array
|
|
3576
|
+
|
|
3577
|
+
#### 15.4.3 Type Definitions
|
|
3578
|
+
|
|
3579
|
+
The generator creates TypeScript type definitions for:
|
|
3580
|
+
- Function parameters (input types)
|
|
3581
|
+
- Function return values (output types)
|
|
3582
|
+
- Event parameters
|
|
3583
|
+
- Struct types (if present in ABI)
|
|
3584
|
+
- Tuple types (if present in ABI)
|
|
3585
|
+
|
|
3586
|
+
All types use quantumcoin.js type system:
|
|
3587
|
+
- `bigint` for uint/int types
|
|
3588
|
+
- `string` for addresses (32-byte)
|
|
3589
|
+
- `BytesLike` for bytes types
|
|
3590
|
+
- Custom struct types for complex data structures
|
|
3591
|
+
|
|
3592
|
+
#### 15.4.4 Code Comments
|
|
3593
|
+
|
|
3594
|
+
All generated code includes comprehensive JSDoc comments:
|
|
3595
|
+
|
|
3596
|
+
**Class Comments**:
|
|
3597
|
+
```typescript
|
|
3598
|
+
/**
|
|
3599
|
+
* {ContractName} - A typed contract interface for {ContractName}
|
|
3600
|
+
*
|
|
3601
|
+
* @description {Description from ABI or package description}
|
|
3602
|
+
* @example
|
|
3603
|
+
* ```typescript
|
|
3604
|
+
* const contract = new {ContractName}(address, provider);
|
|
3605
|
+
* const result = await contract.someMethod(...args);
|
|
3606
|
+
* ```
|
|
3607
|
+
*/
|
|
3608
|
+
```
|
|
3609
|
+
|
|
3610
|
+
**Method Comments**:
|
|
3611
|
+
```typescript
|
|
3612
|
+
/**
|
|
3613
|
+
* {methodName} - {Description from ABI}
|
|
3614
|
+
*
|
|
3615
|
+
* @param {paramName} - {Type and description}
|
|
3616
|
+
* @returns {Return type description}
|
|
3617
|
+
* @throws {Error conditions}
|
|
3618
|
+
*
|
|
3619
|
+
* @example
|
|
3620
|
+
* ```typescript
|
|
3621
|
+
* const result = await contract.{methodName}(...args);
|
|
3622
|
+
* ```
|
|
3623
|
+
*/
|
|
3624
|
+
```
|
|
3625
|
+
|
|
3626
|
+
**Transaction Methods**:
|
|
3627
|
+
```typescript
|
|
3628
|
+
/**
|
|
3629
|
+
* {methodName} - Sends a transaction to {methodName}
|
|
3630
|
+
*
|
|
3631
|
+
* @param {paramName} - {Type and description}
|
|
3632
|
+
* @param overrides - Optional transaction overrides (gas, value, etc.)
|
|
3633
|
+
* @returns Promise<ContractTransactionResponse> - Transaction response object
|
|
3634
|
+
*
|
|
3635
|
+
* @example
|
|
3636
|
+
* ```typescript
|
|
3637
|
+
* const tx = await contract.{methodName}(...args, {
|
|
3638
|
+
* gasLimit: 100000n,
|
|
3639
|
+
* value: parseEther("1.0")
|
|
3640
|
+
* });
|
|
3641
|
+
* await tx.wait();
|
|
3642
|
+
* ```
|
|
3643
|
+
*/
|
|
3644
|
+
```
|
|
3645
|
+
|
|
3646
|
+
### 15.5 Generated File Structure
|
|
3647
|
+
|
|
3648
|
+
#### 15.5.1 New Package Structure
|
|
3649
|
+
|
|
3650
|
+
```
|
|
3651
|
+
{package-name}/
|
|
3652
|
+
├── package.json # Generated with dependencies
|
|
3653
|
+
├── tsconfig.json # TypeScript configuration
|
|
3654
|
+
├── README.md # Generated README
|
|
3655
|
+
├── src/
|
|
3656
|
+
│ ├── {ContractName}.ts # Main contract class
|
|
3657
|
+
│ ├── {ContractName}__factory.ts # Contract factory
|
|
3658
|
+
│ ├── types.ts # Type definitions
|
|
3659
|
+
│ └── index.ts # Main exports
|
|
3660
|
+
└── examples/
|
|
3661
|
+
├── deploy.ts # Deployment example
|
|
3662
|
+
├── read-operations.ts # Read-only operations example
|
|
3663
|
+
├── write-operations.ts # Transaction examples
|
|
3664
|
+
└── events.ts # Event listening examples
|
|
3665
|
+
```
|
|
3666
|
+
|
|
3667
|
+
#### 15.5.2 Existing Package Structure
|
|
3668
|
+
|
|
3669
|
+
```
|
|
3670
|
+
{existing-package}/
|
|
3671
|
+
└── {target-location}/
|
|
3672
|
+
├── {ContractName}.ts
|
|
3673
|
+
├── {ContractName}__factory.ts
|
|
3674
|
+
├── types.ts
|
|
3675
|
+
└── index.ts
|
|
3676
|
+
```
|
|
3677
|
+
|
|
3678
|
+
### 15.6 Example Generation
|
|
3679
|
+
|
|
3680
|
+
#### 15.6.1 Example Files
|
|
3681
|
+
|
|
3682
|
+
The generator creates example files in the `examples/` folder:
|
|
3683
|
+
|
|
3684
|
+
**deploy.ts**:
|
|
3685
|
+
```typescript
|
|
3686
|
+
import { JsonRpcProvider, Wallet } from 'quantumcoin';
|
|
3687
|
+
import { {ContractName}, {ContractName}__factory } from '../src';
|
|
3688
|
+
|
|
3689
|
+
async function deploy() {
|
|
3690
|
+
const provider = new JsonRpcProvider('https://public.rpc.quantumcoinapi.com', 123123);
|
|
3691
|
+
const wallet = new Wallet('0x...privateKey...', provider);
|
|
3692
|
+
|
|
3693
|
+
const factory = new {ContractName}__factory(wallet);
|
|
3694
|
+
const contract = await factory.deploy(...constructorArgs);
|
|
3695
|
+
|
|
3696
|
+
console.log('Contract deployed at:', contract.target);
|
|
3697
|
+
console.log('Deployment transaction:', contract.deploymentTransaction()?.hash);
|
|
3698
|
+
|
|
3699
|
+
await contract.deploymentTransaction()?.wait();
|
|
3700
|
+
console.log('Contract deployed and confirmed!');
|
|
3701
|
+
}
|
|
3702
|
+
|
|
3703
|
+
deploy().catch(console.error);
|
|
3704
|
+
```
|
|
3705
|
+
|
|
3706
|
+
**read-operations.ts**:
|
|
3707
|
+
```typescript
|
|
3708
|
+
import { JsonRpcProvider } from 'quantumcoin';
|
|
3709
|
+
import { {ContractName} } from '../src';
|
|
3710
|
+
|
|
3711
|
+
async function readOperations() {
|
|
3712
|
+
const provider = new JsonRpcProvider('https://public.rpc.quantumcoinapi.com', 123123);
|
|
3713
|
+
const contract = {ContractName}.connect('0x...contractAddress...', provider);
|
|
3714
|
+
|
|
3715
|
+
// Example read operations based on ABI
|
|
3716
|
+
const result = await contract.someViewFunction(...args);
|
|
3717
|
+
console.log('Result:', result);
|
|
3718
|
+
}
|
|
3719
|
+
|
|
3720
|
+
readOperations().catch(console.error);
|
|
3721
|
+
```
|
|
3722
|
+
|
|
3723
|
+
**write-operations.ts**:
|
|
3724
|
+
```typescript
|
|
3725
|
+
import { JsonRpcProvider, Wallet, parseEther } from 'quantumcoin';
|
|
3726
|
+
import { {ContractName} } from '../src';
|
|
3727
|
+
|
|
3728
|
+
async function writeOperations() {
|
|
3729
|
+
const provider = new JsonRpcProvider('https://public.rpc.quantumcoinapi.com', 123123);
|
|
3730
|
+
const wallet = new Wallet('0x...privateKey...', provider);
|
|
3731
|
+
const contract = {ContractName}.connect('0x...contractAddress...', wallet);
|
|
3732
|
+
|
|
3733
|
+
// Example transaction operations based on ABI
|
|
3734
|
+
const tx = await contract.someStateChangingFunction(...args, {
|
|
3735
|
+
gasLimit: 100000n
|
|
3736
|
+
});
|
|
3737
|
+
console.log('Transaction hash:', tx.hash);
|
|
3738
|
+
|
|
3739
|
+
const receipt = await tx.wait();
|
|
3740
|
+
console.log('Transaction confirmed in block:', receipt.blockNumber);
|
|
3741
|
+
}
|
|
3742
|
+
|
|
3743
|
+
writeOperations().catch(console.error);
|
|
3744
|
+
```
|
|
3745
|
+
|
|
3746
|
+
**events.ts**:
|
|
3747
|
+
```typescript
|
|
3748
|
+
import { JsonRpcProvider } from 'quantumcoin';
|
|
3749
|
+
import { {ContractName} } from '../src';
|
|
3750
|
+
|
|
3751
|
+
async function listenToEvents() {
|
|
3752
|
+
const provider = new JsonRpcProvider('https://public.rpc.quantumcoinapi.com', 123123);
|
|
3753
|
+
const contract = {ContractName}.connect('0x...contractAddress...', provider);
|
|
3754
|
+
|
|
3755
|
+
// Example event listening based on ABI
|
|
3756
|
+
contract.on('SomeEvent', (event) => {
|
|
3757
|
+
console.log('Event received:', event);
|
|
3758
|
+
});
|
|
3759
|
+
|
|
3760
|
+
// Filter events
|
|
3761
|
+
const filter = contract.filters.SomeEvent(...args);
|
|
3762
|
+
const events = await contract.queryFilter(filter, fromBlock, toBlock);
|
|
3763
|
+
console.log('Filtered events:', events);
|
|
3764
|
+
}
|
|
3765
|
+
|
|
3766
|
+
listenToEvents().catch(console.error);
|
|
3767
|
+
```
|
|
3768
|
+
|
|
3769
|
+
### 15.7 Transaction Return Types
|
|
3770
|
+
|
|
3771
|
+
Methods that send transactions must return the appropriate transaction object from quantumcoin.js:
|
|
3772
|
+
|
|
3773
|
+
- **Return Type**: `Promise<ContractTransactionResponse>`
|
|
3774
|
+
- **Properties**: All properties from `ContractTransactionResponse`:
|
|
3775
|
+
- `hash`: Transaction hash
|
|
3776
|
+
- `to`: Recipient address
|
|
3777
|
+
- `from`: Sender address
|
|
3778
|
+
- `value`: Transaction value
|
|
3779
|
+
- `data`: Transaction data
|
|
3780
|
+
- `gasLimit`: Gas limit
|
|
3781
|
+
- `gasPrice`: Gas price
|
|
3782
|
+
- `nonce`: Transaction nonce
|
|
3783
|
+
- `chainId`: Chain ID
|
|
3784
|
+
- `wait()`: Method to wait for confirmation
|
|
3785
|
+
- `getTransaction()`: Get full transaction details
|
|
3786
|
+
- `getReceipt()`: Get transaction receipt
|
|
3787
|
+
|
|
3788
|
+
### 15.8 Type Mapping
|
|
3789
|
+
|
|
3790
|
+
The generator maps Solidity types to quantumcoin.js types:
|
|
3791
|
+
|
|
3792
|
+
| Solidity Type | quantumcoin.js Type |
|
|
3793
|
+
|--------------|---------------------|
|
|
3794
|
+
| `address` | `string` (32-byte address) |
|
|
3795
|
+
| `uint8` to `uint256` | `bigint` |
|
|
3796
|
+
| `int8` to `int256` | `bigint` |
|
|
3797
|
+
| `bool` | `boolean` |
|
|
3798
|
+
| `bytes1` to `bytes32` | `BytesLike` |
|
|
3799
|
+
| `bytes` | `BytesLike` |
|
|
3800
|
+
| `string` | `string` |
|
|
3801
|
+
| `tuple` | Custom type or object |
|
|
3802
|
+
| Arrays | `Array<Type>` |
|
|
3803
|
+
| Mappings | Not directly accessible (use getter functions) |
|
|
3804
|
+
|
|
3805
|
+
### 15.9 Generator Implementation Requirements
|
|
3806
|
+
|
|
3807
|
+
1. **ABI Parsing**: Parse ABI JSON to extract functions, events, errors, and constructor
|
|
3808
|
+
2. **Type Inference**: Infer TypeScript types from ABI parameter types
|
|
3809
|
+
3. **Method Generation**: Generate typed methods for all functions in ABI
|
|
3810
|
+
4. **Event Generation**: Generate typed event filters and listeners
|
|
3811
|
+
5. **Error Generation**: Generate custom error classes for contract errors
|
|
3812
|
+
6. **Factory Generation**: Generate ContractFactory with deployment support
|
|
3813
|
+
7. **Example Generation**: Generate comprehensive examples for all operations
|
|
3814
|
+
8. **Documentation**: Generate JSDoc comments for all generated code
|
|
3815
|
+
9. **Package Setup**: Create package.json with proper dependencies
|
|
3816
|
+
10. **Type Safety**: Ensure all generated code is fully typed
|
|
3817
|
+
|
|
3818
|
+
### 15.10 Usage
|
|
3819
|
+
|
|
3820
|
+
The generator should be invoked as a command-line tool or script:
|
|
3821
|
+
|
|
3822
|
+
```bash
|
|
3823
|
+
# As a CLI tool
|
|
3824
|
+
npx sdkgen --abi path/to/abi.json --bin path/to/bytecode.bin
|
|
3825
|
+
|
|
3826
|
+
# Or as a Node.js script
|
|
3827
|
+
node generate-sdk.js --abi path/to/abi.json --bin path/to/bytecode.bin
|
|
3828
|
+
```
|
|
3829
|
+
|
|
3830
|
+
The generator should support:
|
|
3831
|
+
- Interactive mode (prompts for all inputs)
|
|
3832
|
+
- Non-interactive mode (all inputs via command-line arguments)
|
|
3833
|
+
- Configuration file input (JSON/YAML config file)
|
|
3834
|
+
|
|
3835
|
+
---
|
|
3836
|
+
|
|
3837
|
+
## Notes
|
|
3838
|
+
|
|
3839
|
+
1. This specification is based on ethers.js v6 patterns but adapted for QuantumCoin
|
|
3840
|
+
2. All address-related operations must account for 32-byte addresses
|
|
3841
|
+
3. HDWallet functionality is explicitly excluded
|
|
3842
|
+
4. All cryptographic operations must use quantum-coin-js-sdk
|
|
3843
|
+
5. The implementation should be as compatible as possible with ethers.js v6 for ease of migration
|