starknet 4.7.0 → 4.9.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 (95) hide show
  1. package/CHANGELOG.md +43 -0
  2. package/CONTRIBUTING.md +2 -2
  3. package/__mocks__/ERC20.json +32561 -29055
  4. package/__mocks__/l1l2_compiled.json +10107 -0
  5. package/__tests__/account.test.ts +32 -24
  6. package/__tests__/contract.test.ts +25 -14
  7. package/__tests__/defaultProvider.test.ts +19 -49
  8. package/__tests__/fixtures.ts +11 -1
  9. package/__tests__/rpcProvider.test.ts +6 -15
  10. package/__tests__/sequencerProvider.test.ts +57 -11
  11. package/__tests__/utils/merkle.test.ts +113 -3
  12. package/__tests__/utils/typedData.test.ts +3 -3
  13. package/account/default.d.ts +10 -44
  14. package/account/default.js +255 -61
  15. package/account/interface.d.ts +78 -7
  16. package/constants.d.ts +1 -0
  17. package/constants.js +1 -0
  18. package/contract/default.js +6 -6
  19. package/dist/account/default.d.ts +10 -44
  20. package/dist/account/default.js +255 -61
  21. package/dist/account/interface.d.ts +78 -7
  22. package/dist/constants.d.ts +1 -0
  23. package/dist/constants.js +1 -0
  24. package/dist/contract/default.js +6 -6
  25. package/dist/provider/default.d.ts +8 -3
  26. package/dist/provider/default.js +31 -4
  27. package/dist/provider/interface.d.ts +67 -5
  28. package/dist/provider/rpc.d.ts +7 -2
  29. package/dist/provider/rpc.js +83 -8
  30. package/dist/provider/sequencer.d.ts +9 -3
  31. package/dist/provider/sequencer.js +93 -14
  32. package/dist/signer/default.d.ts +4 -1
  33. package/dist/signer/default.js +22 -0
  34. package/dist/signer/interface.d.ts +27 -2
  35. package/dist/types/api/openrpc.d.ts +24 -2
  36. package/dist/types/api/sequencer.d.ts +43 -23
  37. package/dist/types/lib.d.ts +23 -2
  38. package/dist/types/provider.d.ts +19 -10
  39. package/dist/types/signer.d.ts +14 -1
  40. package/dist/utils/hash.d.ts +8 -0
  41. package/dist/utils/hash.js +28 -2
  42. package/dist/utils/merkle.js +4 -5
  43. package/dist/utils/number.d.ts +5 -0
  44. package/dist/utils/number.js +29 -1
  45. package/dist/utils/responseParser/rpc.d.ts +2 -6
  46. package/dist/utils/responseParser/rpc.js +0 -11
  47. package/dist/utils/responseParser/sequencer.js +11 -33
  48. package/package.json +1 -1
  49. package/provider/default.d.ts +8 -3
  50. package/provider/default.js +31 -4
  51. package/provider/interface.d.ts +67 -5
  52. package/provider/rpc.d.ts +7 -2
  53. package/provider/rpc.js +83 -8
  54. package/provider/sequencer.d.ts +9 -3
  55. package/provider/sequencer.js +93 -14
  56. package/signer/default.d.ts +4 -1
  57. package/signer/default.js +22 -0
  58. package/signer/interface.d.ts +27 -2
  59. package/src/account/default.ts +201 -53
  60. package/src/account/interface.ts +104 -6
  61. package/src/constants.ts +1 -0
  62. package/src/contract/default.ts +6 -6
  63. package/src/provider/default.ts +43 -5
  64. package/src/provider/interface.ts +92 -7
  65. package/src/provider/rpc.ts +86 -12
  66. package/src/provider/sequencer.ts +105 -13
  67. package/src/signer/default.ts +54 -2
  68. package/src/signer/interface.ts +31 -2
  69. package/src/types/api/openrpc.ts +28 -2
  70. package/src/types/api/sequencer.ts +54 -25
  71. package/src/types/lib.ts +30 -2
  72. package/src/types/provider.ts +31 -11
  73. package/src/types/signer.ts +18 -1
  74. package/src/utils/hash.ts +70 -2
  75. package/src/utils/merkle.ts +4 -5
  76. package/src/utils/number.ts +27 -0
  77. package/src/utils/responseParser/rpc.ts +4 -20
  78. package/src/utils/responseParser/sequencer.ts +14 -7
  79. package/types/api/openrpc.d.ts +24 -2
  80. package/types/api/sequencer.d.ts +43 -23
  81. package/types/lib.d.ts +23 -2
  82. package/types/provider.d.ts +19 -10
  83. package/types/signer.d.ts +14 -1
  84. package/utils/hash.d.ts +8 -0
  85. package/utils/hash.js +28 -2
  86. package/utils/merkle.js +4 -5
  87. package/utils/number.d.ts +5 -0
  88. package/utils/number.js +29 -1
  89. package/utils/responseParser/rpc.d.ts +2 -6
  90. package/utils/responseParser/rpc.js +0 -11
  91. package/utils/responseParser/sequencer.js +11 -33
  92. package/www/docs/API/account.md +60 -1
  93. package/www/docs/API/provider.md +320 -23
  94. package/www/guides/account.md +1 -1
  95. package/www/guides/erc20.md +13 -7
@@ -8,7 +8,9 @@ The **Provider** API allows you to interact with the StarkNet network, without s
8
8
 
9
9
  Typically, these are _read_ calls on the blockchain.
10
10
 
11
- ## Creating an instance
11
+ ## Default Provider
12
+
13
+ ### Creating an instance
12
14
 
13
15
  `new starknet.Provider(optionsOrProvider)`
14
16
 
@@ -53,7 +55,13 @@ These are also the default options for the Provider constructor with `network: '
53
55
  >
54
56
  > `network` arguement should work in most cases. If you want to use the `sequencer` arguement with `baseUrl`, you will not be able to use the `network` field in the object.
55
57
 
56
- ## Methods
58
+ ### Methods
59
+
60
+ <hr/>
61
+
62
+ provider.**getChainId**() => _Promise < StarknetChainId >_
63
+
64
+ Returns the chain Id for the current network.
57
65
 
58
66
  <hr/>
59
67
 
@@ -117,6 +125,28 @@ Gets the contract class of the deployed contract.
117
125
 
118
126
  <hr/>
119
127
 
128
+ provider.**getInvokeEstimateFee**(invocationWithTxType, invocationDetails, blockIdentifier) => _Promise < EstimateFeeResponse >_
129
+
130
+ Estimate fee for invoke transaction.
131
+
132
+ ###### _EstimateFeeResponse_
133
+
134
+ ```typescript
135
+ {
136
+ overall_fee: BN;
137
+ gas_consumed?: BN;
138
+ gas_price?: BN;
139
+ }
140
+ ```
141
+
142
+ <hr/>
143
+
144
+ provider.**getNonce**(contractAddress, blockIdentifier) => _Promise < BigNumberish >_
145
+
146
+ Gets the nonce of the provided contractAddress.
147
+
148
+ <hr/>
149
+
120
150
  provider.**getStorageAt**(contractAddress, key, blockIdentifier) => _Promise < string >_
121
151
 
122
152
  Gets the contract's storage variable at a specific key.
@@ -166,9 +196,24 @@ Gets the transaction information from a tx hash.
166
196
 
167
197
  <hr/>
168
198
 
169
- provider.**declareContract**(payload) => _Promise < DeclareContractResponse >_
199
+ provider.**deployContract**(payload [ , abi ]) => _Promise < DeployContractResponse >_
200
+
201
+ Deploys a contract on Starknet.
170
202
 
171
- Declares a contract on Starknet.
203
+ ###### _DeployContractResponse_
204
+
205
+ ```typescript
206
+ {
207
+ transaction_hash: string;
208
+ contract_address: string;
209
+ };
210
+ ```
211
+
212
+ <hr/>
213
+
214
+ provider.**declareContract**(transaction, details) => _Promise < DeclareContractResponse >_
215
+
216
+ Declare a contract on Starknet.
172
217
 
173
218
  ###### _DeclareContractResponse_
174
219
 
@@ -181,16 +226,17 @@ Declares a contract on Starknet.
181
226
 
182
227
  <hr/>
183
228
 
184
- provider.**deployContract**(payload [ , abi ]) => _Promise < DeployContractResponse >_
229
+ provider.**getDeclareEstimateFee**(transaction, details, blockIdentifier) => _Promise < EstimateFeeResponse >_
185
230
 
186
- Deploys a contract on Starknet.
231
+ Estimate fee for declare transaction.
187
232
 
188
- ###### _DeployContractResponse_
233
+ ###### _EstimateFeeResponse_
189
234
 
190
235
  ```typescript
191
236
  {
192
- transaction_hash: string;
193
- contract_address?: string;
237
+ overall_fee: BN;
238
+ gas_consumed?: BN;
239
+ gas_price?: BN;
194
240
  };
195
241
  ```
196
242
 
@@ -200,9 +246,11 @@ provider.**waitForTransaction**(txHash [ , retryInterval]) => _Promise < void >_
200
246
 
201
247
  Wait for the transaction to be accepted on L2 or L1.
202
248
 
203
- # SequencerProvider
249
+ ## SequencerProvider
204
250
 
205
- ## Creating an instance
251
+ On top of methods found in the [Default Provider](#default-provider) section, `SequencerProvider` has some additional ones you can use.
252
+
253
+ ### Creating an instance
206
254
 
207
255
  `new starknet.SequencerProvider(optionsOrProvider)`
208
256
 
@@ -219,19 +267,21 @@ or
219
267
  Example:
220
268
 
221
269
  ```typescript
222
- const provider = new starknet.Provider({
270
+ const provider = new starknet.SequencerProvider({
223
271
  baseUrl: 'https://alpha4.starknet.io',
224
272
  feederGatewayUrl: 'feeder_gateway',
225
273
  gatewayUrl: 'gateway',
226
274
  })
227
275
  ```
228
276
 
229
- ## Methods
277
+ ### Methods
230
278
 
231
- Gets the smart contract address on the network.
279
+ <hr/>
232
280
 
233
281
  provider.**getContractAddresses**() => _Promise < GetContractAddressesResponse >_
234
282
 
283
+ Gets the smart contract address on the network.
284
+
235
285
  ###### _GetContractAddressesResponse_
236
286
 
237
287
  ```typescript
@@ -243,6 +293,48 @@ provider.**getContractAddresses**() => _Promise < GetContractAddressesResponse >
243
293
 
244
294
  <hr/>
245
295
 
296
+ provider.**getCode**(contractAddress, blockIdentifier) => _Promise < GetCodeResponse >_
297
+
298
+ Gets the smart contract address on the network.
299
+
300
+ ###### _GetCodeResponse_
301
+
302
+ ```typescript
303
+ {
304
+ bytecode: string[];
305
+ abi: Abi;
306
+ }
307
+ ```
308
+
309
+ <hr/>
310
+
311
+ provider.**estimateMessageFee**(CallL1Handler, blockIdentifier) => _Promise < EstimateFeeResponse >_
312
+
313
+ Estimate fee for sending a message to L1.
314
+
315
+ ##### _CallL1Handler_
316
+
317
+ ````typescript
318
+ type CallL1Handler = {
319
+ from_address: getDecimalString(from_address),
320
+ to_address: getHexString(to_address),
321
+ entry_point_selector: getSelector(entry_point_selector),
322
+ payload: getHexStringArray(payload),
323
+ };
324
+
325
+ ###### _EstimateFeeResponse_
326
+
327
+ ```typescript
328
+ {
329
+ overall_fee: number;
330
+ gas_price: number;
331
+ gas_usage: number;
332
+ unit: string;
333
+ }
334
+ ````
335
+
336
+ <hr/>
337
+
246
338
  provider.**getTransactionStatus**(txHash) => _Promise < GetTransactionStatusResponse >_
247
339
 
248
340
  Gets the status of a transaction.
@@ -271,27 +363,35 @@ Gets the transaction trace from a tx hash.
271
363
 
272
364
  ```typescript
273
365
  {
274
- function_invocation: {
366
+ validate_invocation?: FunctionInvocation;
367
+ function_invocation?: FunctionInvocation;
368
+ fee_transfer_invocation?: FunctionInvocation;
369
+ signature: Signature;
370
+ }
371
+
372
+ {
373
+ FunctionInvocation: {
275
374
  caller_address: string;
276
375
  contract_address: string;
277
- code_address: string;
278
- selector: string;
279
376
  calldata: {
280
377
  [inputName: string]: string | string[] | { type: 'struct'; [k: string]: BigNumberish };
281
378
  };
379
+ call_type?: string;
380
+ class_hash?: string;
381
+ selector?: string;
382
+ entry_point_type?: EntryPointType;
282
383
  result: Array<any>;
283
- execution_resources: any;
284
- internal_call: Array<any>;
384
+ execution_resources: ExecutionResources;
385
+ internal_calls: Array<FunctionInvocation>;
285
386
  events: Array<any>;
286
387
  messages: Array<any>;
287
388
  };
288
- signature: Signature;
289
389
  }
290
390
  ```
291
391
 
292
- # RpcProvider
392
+ ## RpcProvider
293
393
 
294
- ## Creating an instance
394
+ ### Creating an instance
295
395
 
296
396
  `new starknet.RpcProvider(options)`
297
397
 
@@ -305,7 +405,60 @@ const provider = new starknet.RpcProvider({
305
405
  })
306
406
  ```
307
407
 
308
- ## Methods
408
+ ### Methods
409
+
410
+ <hr/>
411
+
412
+ provider.**fetch**(method: any, params: any) => _Promise < any >_
413
+
414
+ Generic method for users to be able to experiment with RPC methods.
415
+
416
+ <hr/>
417
+
418
+ provider.**getChainId**() => _Promise < any >_
419
+
420
+ <hr/>
421
+
422
+ provider.**getBlock**(blockIdentifier) => _Promise < GetBlockResponse >_
423
+
424
+ <hr/>
425
+
426
+ provider.**getBlockHashAndNumber**() => _Promise < BlockHashAndNumber >_
427
+
428
+ ###### _BlockHashAndNumber_
429
+
430
+ ```typescript
431
+ {
432
+ block_hash: BLOCK_HASH;
433
+ block_number: BLOCK_NUMBER;
434
+ }
435
+ ```
436
+
437
+ <hr/>
438
+
439
+ provider.**getBlockWithTxHashes**(blockIdentifier) => _Promise < GetBlockWithTxHashesResponse >_
440
+
441
+ ###### _GetBlockWithTxHashesResponse_
442
+
443
+ ```typescript
444
+ OPENRPC.BlockWithTxHashes
445
+ ```
446
+
447
+ <hr/>
448
+
449
+ provider.**getBlockWithTxs**(blockIdentifier) => _Promise < GetBlockWithTxs >_
450
+
451
+ ###### _GetBlockWithTxs_
452
+
453
+ ```typescript
454
+ OPENRPC.BlockWithTxs
455
+ ```
456
+
457
+ <hr/>
458
+
459
+ provider.**getClassHashAt**(blockIdentifier) => _Promise < ContractAddress >_
460
+
461
+ <hr/>
309
462
 
310
463
  provider.**getTransactionCount**(blockIdentifier) => _Promise < number >_
311
464
 
@@ -325,6 +478,148 @@ Gets the nonce of the provided contractAddress
325
478
 
326
479
  <hr/>
327
480
 
481
+ provider.**getPendingTransactions**() => _Promise < PendingTransactions >_
482
+
483
+ ###### _PendingTransactions_
484
+
485
+ ```typescript
486
+ OPENRPC.PendingTransactions;
487
+ ```
488
+
489
+ <hr/>
490
+
491
+ provider.**getStateUpdate**(blockIdentifier) => _Promise < StateUpdate >_
492
+
493
+ ###### _StateUpdate_
494
+
495
+ ```typescript
496
+ OPENRPC.StateUpdate;
497
+ ```
498
+
499
+ <hr/>
500
+
501
+ provider.**getStorageAt**(contractAddress, key, blockIdentifier) => _Promise < BigNumberish >_
502
+
503
+ <hr/>
504
+
505
+ provider.**getTransaction**(txHash) => _Promise < GetTransactionResponse >_
506
+
507
+ <hr/>
508
+
509
+ provider.**getTransactionByHash**(txHash) => _Promise < GetTransactionByHashResponse >_
510
+
511
+ ###### _GetTransactionByHashResponse_
512
+
513
+ ```typescript
514
+ OPENRPC.Transaction;
515
+ ```
516
+
517
+ <hr/>
518
+
519
+ provider.**getTransactionByBlockIdAndIndex**(blockIdentifier, index) => _Promise < GetTransactionByBlockIdAndIndex >_
520
+
521
+ ###### _GetTransactionByBlockIdAndIndex_
522
+
523
+ ```typescript
524
+ OPENRPC.Transaction;
525
+ ```
526
+
527
+ <hr/>
528
+
529
+ provider.**getTransactionReceipt**(txHash) => _Promise < GetTransactionReceiptResponse >_
530
+
531
+ <hr/>
532
+
533
+ provider.**getClass**(classHash) => _Promise < ContractClass >_
534
+
535
+ ###### _ContractClass_
536
+
537
+ ```typescript
538
+ OPENRPC.ContractClass;
539
+ ```
540
+
541
+ <hr/>
542
+
543
+ provider.**getClassAt**(contractAddress, blockIdentifier) => _Promise < ContractClass >_
544
+
545
+ ###### _ContractClass_
546
+
547
+ ```typescript
548
+ OPENRPC.ContractClass;
549
+ ```
550
+
551
+ <hr/>
552
+
553
+ provider.**getInvokeEstimateFee**(invocation, invocationDetails, blockIdentifier) => _Promise < EstimateFeeResponse >_
554
+
555
+ ###### _EstimateFeeResponse_
556
+
557
+ ```typescript
558
+ overall_fee: BN;
559
+ gas_consumed?: BN;
560
+ gas_price?: BN;
561
+ ```
562
+
563
+ <hr/>
564
+
565
+ provider.**getDeclareEstimateFee**(DeclareContractTransaction, details, blockIdentifier) => _Promise < EstimateFeeResponse >_
566
+
567
+ ###### _EstimateFeeResponse_
568
+
569
+ ```typescript
570
+ overall_fee: BN;
571
+ gas_consumed?: BN;
572
+ gas_price?: BN;
573
+ ```
574
+
575
+ <hr/>
576
+
577
+ provider.**declareContract**(DeclareContractTransaction, details) => _Promise < DeclareContractResponse >_
578
+
579
+ ###### _DeclareContractResponse_
580
+
581
+ ```typescript
582
+ transaction_hash: string;
583
+ class_hash: string;
584
+ ```
585
+
586
+ <hr/>
587
+
588
+ provider.**deployContract**(contract, constructorCalldata, addressSalt) => _Promise < DeployContractResponse >_
589
+
590
+ ###### _DeployContractResponse_
591
+
592
+ ```typescript
593
+ contract_address: string;
594
+ transaction_hash: string;
595
+ ```
596
+
597
+ <hr/>
598
+
599
+ provider.**callContract**(call, blockIdentifier) => _Promise < CallContractResponse >_
600
+
601
+ <hr/>
602
+
603
+ provider.**traceTransaction**(transactionHash) => _Promise < Trace >_
604
+
605
+ ###### _Trace_
606
+
607
+ ```typescript
608
+ OPENRPC.Trace;
609
+ ```
610
+
611
+ <hr/>
612
+
613
+ provider.**traceBlockTransactions**(blockHash) => _Promise < Traces >_
614
+
615
+ ###### _Traces_
616
+
617
+ ```typescript
618
+ OPENRPC.Traces;
619
+ ```
620
+
621
+ <hr/>
622
+
328
623
  provider.**getSyncingStats**() => _Promise < GetSyncingStatsResponse >_
329
624
 
330
625
  Gets syncing status of the node.
@@ -347,6 +642,8 @@ boolean |
347
642
 
348
643
  provider.**getEvents**(eventFilter) => _Promise < GetEventsResponse >_
349
644
 
645
+ Gets all the events filtered
646
+
350
647
  ##### _EventFilter_
351
648
 
352
649
  ```typescript
@@ -45,7 +45,7 @@ const compiledAccount = json.parse(
45
45
 
46
46
  > **Note**
47
47
  >
48
- > below example uses [Argent's](https://github.com/argentlabs/argent-contracts-starknet/blob/develop/contracts/ArgentAccount.cairo) account contract
48
+ > below example uses [Argent's](https://github.com/argentlabs/argent-contracts-starknet/blob/develop/contracts/account/ArgentAccount.cairo) account contract
49
49
 
50
50
  ```javascript
51
51
  const accountResponse = await defaultProvider.deployContract({
@@ -12,11 +12,17 @@ const compiledErc20 = json.parse(
12
12
  );
13
13
  const erc20Response = await defaultProvider.deployContract({
14
14
  contract: compiledErc20,
15
+ constructorCalldata: [encodeShortString('TokenName'), encodeShortString('TokenSymbol'), recipient], // Here the `recipient` receives the initial 1000 tokens
15
16
  });
17
+
16
18
  console.log("Waiting for Tx to be Accepted on Starknet - ERC20 Deployment...");
17
19
  await defaultProvider.waitForTransaction(erc20Response.transaction_hash);
18
20
  ```
19
21
 
22
+ > **Note**
23
+ >
24
+ > The ERC20 contract can be found [here](https://github.com/argentlabs/argent-contracts-starknet/blob/develop/contracts/lib/ERC20.cairo)
25
+
20
26
  ## Get the erc20 contract address and create the contact object
21
27
 
22
28
  ```javascript
@@ -35,7 +41,7 @@ erc20.connect(account);
35
41
 
36
42
  const { transaction_hash: mintTxHash } = await erc20.mint(
37
43
  account.address,
38
- "1000",
44
+ [ "1000", "0"]
39
45
  {
40
46
  maxFee: "1"
41
47
  }
@@ -59,11 +65,11 @@ await defaultProvider.waitForTransaction(mintTxHash);
59
65
 
60
66
  ```javascript
61
67
  console.log(`Calling StarkNet for account balance...`);
62
- const balanceBeforeTransfer = await erc20.balance_of(account.address);
68
+ const balanceBeforeTransfer = await erc20.balanceOf(account.address);
63
69
 
64
70
  console.log(
65
71
  `account Address ${account.address} has a balance of:`,
66
- number.toBN(balanceBeforeTransfer.res, 16).toString()
72
+ number.toBN(balanceBeforeTransfer.balance.low, 16).toString()
67
73
  );
68
74
  ```
69
75
 
@@ -76,7 +82,7 @@ const { transaction_hash: transferTxHash } = await account.execute(
76
82
  {
77
83
  contractAddress: erc20Address,
78
84
  entrypoint: "transfer",
79
- calldata: [erc20Address, "10"],
85
+ calldata: [erc20Address, "10", "0"],
80
86
  },
81
87
  undefined,
82
88
  { maxFee: "1" }
@@ -90,12 +96,12 @@ await defaultProvider.waitForTransaction(transferTxHash);
90
96
  ## Check balance after transfer
91
97
 
92
98
  ```javascript
93
- // Check balance after transfer - should be 990
99
+ // Check balance after transfer - should be 1990 (1000 initial supply + 1000 mint - 10 transfer)
94
100
  console.log(`Calling StarkNet for account balance...`);
95
- const balanceAfterTransfer = await erc20.balance_of(account.address);
101
+ const balanceAfterTransfer = await erc20.balanceOf(account.address);
96
102
 
97
103
  console.log(
98
104
  `account Address ${account.address} has a balance of:`,
99
- number.toBN(balanceAfterTransfer.res, 16).toString()
105
+ number.toBN(balanceAfterTransfer.balance.low, 16).toString()
100
106
  );
101
107
  ```