starknet 4.5.0 → 4.6.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.
@@ -1,9 +1,11 @@
1
1
  /**
2
2
  * Starknet RPC version 0.1.0
3
- * starknet_api_openrpc version 0.31.0
4
3
  *
5
- * TypeScript Representation of OpenRpc protocol types | results
6
- * errors are not implemented here only results
4
+ * StarkNet Node API 0.31.0
5
+ * StarkNet Node Write API 0.3.0
6
+ * StarkNet Trace API 0.3.0
7
+ *
8
+ * TypeScript Representation of OpenRpc protocol types
7
9
  */
8
10
 
9
11
  /**
@@ -13,12 +15,28 @@
13
15
  * "description": "A field element. Represented as up to 63 hex digits and leading 4 bits zeroed.",
14
16
  * "pattern": "^0x0[a-fA-F0-9]{1,63}$"
15
17
  */
16
- type FELT = string;
18
+ export type FELT = string;
19
+ export type ADDRESS = FELT;
20
+ /**
21
+ * "title": "An integer number in hex format (0x...)",
22
+ * "pattern": "^0x[a-fA-F0-9]+$"
23
+ */
24
+ type NUM_AS_HEX = string;
25
+ type SIGNATURE = Array<FELT>;
26
+ type ETH_ADDRESS = string;
17
27
  type BLOCK_NUMBER = number;
18
28
  type BLOCK_HASH = FELT;
19
29
  type TXN_HASH = FELT;
30
+ type CHAIN_ID = string;
31
+ type PROTOCOL_VERSION = string;
20
32
  type TXN_STATUS = 'PENDING' | 'ACCEPTED_ON_L2' | 'ACCEPTED_ON_L1' | 'REJECTED';
21
33
  type TXN_TYPE = 'DECLARE' | 'DEPLOY' | 'INVOKE' | 'L1_HANDLER';
34
+ type BLOCK_STATUS = 'PENDING' | 'ACCEPTED_ON_L2' | 'ACCEPTED_ON_L1' | 'REJECTED';
35
+ enum BLOCK_TAG {
36
+ 'latest',
37
+ 'pending',
38
+ }
39
+ type BLOCK_ID = { block_hash: BLOCK_HASH } | { block_number: BLOCK_NUMBER } | BLOCK_TAG;
22
40
  type MSG_TO_L1 = {
23
41
  to_address: FELT;
24
42
  payload: Array<FELT>;
@@ -32,45 +50,34 @@ type COMMON_RECEIPT_PROPERTIES = {
32
50
  transaction_hash: TXN_HASH;
33
51
  actual_fee: FELT;
34
52
  status: TXN_STATUS;
53
+ status_data?: string;
35
54
  block_hash: BLOCK_HASH;
36
55
  block_number: BLOCK_NUMBER;
37
- type?: TXN_TYPE;
56
+ };
57
+ type MSG_TO_L2 = {
58
+ from_address: ETH_ADDRESS;
59
+ payload: FELT;
38
60
  };
39
61
  type INVOKE_TXN_RECEIPT_PROPERTIES = {
40
62
  messages_sent: MSG_TO_L1;
63
+ l1_origin_message?: MSG_TO_L2;
41
64
  events: EVENT;
42
65
  };
43
66
  type PENDING_COMMON_RECEIPT_PROPERTIES = {
44
67
  transaction_hash: TXN_HASH;
45
68
  actual_fee: FELT;
46
- type?: TXN_TYPE;
47
69
  };
48
70
  type INVOKE_TXN_RECEIPT = COMMON_RECEIPT_PROPERTIES & INVOKE_TXN_RECEIPT_PROPERTIES;
49
- type L1_HANDLER_TXN_RECEIPT = COMMON_RECEIPT_PROPERTIES;
71
+ // type L1_HANDLER_TXN_RECEIPT = COMMON_RECEIPT_PROPERTIES;
50
72
  type DECLARE_TXN_RECEIPT = COMMON_RECEIPT_PROPERTIES;
51
73
  type DEPLOY_TXN_RECEIPT = COMMON_RECEIPT_PROPERTIES;
52
74
  type PENDING_INVOKE_TXN_RECEIPT = PENDING_COMMON_RECEIPT_PROPERTIES & INVOKE_TXN_RECEIPT_PROPERTIES;
53
75
  type PENDING_TXN_RECEIPT = PENDING_INVOKE_TXN_RECEIPT | PENDING_COMMON_RECEIPT_PROPERTIES;
54
76
  type TXN_RECEIPT =
55
77
  | INVOKE_TXN_RECEIPT
56
- | L1_HANDLER_TXN_RECEIPT
57
78
  | DECLARE_TXN_RECEIPT
58
79
  | DEPLOY_TXN_RECEIPT
59
80
  | PENDING_TXN_RECEIPT;
60
-
61
- export namespace RPC_1 {
62
- export type GetTransactionReceiptResponse = TXN_RECEIPT;
63
-
64
- export type Methods = {
65
- starknet_getTransactionReceipt: {
66
- QUERY: never;
67
- REQUEST: any[];
68
- RESPONSE: GetTransactionReceiptResponse;
69
- };
70
- };
71
- }
72
-
73
- // starknet_getBlockWithTxHashes
74
81
  type BLOCK_HEADER = {
75
82
  block_hash: BLOCK_HASH;
76
83
  parent_hash: BLOCK_HASH;
@@ -91,15 +98,6 @@ type PENDING_BLOCK_WITH_TX_HASHES = BLOCK_BODY_WITH_TX_HASHES & {
91
98
  sequencer_address: FELT;
92
99
  parent_hash: BLOCK_HASH;
93
100
  };
94
-
95
- // starknet_getBlockWithTx
96
- type BLOCK_STATUS = 'PENDING' | 'ACCEPTED_ON_L2' | 'ACCEPTED_ON_L1' | 'REJECTED';
97
- /**
98
- * "title": "An integer number in hex format (0x...)",
99
- * "pattern": "^0x[a-fA-F0-9]+$"
100
- */
101
- type NUM_AS_HEX = string;
102
- type SIGNATURE = Array<FELT>;
103
101
  type COMMON_TXN_PROPERTIES = {
104
102
  transaction_hash: TXN_HASH;
105
103
  max_fee: FELT;
@@ -108,7 +106,6 @@ type COMMON_TXN_PROPERTIES = {
108
106
  nonce: FELT;
109
107
  type: TXN_TYPE;
110
108
  };
111
- type ADDRESS = FELT;
112
109
  type FUNCTION_CALL = {
113
110
  contract_address: ADDRESS;
114
111
  entry_point_selector: FELT;
@@ -136,13 +133,11 @@ type BLOCK_WITH_TXS = {
136
133
  status: BLOCK_STATUS;
137
134
  } & BLOCK_HEADER &
138
135
  BLOCK_BODY_WITH_TXS;
139
-
140
136
  type PENDING_BLOCK_WITH_TXS = BLOCK_BODY_WITH_TXS & {
141
137
  timestamp: number;
142
138
  sequencer_address: FELT;
143
139
  parent_hash: BLOCK_HASH;
144
140
  };
145
-
146
141
  type CONTRACT_CLASS = {
147
142
  program: string; // A base64 representation of the compressed program code
148
143
  entry_points_by_type: {
@@ -150,19 +145,354 @@ type CONTRACT_CLASS = {
150
145
  EXTERNAL: CONTRACT_ENTRY_POINT_LIST;
151
146
  L1_HANDLER: CONTRACT_ENTRY_POINT_LIST;
152
147
  };
148
+ abi?: any; // Pathfinder exception from rpc 0.1.0
153
149
  };
154
-
155
150
  type CONTRACT_ENTRY_POINT_LIST = Array<CONTRACT_ENTRY_POINT>;
156
151
  type CONTRACT_ENTRY_POINT = {
157
152
  offset: NUM_AS_HEX;
158
153
  selector: FELT;
159
154
  };
155
+ type STORAGE_DIFF_ITEM = {
156
+ address: FELT;
157
+ key: FELT;
158
+ value: FELT;
159
+ };
160
+ type DECLARED_CONTRACT_ITEM = {
161
+ class_hash: FELT;
162
+ };
163
+ type DEPLOYED_CONTRACT_ITEM = {
164
+ address: FELT;
165
+ class_hash: FELT;
166
+ };
167
+ type STATE_UPDATE = {
168
+ block_hash: BLOCK_HASH;
169
+ new_root: FELT;
170
+ old_root: FELT;
171
+ state_diff: {
172
+ storage_diffs: Array<STORAGE_DIFF_ITEM>;
173
+ declared_contracts: Array<DECLARED_CONTRACT_ITEM>;
174
+ deployed_contracts: Array<DEPLOYED_CONTRACT_ITEM>;
175
+ nonces: Array<{
176
+ contract_address: ADDRESS;
177
+ nonce: FELT;
178
+ }>;
179
+ };
180
+ };
181
+ type STORAGE_KEY = string;
182
+ type EVENT_FILTER = {
183
+ from_block?: BLOCK_ID;
184
+ to_block?: BLOCK_ID;
185
+ address?: ADDRESS;
186
+ keys?: Array<FELT>;
187
+ };
188
+ type RESULT_PAGE_REQUEST = {
189
+ page_size: number;
190
+ page_number: number;
191
+ };
192
+ type EMITTED_EVENT = EVENT & {
193
+ block_hash: BLOCK_HASH;
194
+ block_number: BLOCK_NUMBER;
195
+ transaction_hash: TXN_HASH;
196
+ };
197
+ type SYNC_STATUS = {
198
+ starting_block_hash: BLOCK_HASH;
199
+ starting_block_num: NUM_AS_HEX;
200
+ current_block_hash: BLOCK_HASH;
201
+ current_block_num: NUM_AS_HEX;
202
+ highest_block_hash: BLOCK_HASH;
203
+ highest_block_num: NUM_AS_HEX;
204
+ };
205
+ type FEE_ESTIMATE = {
206
+ gas_consumed: NUM_AS_HEX;
207
+ gas_price: NUM_AS_HEX;
208
+ overall_fee: NUM_AS_HEX;
209
+ };
210
+
211
+ enum CALL_TYPE {
212
+ 'DELEGATE',
213
+ 'CALL',
214
+ }
215
+ enum ENTRY_POINT_TYPE {
216
+ 'EXTERNAL',
217
+ 'L1_HANDLER',
218
+ 'CONSTRUCTOR',
219
+ }
220
+ type FUNCTION_INVOCATION = FUNCTION_CALL & {
221
+ caller_address: FELT;
222
+ code_address: FELT;
223
+ entry_point_type: ENTRY_POINT_TYPE;
224
+ call_type: CALL_TYPE;
225
+ result: FELT;
226
+ calls: FUNCTION_INVOCATION;
227
+ events: EVENT;
228
+ messages: MSG_TO_L1;
229
+ };
230
+ type TRACE_ROOT = {
231
+ nonce: FELT;
232
+ signature: FELT;
233
+ function_invocation: FUNCTION_INVOCATION;
234
+ };
160
235
 
161
236
  export namespace OPENRPC {
162
- export type GetBlockWithTxHashesResponse = BLOCK_WITH_TX_HASHES | PENDING_BLOCK_WITH_TX_HASHES;
163
- export type GetBlockWithTxs = BLOCK_WITH_TXS | PENDING_BLOCK_WITH_TXS;
164
- export type GetStorageAtResponse = FELT;
165
- export type GetTransactionByHashResponse = TXN;
166
- export type GetTransactionByBlockIdAndIndex = TXN;
167
- export type GetClassResponse = CONTRACT_CLASS;
237
+ export type BlockWithTxHashes = BLOCK_WITH_TX_HASHES | PENDING_BLOCK_WITH_TX_HASHES;
238
+ export type BlockWithTxs = BLOCK_WITH_TXS | PENDING_BLOCK_WITH_TXS;
239
+ export type StateUpdate = STATE_UPDATE;
240
+ export type Storage = FELT;
241
+ export type Transaction = TXN;
242
+ export type TransactionReceipt = TXN_RECEIPT;
243
+ export type ContractClass = CONTRACT_CLASS;
244
+ export type CallResponse = Array<FELT>;
245
+ export type EstimatedFee = FEE_ESTIMATE;
246
+ export type BlockNumber = BLOCK_NUMBER;
247
+ export type BlockHashAndNumber = {
248
+ block_hash: BLOCK_HASH;
249
+ block_number: BLOCK_NUMBER;
250
+ };
251
+ export type ChainId = CHAIN_ID;
252
+ export type PendingTransactions = Array<TXN>;
253
+ export type ProtocolVersion = PROTOCOL_VERSION;
254
+ export type SyncingStatus = false | SYNC_STATUS;
255
+ export type Events = {
256
+ events: Array<EMITTED_EVENT>;
257
+ page_number: number;
258
+ is_last_page: boolean;
259
+ };
260
+ export type Nonce = FELT;
261
+ export type Trace = TRACE_ROOT;
262
+ export type Traces = Array<{
263
+ transaction_hash: FELT;
264
+ trace_root: TRACE_ROOT;
265
+ }>;
266
+ export type TransactionHash = TXN_HASH;
267
+ export type BlockHash = BLOCK_HASH;
268
+ export type EventFilter = EVENT_FILTER;
269
+ export type InvokedTransaction = { transaction_hash: TXN_HASH };
270
+ export type DeclaredTransaction = { transaction_hash: TXN_HASH; class_hash: FELT };
271
+ export type DeployedTransaction = { transaction_hash: TXN_HASH; contract_address: FELT };
272
+
273
+ // Final Methods
274
+ export type Methods = {
275
+ // Read API
276
+ starknet_getBlockWithTxHashes: {
277
+ params: { block_id: BLOCK_ID };
278
+ result: BlockWithTxHashes;
279
+ errors: Errors.INVALID_BLOCK_ID;
280
+ };
281
+ starknet_getBlockWithTxs: {
282
+ params: { block_id: BLOCK_ID };
283
+ result: BlockWithTxs;
284
+ errors: Errors.INVALID_BLOCK_ID;
285
+ };
286
+ starknet_getStateUpdate: {
287
+ params: { block_id: BLOCK_ID };
288
+ result: StateUpdate;
289
+ errors: Errors.INVALID_BLOCK_ID;
290
+ };
291
+ starknet_getStorageAt: {
292
+ params: { contract_address: ADDRESS; key: STORAGE_KEY; block_id: BLOCK_ID };
293
+ result: Storage;
294
+ errors: Errors.CONTRACT_NOT_FOUND | Errors.INVALID_BLOCK_ID;
295
+ };
296
+ starknet_getTransactionByHash: {
297
+ params: { transaction_hash: TXN_HASH };
298
+ result: Transaction;
299
+ errors: Errors.INVALID_TXN_HASH;
300
+ };
301
+ starknet_getTransactionByBlockIdAndIndex: {
302
+ params: { block_id: BLOCK_ID; index: number };
303
+ result: Transaction;
304
+ errors: Errors.INVALID_BLOCK_ID | Errors.INVALID_TXN_INDEX;
305
+ };
306
+ starknet_getTransactionReceipt: {
307
+ params: { transaction_hash: TXN_HASH };
308
+ result: TransactionReceipt;
309
+ errors: Errors.INVALID_TXN_HASH;
310
+ };
311
+ starknet_getClass: {
312
+ params: { class_hash: FELT };
313
+ result: ContractClass;
314
+ errors: Errors.INVALID_CONTRACT_CLASS_HASH;
315
+ };
316
+ starknet_getClassHashAt: {
317
+ params: { block_id: BLOCK_ID; contract_address: ADDRESS };
318
+ result: FELT;
319
+ errors: Errors.INVALID_BLOCK_ID | Errors.CONTRACT_NOT_FOUND;
320
+ };
321
+ starknet_getClassAt: {
322
+ params: { block_id: BLOCK_ID; contract_address: ADDRESS };
323
+ result: ContractClass;
324
+ errors: Errors.INVALID_BLOCK_ID | Errors.CONTRACT_NOT_FOUND;
325
+ };
326
+ starknet_getBlockTransactionCount: {
327
+ params: { block_id: BLOCK_ID };
328
+ result: number;
329
+ errors: Errors.INVALID_BLOCK_ID;
330
+ };
331
+ starknet_call: {
332
+ params: { request: FUNCTION_CALL; block_id: BLOCK_ID };
333
+ result: Array<FELT>;
334
+ errors:
335
+ | Errors.CONTRACT_NOT_FOUND
336
+ | Errors.INVALID_MESSAGE_SELECTOR
337
+ | Errors.INVALID_CALL_DATA
338
+ | Errors.CONTRACT_ERROR
339
+ | Errors.INVALID_BLOCK_ID;
340
+ };
341
+ starknet_estimateFee: {
342
+ params: { request: INVOKE_TXN; block_id: BLOCK_ID };
343
+ result: FEE_ESTIMATE;
344
+ errors:
345
+ | Errors.CONTRACT_NOT_FOUND
346
+ | Errors.INVALID_MESSAGE_SELECTOR
347
+ | Errors.INVALID_CALL_DATA
348
+ | Errors.CONTRACT_ERROR
349
+ | Errors.INVALID_BLOCK_ID;
350
+ };
351
+ starknet_blockNumber: {
352
+ result: BLOCK_NUMBER;
353
+ errors: Errors.NO_BLOCKS;
354
+ };
355
+ starknet_blockHashAndNumber: {
356
+ result: BLOCK_HASH & BLOCK_NUMBER;
357
+ errors: Errors.NO_BLOCKS;
358
+ };
359
+ starknet_chainId: {
360
+ result: CHAIN_ID;
361
+ };
362
+ starknet_pendingTransactions: {
363
+ result: PendingTransactions;
364
+ };
365
+ starknet_syncing: {
366
+ result: SyncingStatus;
367
+ };
368
+ starknet_getEvents: {
369
+ params: { filter: EVENT_FILTER & RESULT_PAGE_REQUEST };
370
+ result: { events: EMITTED_EVENT; page_number: number; is_last_page: boolean };
371
+ errors: Errors.PAGE_SIZE_TOO_BIG;
372
+ };
373
+ starknet_getNonce: {
374
+ params: { contract_address: ADDRESS };
375
+ result: FELT;
376
+ errors: Errors.CONTRACT_NOT_FOUND;
377
+ };
378
+
379
+ // Write API
380
+ starknet_addInvokeTransaction: {
381
+ params: {
382
+ function_invocation: FUNCTION_CALL;
383
+ signature: SIGNATURE;
384
+ max_fee: NUM_AS_HEX;
385
+ version: NUM_AS_HEX;
386
+ };
387
+ result: InvokedTransaction;
388
+ };
389
+ starknet_addDeclareTransaction: {
390
+ params: {
391
+ contract_class: CONTRACT_CLASS;
392
+ version: NUM_AS_HEX;
393
+ };
394
+ result: DeclaredTransaction;
395
+ errors: Errors.INVALID_CONTRACT_CLASS;
396
+ };
397
+ starknet_addDeployTransaction: {
398
+ params: {
399
+ contract_address_salt: FELT;
400
+ constructor_calldata: FELT;
401
+ contract_definition: CONTRACT_CLASS;
402
+ };
403
+ result: DeployedTransaction;
404
+ errors: Errors.INVALID_CONTRACT_CLASS;
405
+ };
406
+
407
+ // Trace API
408
+ starknet_traceTransaction: {
409
+ params: { transaction_hash: TXN_HASH };
410
+ result: Trace;
411
+ errors:
412
+ | Errors.INVALID_TXN_HASH
413
+ | Errors.NO_TRACE_AVAILABLE
414
+ | Errors.INVALID_BLOCK_HASH
415
+ | Errors.INVALID_TXN_HASH;
416
+ };
417
+ starknet_traceBlockTransactions: {
418
+ params: { block_hash: BLOCK_HASH };
419
+ result: Traces;
420
+ errors: Errors.INVALID_BLOCK_HASH;
421
+ };
422
+ };
423
+ }
424
+
425
+ export namespace Errors {
426
+ export interface FAILED_TO_RECEIVE_TXN {
427
+ code: 1;
428
+ message: 'Failed to write transaction';
429
+ }
430
+
431
+ export interface CONTRACT_NOT_FOUND {
432
+ code: 20;
433
+ message: 'Contract not found';
434
+ }
435
+
436
+ export interface INVALID_MESSAGE_SELECTOR {
437
+ code: 21;
438
+ message: 'Invalid message selector';
439
+ }
440
+
441
+ export interface INVALID_CALL_DATA {
442
+ code: 22;
443
+ message: 'Invalid call data';
444
+ }
445
+
446
+ export interface INVALID_BLOCK_ID {
447
+ code: 24;
448
+ message: 'Invalid block id';
449
+ }
450
+
451
+ export interface INVALID_TXN_INDEX {
452
+ code: 27;
453
+ message: 'Invalid transaction index in a block';
454
+ }
455
+
456
+ export interface INVALID_CONTRACT_CLASS_HASH {
457
+ code: 28;
458
+ message: 'The supplied contract class hash is invalid or unknown';
459
+ }
460
+
461
+ export interface PAGE_SIZE_TOO_BIG {
462
+ code: 31;
463
+ message: 'Requested page size is too big';
464
+ }
465
+
466
+ export interface NO_BLOCKS {
467
+ code: 32;
468
+ message: 'There are no blocks';
469
+ }
470
+
471
+ export interface CONTRACT_ERROR {
472
+ code: 40;
473
+ message: 'Contract error';
474
+ }
475
+
476
+ export interface INVALID_CONTRACT_CLASS {
477
+ code: 50;
478
+ message: 'Invalid contract class';
479
+ }
480
+
481
+ export interface NO_TRACE_AVAILABLE {
482
+ code: 10;
483
+ message: 'No trace available for transaction';
484
+ data: {
485
+ status: 'RECEIVED' | 'REJECTED';
486
+ };
487
+ }
488
+
489
+ export interface INVALID_BLOCK_HASH {
490
+ code: 24;
491
+ message: 'Invalid block hash';
492
+ }
493
+
494
+ export interface INVALID_TXN_HASH {
495
+ code: 25;
496
+ message: 'Invalid transaction hash';
497
+ }
168
498
  }