lighter-ts-sdk 1.0.0

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.
Files changed (110) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +440 -0
  3. package/dist/api/account-api.d.ts +89 -0
  4. package/dist/api/account-api.d.ts.map +1 -0
  5. package/dist/api/account-api.js +61 -0
  6. package/dist/api/account-api.js.map +1 -0
  7. package/dist/api/api-client.d.ts +23 -0
  8. package/dist/api/api-client.d.ts.map +1 -0
  9. package/dist/api/api-client.js +129 -0
  10. package/dist/api/api-client.js.map +1 -0
  11. package/dist/api/block-api.d.ts +24 -0
  12. package/dist/api/block-api.d.ts.map +1 -0
  13. package/dist/api/block-api.js +22 -0
  14. package/dist/api/block-api.js.map +1 -0
  15. package/dist/api/candlestick-api.d.ts +27 -0
  16. package/dist/api/candlestick-api.d.ts.map +1 -0
  17. package/dist/api/candlestick-api.js +18 -0
  18. package/dist/api/candlestick-api.js.map +1 -0
  19. package/dist/api/order-api.d.ts +76 -0
  20. package/dist/api/order-api.d.ts.map +1 -0
  21. package/dist/api/order-api.js +102 -0
  22. package/dist/api/order-api.js.map +1 -0
  23. package/dist/api/root-api.d.ts +8 -0
  24. package/dist/api/root-api.d.ts.map +1 -0
  25. package/dist/api/root-api.js +14 -0
  26. package/dist/api/root-api.js.map +1 -0
  27. package/dist/api/transaction-api.d.ts +58 -0
  28. package/dist/api/transaction-api.d.ts.map +1 -0
  29. package/dist/api/transaction-api.js +141 -0
  30. package/dist/api/transaction-api.js.map +1 -0
  31. package/dist/api/ws-client.d.ts +21 -0
  32. package/dist/api/ws-client.d.ts.map +1 -0
  33. package/dist/api/ws-client.js +139 -0
  34. package/dist/api/ws-client.js.map +1 -0
  35. package/dist/index.d.ts +62 -0
  36. package/dist/index.d.ts.map +1 -0
  37. package/dist/index.js +99 -0
  38. package/dist/index.js.map +1 -0
  39. package/dist/signer/signer-client.d.ts +79 -0
  40. package/dist/signer/signer-client.d.ts.map +1 -0
  41. package/dist/signer/signer-client.js +213 -0
  42. package/dist/signer/signer-client.js.map +1 -0
  43. package/dist/signer/wasm-signer-client.d.ts +129 -0
  44. package/dist/signer/wasm-signer-client.d.ts.map +1 -0
  45. package/dist/signer/wasm-signer-client.js +607 -0
  46. package/dist/signer/wasm-signer-client.js.map +1 -0
  47. package/dist/types/index.d.ts +130 -0
  48. package/dist/types/index.d.ts.map +1 -0
  49. package/dist/types/index.js +3 -0
  50. package/dist/types/index.js.map +1 -0
  51. package/dist/utils/api-key-utils.d.ts +7 -0
  52. package/dist/utils/api-key-utils.d.ts.map +1 -0
  53. package/dist/utils/api-key-utils.js +31 -0
  54. package/dist/utils/api-key-utils.js.map +1 -0
  55. package/dist/utils/configuration.d.ts +19 -0
  56. package/dist/utils/configuration.d.ts.map +1 -0
  57. package/dist/utils/configuration.js +55 -0
  58. package/dist/utils/configuration.js.map +1 -0
  59. package/dist/utils/exceptions.d.ts +33 -0
  60. package/dist/utils/exceptions.d.ts.map +1 -0
  61. package/dist/utils/exceptions.js +76 -0
  62. package/dist/utils/exceptions.js.map +1 -0
  63. package/dist/utils/node-wasm-signer.d.ts +126 -0
  64. package/dist/utils/node-wasm-signer.d.ts.map +1 -0
  65. package/dist/utils/node-wasm-signer.js +286 -0
  66. package/dist/utils/node-wasm-signer.js.map +1 -0
  67. package/dist/utils/signer-server.d.ts +18 -0
  68. package/dist/utils/signer-server.d.ts.map +1 -0
  69. package/dist/utils/signer-server.js +79 -0
  70. package/dist/utils/signer-server.js.map +1 -0
  71. package/dist/utils/signer.d.ts +15 -0
  72. package/dist/utils/signer.d.ts.map +1 -0
  73. package/dist/utils/signer.js +68 -0
  74. package/dist/utils/signer.js.map +1 -0
  75. package/dist/utils/wasm-signer.d.ts +130 -0
  76. package/dist/utils/wasm-signer.d.ts.map +1 -0
  77. package/dist/utils/wasm-signer.js +178 -0
  78. package/dist/utils/wasm-signer.js.map +1 -0
  79. package/docs/API.md +195 -0
  80. package/docs/AccountApi.md +220 -0
  81. package/docs/GettingStarted.md +261 -0
  82. package/docs/OrderApi.md +199 -0
  83. package/docs/SignerClient.md +326 -0
  84. package/docs/TransactionApi.md +312 -0
  85. package/docs/WsClient.md +275 -0
  86. package/docs/types/Account.md +67 -0
  87. package/docs/types/ApiKeyPair.md +33 -0
  88. package/docs/types/CreateOrderParams.md +47 -0
  89. package/docs/types/MarketOrderParams.md +36 -0
  90. package/docs/types/SignerConfig.md +40 -0
  91. package/docs/types/WasmSignerConfig.md +30 -0
  92. package/examples/README.md +171 -0
  93. package/examples/account_info.ts +12 -0
  94. package/examples/create_cancel_order.ts +74 -0
  95. package/examples/create_market_order.ts +42 -0
  96. package/examples/create_market_order_max_slippage.ts +43 -0
  97. package/examples/create_sl_tp.ts +61 -0
  98. package/examples/create_with_multiple_keys.ts +58 -0
  99. package/examples/get_info.ts +58 -0
  100. package/examples/send_tx_batch.ts +87 -0
  101. package/examples/system_setup.ts +96 -0
  102. package/examples/transfer_update_leverage.ts +53 -0
  103. package/examples/ws.ts +24 -0
  104. package/examples/ws_async.ts +39 -0
  105. package/examples/ws_send_batch_tx.ts +113 -0
  106. package/examples/ws_send_tx.ts +94 -0
  107. package/package.json +71 -0
  108. package/wasm/lighter-signer.wasm +0 -0
  109. package/wasm/wasm_exec.js +402 -0
  110. package/wasm/wasm_exec_nodejs.js +402 -0
@@ -0,0 +1,326 @@
1
+ # SignerClient
2
+
3
+ The `SignerClient` is the main class for interacting with the Lighter Protocol. It provides high-level methods for creating orders, managing accounts, and performing transactions using a WASM-based signer.
4
+
5
+ ## Constructor
6
+
7
+ ```typescript
8
+ new SignerClient(config: SignerConfig)
9
+ ```
10
+
11
+ ### SignerConfig
12
+
13
+ | Property | Type | Required | Description |
14
+ |----------|------|----------|-------------|
15
+ | `url` | `string` | Yes | The Lighter API URL (e.g., `https://mainnet.zklighter.elliot.ai`) |
16
+ | `privateKey` | `string` | Yes | Your API key private key |
17
+ | `accountIndex` | `number` | Yes | Your account index |
18
+ | `apiKeyIndex` | `number` | Yes | Your API key index |
19
+ | `signerServerUrl` | `string` | No | URL of the signer server (alternative to WASM) |
20
+ | `wasmConfig` | `WasmSignerConfig` | No | Configuration for WASM signer |
21
+
22
+ ## Methods
23
+
24
+ ### initialize()
25
+
26
+ Initializes the signer client. Must be called before using other methods.
27
+
28
+ ```typescript
29
+ await client.initialize();
30
+ ```
31
+
32
+ ### ensureWasmClient()
33
+
34
+ Ensures the WASM client is properly initialized and ready for use.
35
+
36
+ ```typescript
37
+ await client.ensureWasmClient();
38
+ ```
39
+
40
+ ### createOrder(params: CreateOrderParams)
41
+
42
+ Creates a limit order.
43
+
44
+ **Parameters:**
45
+ - `marketIndex: number` - Market index (0 for ETH/USDC)
46
+ - `clientOrderIndex: number` - Unique client order index
47
+ - `baseAmount: number` - Base amount in smallest unit
48
+ - `price: number` - Order price in smallest unit
49
+ - `isAsk: boolean` - True for sell orders, false for buy orders
50
+ - `orderType: number` - Order type (use `SignerClient.ORDER_TYPE_LIMIT`)
51
+ - `timeInForce: number` - Time in force (use `SignerClient.ORDER_TIME_IN_FORCE_*`)
52
+ - `reduceOnly: boolean` - Whether this is a reduce-only order
53
+ - `triggerPrice: number` - Trigger price for conditional orders
54
+ - `orderExpiry: number` - Order expiry timestamp
55
+
56
+ **Returns:** `Promise<[any, string, string | null]>` - `[transaction, txHash, error]`
57
+
58
+ **Example:**
59
+ ```typescript
60
+ const [tx, txHash, err] = await client.createOrder({
61
+ marketIndex: 0,
62
+ clientOrderIndex: Date.now(),
63
+ baseAmount: 1000000, // 1 ETH in smallest unit
64
+ price: 300000000, // $3000 in smallest unit
65
+ isAsk: true,
66
+ orderType: SignerClient.ORDER_TYPE_LIMIT,
67
+ timeInForce: SignerClient.ORDER_TIME_IN_FORCE_GOOD_TILL_TIME,
68
+ reduceOnly: false,
69
+ triggerPrice: SignerClient.NIL_TRIGGER_PRICE,
70
+ orderExpiry: SignerClient.DEFAULT_28_DAY_ORDER_EXPIRY
71
+ });
72
+ ```
73
+
74
+ ### createMarketOrder(params: MarketOrderParams)
75
+
76
+ Creates a market order.
77
+
78
+ **Parameters:**
79
+ - `marketIndex: number` - Market index (0 for ETH/USDC)
80
+ - `clientOrderIndex: number` - Unique client order index
81
+ - `baseAmount: number` - Base amount in smallest unit
82
+ - `avgExecutionPrice: number` - Maximum average execution price
83
+ - `isAsk: boolean` - True for sell orders, false for buy orders
84
+
85
+ **Returns:** `Promise<[any, string, string | null]>` - `[transaction, txHash, error]`
86
+
87
+ **Example:**
88
+ ```typescript
89
+ const [tx, txHash, err] = await client.createMarketOrder({
90
+ marketIndex: 0,
91
+ clientOrderIndex: Date.now(),
92
+ baseAmount: 1000000, // 1 ETH in smallest unit
93
+ avgExecutionPrice: 300000000, // Max $3000 average price
94
+ isAsk: true
95
+ });
96
+ ```
97
+
98
+ ### cancelOrder(params: CancelOrderParams)
99
+
100
+ Cancels an existing order.
101
+
102
+ **Parameters:**
103
+ - `marketIndex: number` - Market index
104
+ - `orderIndex: number` - Order index to cancel
105
+ - `nonce?: number` - Optional nonce (auto-generated if not provided)
106
+
107
+ **Returns:** `Promise<[any, string, string | null]>` - `[transaction, txHash, error]`
108
+
109
+ **Example:**
110
+ ```typescript
111
+ const [tx, txHash, err] = await client.cancelOrder({
112
+ marketIndex: 0,
113
+ orderIndex: 12345
114
+ });
115
+ ```
116
+
117
+ ### cancelAllOrders(timeInForce: number, time: number)
118
+
119
+ Cancels all orders for the account.
120
+
121
+ **Parameters:**
122
+ - `timeInForce: number` - Time in force (use `SignerClient.CANCEL_ALL_TIF_*`)
123
+ - `time: number` - Time parameter
124
+ - `nonce?: number` - Optional nonce (auto-generated if not provided)
125
+
126
+ **Returns:** `Promise<[any, string | null]>` - `[txHash, error]`
127
+
128
+ **Example:**
129
+ ```typescript
130
+ const [txHash, err] = await client.cancelAllOrders(
131
+ SignerClient.CANCEL_ALL_TIF_IMMEDIATE,
132
+ 0
133
+ );
134
+ ```
135
+
136
+ ### transfer(toAccountIndex: number, usdcAmount: number)
137
+
138
+ Transfers USDC between accounts.
139
+
140
+ **Parameters:**
141
+ - `toAccountIndex: number` - Destination account index
142
+ - `usdcAmount: number` - Amount in USDC (will be scaled internally)
143
+ - `nonce?: number` - Optional nonce (auto-generated if not provided)
144
+
145
+ **Returns:** `Promise<[any, string, string | null]>` - `[transaction, txHash, error]`
146
+
147
+ **Example:**
148
+ ```typescript
149
+ const [tx, txHash, err] = await client.transfer(456, 100); // Transfer 100 USDC
150
+ ```
151
+
152
+ ### updateLeverage(marketIndex: number, marginMode: number, initialMarginFraction: number)
153
+
154
+ Updates leverage settings for a market.
155
+
156
+ **Parameters:**
157
+ - `marketIndex: number` - Market index
158
+ - `marginMode: number` - Margin mode (use `SignerClient.CROSS_MARGIN_MODE` or `SignerClient.ISOLATED_MARGIN_MODE`)
159
+ - `initialMarginFraction: number` - Initial margin fraction
160
+ - `nonce?: number` - Optional nonce (auto-generated if not provided)
161
+
162
+ **Returns:** `Promise<[any, string, string | null]>` - `[transaction, txHash, error]`
163
+
164
+ **Example:**
165
+ ```typescript
166
+ const [tx, txHash, err] = await client.updateLeverage(
167
+ 0, // ETH/USDC market
168
+ SignerClient.CROSS_MARGIN_MODE,
169
+ 3 // 3x leverage
170
+ );
171
+ ```
172
+
173
+ ### generateAPIKey(seed?: string)
174
+
175
+ Generates a new API key pair.
176
+
177
+ **Parameters:**
178
+ - `seed?: string` - Optional seed for key generation
179
+
180
+ **Returns:** `Promise<{ privateKey: string; publicKey: string } | null>`
181
+
182
+ **Example:**
183
+ ```typescript
184
+ const apiKey = await client.generateAPIKey();
185
+ if (apiKey) {
186
+ console.log('New API key:', apiKey.privateKey);
187
+ console.log('Public key:', apiKey.publicKey);
188
+ }
189
+ ```
190
+
191
+ ### createAuthTokenWithExpiry(expirySeconds?: number)
192
+
193
+ Creates an authentication token.
194
+
195
+ **Parameters:**
196
+ - `expirySeconds?: number` - Token expiry in seconds (default: 10 minutes)
197
+
198
+ **Returns:** `Promise<string>` - Authentication token
199
+
200
+ **Example:**
201
+ ```typescript
202
+ const token = await client.createAuthTokenWithExpiry(3600); // 1 hour expiry
203
+ ```
204
+
205
+ ### checkClient()
206
+
207
+ Checks if the client is properly configured and connected.
208
+
209
+ **Returns:** `string | null` - Error message if check fails, null if successful
210
+
211
+ **Example:**
212
+ ```typescript
213
+ const error = client.checkClient();
214
+ if (error) {
215
+ console.error('Client check failed:', error);
216
+ }
217
+ ```
218
+
219
+ ### close()
220
+
221
+ Closes the client and cleans up resources.
222
+
223
+ ```typescript
224
+ await client.close();
225
+ ```
226
+
227
+ ## Constants
228
+
229
+ ### Order Types
230
+ - `ORDER_TYPE_LIMIT = 0` - Limit order
231
+ - `ORDER_TYPE_MARKET = 1` - Market order
232
+
233
+ ### Time in Force
234
+ - `ORDER_TIME_IN_FORCE_IMMEDIATE_OR_CANCEL = 0` - Immediate or Cancel
235
+ - `ORDER_TIME_IN_FORCE_GOOD_TILL_TIME = 1` - Good Till Time
236
+ - `ORDER_TIME_IN_FORCE_FILL_OR_KILL = 2` - Fill or Kill
237
+
238
+ ### Cancel All Orders Time in Force
239
+ - `CANCEL_ALL_TIF_IMMEDIATE = 0` - Immediate cancellation
240
+ - `CANCEL_ALL_TIF_SCHEDULED = 1` - Scheduled cancellation
241
+ - `CANCEL_ALL_TIF_ABORT = 2` - Abort cancellation
242
+
243
+ ### Margin Modes
244
+ - `CROSS_MARGIN_MODE = 0` - Cross margin mode
245
+ - `ISOLATED_MARGIN_MODE = 1` - Isolated margin mode
246
+
247
+ ### Transaction Types
248
+ - `TX_TYPE_CREATE_ORDER = 1` - Create order transaction
249
+ - `TX_TYPE_CANCEL_ORDER = 2` - Cancel order transaction
250
+ - `TX_TYPE_CANCEL_ALL_ORDERS = 3` - Cancel all orders transaction
251
+ - `TX_TYPE_TRANSFER = 4` - Transfer transaction
252
+ - `TX_TYPE_UPDATE_LEVERAGE = 20` - Update leverage transaction
253
+
254
+ ### Other Constants
255
+ - `NIL_TRIGGER_PRICE = 0` - No trigger price
256
+ - `DEFAULT_28_DAY_ORDER_EXPIRY = -1` - Default 28-day expiry
257
+ - `DEFAULT_IOC_EXPIRY = 0` - Default IOC expiry
258
+ - `DEFAULT_10_MIN_AUTH_EXPIRY = -1` - Default auth expiry
259
+ - `MINUTE = 60` - Seconds in a minute
260
+ - `USDC_TICKER_SCALE = 1e6` - USDC scaling factor
261
+
262
+ ## Error Handling
263
+
264
+ All methods return a tuple where the last element is an error string if something goes wrong:
265
+
266
+ ```typescript
267
+ const [tx, txHash, err] = await client.createOrder(params);
268
+ if (err) {
269
+ console.error('Order creation failed:', err);
270
+ return;
271
+ }
272
+ console.log('Order created successfully:', txHash);
273
+ ```
274
+
275
+ ## Complete Example
276
+
277
+ ```typescript
278
+ import { SignerClient } from '@lighter/typescript-sdk';
279
+
280
+ async function main() {
281
+ const client = new SignerClient({
282
+ url: 'https://mainnet.zklighter.elliot.ai',
283
+ privateKey: 'your-api-key-private-key',
284
+ accountIndex: 123,
285
+ apiKeyIndex: 0,
286
+ wasmConfig: { wasmPath: 'wasm/lighter-signer.wasm' }
287
+ });
288
+
289
+ try {
290
+ await client.initialize();
291
+ await client.ensureWasmClient();
292
+
293
+ // Check client status
294
+ const checkError = client.checkClient();
295
+ if (checkError) {
296
+ throw new Error(`Client check failed: ${checkError}`);
297
+ }
298
+
299
+ // Create a limit order
300
+ const [tx, txHash, err] = await client.createOrder({
301
+ marketIndex: 0,
302
+ clientOrderIndex: Date.now(),
303
+ baseAmount: 1000000,
304
+ price: 300000000,
305
+ isAsk: true,
306
+ orderType: SignerClient.ORDER_TYPE_LIMIT,
307
+ timeInForce: SignerClient.ORDER_TIME_IN_FORCE_GOOD_TILL_TIME,
308
+ reduceOnly: false,
309
+ triggerPrice: SignerClient.NIL_TRIGGER_PRICE,
310
+ orderExpiry: SignerClient.DEFAULT_28_DAY_ORDER_EXPIRY
311
+ });
312
+
313
+ if (err) {
314
+ console.error('Order creation failed:', err);
315
+ return;
316
+ }
317
+
318
+ console.log('Order created successfully:', txHash);
319
+
320
+ } finally {
321
+ await client.close();
322
+ }
323
+ }
324
+
325
+ main().catch(console.error);
326
+ ```
@@ -0,0 +1,312 @@
1
+ # TransactionApi
2
+
3
+ The `TransactionApi` class provides methods for retrieving transaction data, managing nonces, and sending transactions.
4
+
5
+ ## Constructor
6
+
7
+ ```typescript
8
+ new TransactionApi(client: ApiClient)
9
+ ```
10
+
11
+ ## Methods
12
+
13
+ ### getTransaction(params: TransactionParams)
14
+
15
+ Gets a specific transaction by hash or other identifier.
16
+
17
+ **Parameters:**
18
+ - `by: 'hash' | 'l1_tx_hash'` - Search by transaction hash or L1 transaction hash
19
+ - `value: string` - The transaction hash value
20
+
21
+ **Returns:** `Promise<Transaction>` - Transaction information
22
+
23
+ **Example:**
24
+ ```typescript
25
+ const transactionApi = new TransactionApi(client);
26
+
27
+ // Get transaction by hash
28
+ const tx = await transactionApi.getTransaction({
29
+ by: 'hash',
30
+ value: '0x1234567890abcdef...'
31
+ });
32
+
33
+ // Get transaction by L1 hash
34
+ const tx = await transactionApi.getTransaction({
35
+ by: 'l1_tx_hash',
36
+ value: '0xabcdef1234567890...'
37
+ });
38
+ ```
39
+
40
+ ### getTransactions(params?: PaginationParams)
41
+
42
+ Gets a list of transactions with pagination.
43
+
44
+ **Parameters:**
45
+ - `limit?: number` - Maximum number of transactions to return
46
+ - `index?: number` - Starting index for pagination
47
+
48
+ **Returns:** `Promise<Transaction[]>` - Array of transactions
49
+
50
+ **Example:**
51
+ ```typescript
52
+ const transactions = await transactionApi.getTransactions({
53
+ limit: 50,
54
+ index: 0
55
+ });
56
+ console.log(`Found ${transactions.length} transactions`);
57
+ ```
58
+
59
+ ### getBlockTransactions(params: BlockParams & PaginationParams)
60
+
61
+ Gets transactions for a specific block.
62
+
63
+ **Parameters:**
64
+ - `by: 'height' | 'hash'` - Search by block height or hash
65
+ - `value: string` - The block height or hash value
66
+ - `limit?: number` - Maximum number of transactions to return
67
+ - `index?: number` - Starting index for pagination
68
+
69
+ **Returns:** `Promise<Transaction[]>` - Array of block transactions
70
+
71
+ **Example:**
72
+ ```typescript
73
+ const blockTxs = await transactionApi.getBlockTransactions({
74
+ by: 'height',
75
+ value: '100',
76
+ limit: 20
77
+ });
78
+ console.log(`Found ${blockTxs.length} transactions in block 100`);
79
+ ```
80
+
81
+ ### getAccountTransactions(accountIndex: number, params?: PaginationParams)
82
+
83
+ Gets transactions for a specific account.
84
+
85
+ **Parameters:**
86
+ - `accountIndex: number` - Account index
87
+ - `limit?: number` - Maximum number of transactions to return
88
+ - `index?: number` - Starting index for pagination
89
+
90
+ **Returns:** `Promise<Transaction[]>` - Array of account transactions
91
+
92
+ **Example:**
93
+ ```typescript
94
+ const accountTxs = await transactionApi.getAccountTransactions(123, {
95
+ limit: 100
96
+ });
97
+ console.log(`Found ${accountTxs.length} transactions for account 123`);
98
+ ```
99
+
100
+ ### getNextNonce(accountIndex: number, apiKeyIndex: number)
101
+
102
+ Gets the next nonce for an account and API key combination.
103
+
104
+ **Parameters:**
105
+ - `accountIndex: number` - Account index
106
+ - `apiKeyIndex: number` - API key index
107
+
108
+ **Returns:** `Promise<NextNonce>` - Next nonce information
109
+
110
+ **Example:**
111
+ ```typescript
112
+ const nextNonce = await transactionApi.getNextNonce(123, 0);
113
+ console.log('Next nonce:', nextNonce.nonce);
114
+ ```
115
+
116
+ ### sendTx(txType: number, txInfo: string)
117
+
118
+ Sends a transaction to the network.
119
+
120
+ **Parameters:**
121
+ - `txType: number` - Transaction type (use `SignerClient.TX_TYPE_*` constants)
122
+ - `txInfo: string` - Transaction information as JSON string
123
+
124
+ **Returns:** `Promise<TxHash>` - Transaction hash
125
+
126
+ **Example:**
127
+ ```typescript
128
+ const txHash = await transactionApi.sendTx(
129
+ SignerClient.TX_TYPE_CREATE_ORDER,
130
+ JSON.stringify(orderData)
131
+ );
132
+ console.log('Transaction sent:', txHash.hash);
133
+ ```
134
+
135
+ ### sendTxWithIndices(txType: number, txInfo: string, accountIndex: number, apiKeyIndex: number)
136
+
137
+ Sends a transaction with account and API key indices.
138
+
139
+ **Parameters:**
140
+ - `txType: number` - Transaction type
141
+ - `txInfo: string` - Transaction information as JSON string
142
+ - `accountIndex: number` - Account index
143
+ - `apiKeyIndex: number` - API key index
144
+
145
+ **Returns:** `Promise<TxHash>` - Transaction hash
146
+
147
+ **Example:**
148
+ ```typescript
149
+ const txHash = await transactionApi.sendTxWithIndices(
150
+ SignerClient.TX_TYPE_CREATE_ORDER,
151
+ JSON.stringify(orderData),
152
+ 123,
153
+ 0
154
+ );
155
+ console.log('Transaction sent:', txHash.hash);
156
+ ```
157
+
158
+ ### sendTxBatch(txHashes: string[])
159
+
160
+ Sends multiple transactions in a batch.
161
+
162
+ **Parameters:**
163
+ - `txHashes: string[]` - Array of transaction hashes
164
+
165
+ **Returns:** `Promise<TxHashes>` - Batch transaction hashes
166
+
167
+ **Example:**
168
+ ```typescript
169
+ const batchHashes = await transactionApi.sendTxBatch([
170
+ '0xhash1...',
171
+ '0xhash2...',
172
+ '0xhash3...'
173
+ ]);
174
+ console.log('Batch sent:', batchHashes.hashes);
175
+ ```
176
+
177
+ ## Types
178
+
179
+ ### TransactionParams
180
+
181
+ ```typescript
182
+ interface TransactionParams {
183
+ by: 'hash' | 'l1_tx_hash';
184
+ value: string;
185
+ }
186
+ ```
187
+
188
+ ### BlockParams
189
+
190
+ ```typescript
191
+ interface BlockParams {
192
+ by: 'height' | 'hash';
193
+ value: string;
194
+ }
195
+ ```
196
+
197
+ ### PaginationParams
198
+
199
+ ```typescript
200
+ interface PaginationParams {
201
+ limit?: number;
202
+ index?: number;
203
+ }
204
+ ```
205
+
206
+ ### Transaction
207
+
208
+ ```typescript
209
+ interface Transaction {
210
+ hash: string;
211
+ type: number;
212
+ info: string;
213
+ status: number;
214
+ block_height: number;
215
+ account_index: number;
216
+ nonce: number;
217
+ // ... other transaction properties
218
+ }
219
+ ```
220
+
221
+ ### NextNonce
222
+
223
+ ```typescript
224
+ interface NextNonce {
225
+ nonce: number;
226
+ }
227
+ ```
228
+
229
+ ### TxHash
230
+
231
+ ```typescript
232
+ interface TxHash {
233
+ hash: string;
234
+ }
235
+ ```
236
+
237
+ ### TxHashes
238
+
239
+ ```typescript
240
+ interface TxHashes {
241
+ hashes: string[];
242
+ }
243
+ ```
244
+
245
+ ## Error Handling
246
+
247
+ All methods throw errors for invalid parameters or network issues:
248
+
249
+ ```typescript
250
+ try {
251
+ const tx = await transactionApi.getTransaction({
252
+ by: 'hash',
253
+ value: '0x123...'
254
+ });
255
+ console.log('Transaction:', tx);
256
+ } catch (error) {
257
+ console.error('Failed to get transaction:', error.message);
258
+ }
259
+ ```
260
+
261
+ ## Complete Example
262
+
263
+ ```typescript
264
+ import { ApiClient, TransactionApi, SignerClient } from '@lighter/typescript-sdk';
265
+
266
+ async function main() {
267
+ const client = new ApiClient({ host: 'https://mainnet.zklighter.elliot.ai' });
268
+ const transactionApi = new TransactionApi(client);
269
+
270
+ try {
271
+ // Get recent transactions
272
+ const transactions = await transactionApi.getTransactions({
273
+ limit: 20
274
+ });
275
+ console.log(`Found ${transactions.length} recent transactions`);
276
+
277
+ // Get transactions for a specific block
278
+ const blockTxs = await transactionApi.getBlockTransactions({
279
+ by: 'height',
280
+ value: '100',
281
+ limit: 10
282
+ });
283
+ console.log(`Found ${blockTxs.length} transactions in block 100`);
284
+
285
+ // Get account transactions
286
+ const accountTxs = await transactionApi.getAccountTransactions(123, {
287
+ limit: 50
288
+ });
289
+ console.log(`Found ${accountTxs.length} transactions for account 123`);
290
+
291
+ // Get next nonce
292
+ const nextNonce = await transactionApi.getNextNonce(123, 0);
293
+ console.log('Next nonce:', nextNonce.nonce);
294
+
295
+ // Get specific transaction
296
+ if (transactions.length > 0) {
297
+ const tx = await transactionApi.getTransaction({
298
+ by: 'hash',
299
+ value: transactions[0].hash
300
+ });
301
+ console.log('Transaction details:', tx);
302
+ }
303
+
304
+ } catch (error) {
305
+ console.error('Error:', error.message);
306
+ } finally {
307
+ await client.close();
308
+ }
309
+ }
310
+
311
+ main().catch(console.error);
312
+ ```