starknet 4.8.0 → 4.10.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 (107) hide show
  1. package/CHANGELOG.md +46 -0
  2. package/README.md +1 -3
  3. package/__mocks__/ERC20.json +32561 -29055
  4. package/__tests__/account.test.ts +32 -24
  5. package/__tests__/contract.test.ts +25 -14
  6. package/__tests__/defaultProvider.test.ts +91 -240
  7. package/__tests__/fixtures.ts +10 -2
  8. package/__tests__/rpcProvider.test.ts +8 -16
  9. package/__tests__/sequencerProvider.test.ts +17 -10
  10. package/__tests__/udc.test.ts +41 -0
  11. package/__tests__/utils/merkle.test.ts +98 -3
  12. package/__tests__/utils/typedData.test.ts +3 -3
  13. package/account/default.d.ts +12 -44
  14. package/account/default.js +305 -61
  15. package/account/interface.d.ts +96 -8
  16. package/constants.d.ts +8 -1
  17. package/constants.js +8 -1
  18. package/contract/default.d.ts +11 -27
  19. package/contract/default.js +105 -121
  20. package/contract/interface.d.ts +5 -2
  21. package/dist/account/default.d.ts +12 -44
  22. package/dist/account/default.js +305 -61
  23. package/dist/account/interface.d.ts +96 -8
  24. package/dist/constants.d.ts +8 -1
  25. package/dist/constants.js +8 -1
  26. package/dist/contract/default.d.ts +11 -27
  27. package/dist/contract/default.js +105 -121
  28. package/dist/contract/interface.d.ts +5 -2
  29. package/dist/provider/default.d.ts +8 -3
  30. package/dist/provider/default.js +31 -4
  31. package/dist/provider/interface.d.ts +67 -5
  32. package/dist/provider/rpc.d.ts +10 -3
  33. package/dist/provider/rpc.js +98 -10
  34. package/dist/provider/sequencer.d.ts +11 -4
  35. package/dist/provider/sequencer.js +89 -18
  36. package/dist/signer/default.d.ts +5 -2
  37. package/dist/signer/default.js +25 -3
  38. package/dist/signer/interface.d.ts +29 -2
  39. package/dist/types/api/index.d.ts +0 -6
  40. package/dist/types/api/openrpc.d.ts +24 -2
  41. package/dist/types/api/sequencer.d.ts +22 -7
  42. package/dist/types/index.d.ts +1 -1
  43. package/dist/types/lib.d.ts +36 -2
  44. package/dist/types/provider.d.ts +15 -10
  45. package/dist/types/signer.d.ts +14 -1
  46. package/dist/utils/hash.d.ts +2 -0
  47. package/dist/utils/hash.js +13 -2
  48. package/dist/utils/merkle.js +2 -4
  49. package/dist/utils/number.d.ts +1 -0
  50. package/dist/utils/number.js +3 -1
  51. package/dist/utils/responseParser/rpc.d.ts +2 -6
  52. package/dist/utils/responseParser/rpc.js +0 -11
  53. package/dist/utils/responseParser/sequencer.js +4 -14
  54. package/package.json +1 -1
  55. package/provider/default.d.ts +8 -3
  56. package/provider/default.js +31 -4
  57. package/provider/interface.d.ts +67 -5
  58. package/provider/rpc.d.ts +10 -3
  59. package/provider/rpc.js +98 -10
  60. package/provider/sequencer.d.ts +11 -4
  61. package/provider/sequencer.js +89 -18
  62. package/signer/default.d.ts +5 -2
  63. package/signer/default.js +25 -3
  64. package/signer/interface.d.ts +29 -2
  65. package/src/account/default.ts +243 -55
  66. package/src/account/interface.ts +132 -7
  67. package/src/constants.ts +8 -0
  68. package/src/contract/default.ts +124 -141
  69. package/src/contract/interface.ts +5 -2
  70. package/src/provider/default.ts +43 -5
  71. package/src/provider/interface.ts +92 -7
  72. package/src/provider/rpc.ts +93 -15
  73. package/src/provider/sequencer.ts +87 -14
  74. package/src/signer/default.ts +56 -4
  75. package/src/signer/interface.ts +33 -2
  76. package/src/types/api/index.ts +0 -4
  77. package/src/types/api/openrpc.ts +28 -2
  78. package/src/types/api/sequencer.ts +32 -9
  79. package/src/types/index.ts +1 -1
  80. package/src/types/lib.ts +43 -2
  81. package/src/types/provider.ts +27 -11
  82. package/src/types/signer.ts +18 -1
  83. package/src/utils/hash.ts +46 -1
  84. package/src/utils/merkle.ts +2 -4
  85. package/src/utils/number.ts +2 -0
  86. package/src/utils/responseParser/rpc.ts +4 -20
  87. package/src/utils/responseParser/sequencer.ts +2 -0
  88. package/types/api/index.d.ts +0 -6
  89. package/types/api/openrpc.d.ts +24 -2
  90. package/types/api/sequencer.d.ts +22 -7
  91. package/types/index.d.ts +1 -1
  92. package/types/lib.d.ts +36 -2
  93. package/types/provider.d.ts +15 -10
  94. package/types/signer.d.ts +14 -1
  95. package/utils/hash.d.ts +2 -0
  96. package/utils/hash.js +13 -2
  97. package/utils/merkle.js +2 -4
  98. package/utils/number.d.ts +1 -0
  99. package/utils/number.js +3 -1
  100. package/utils/responseParser/rpc.d.ts +2 -6
  101. package/utils/responseParser/rpc.js +0 -11
  102. package/utils/responseParser/sequencer.js +4 -14
  103. package/www/docs/API/account.md +170 -11
  104. package/www/docs/API/contract.md +39 -3
  105. package/www/docs/API/provider.md +310 -17
  106. package/www/docs/API/signer.md +56 -2
  107. package/www/guides/erc20.md +13 -7
@@ -33,25 +33,22 @@ export declare class Contract implements ContractInterface {
33
33
  * @param providerOrAccount (optional) - Provider or Account to attach to
34
34
  */
35
35
  constructor(abi: Abi, address: string, providerOrAccount?: ProviderInterface | AccountInterface);
36
- /**
37
- * Saves the address of the contract deployed on network that will be used for interaction
38
- *
39
- * @param address - address of the contract
40
- */
41
36
  attach(address: string): void;
42
- /**
43
- * Attaches to new Provider or Account
44
- *
45
- * @param providerOrAccount - new Provider or Account to attach to
46
- */
47
37
  connect(providerOrAccount: ProviderInterface | AccountInterface): void;
38
+ deployed(): Promise<Contract>;
39
+ call(method: string, args?: Array<any>, { blockIdentifier, }?: {
40
+ blockIdentifier?: BlockIdentifier;
41
+ }): Promise<Result>;
42
+ invoke(method: string, args?: Array<any>, options?: Overrides): Promise<InvokeFunctionResponse>;
43
+ estimate(method: string, args?: Array<any>): Promise<import("../types").EstimateFeeResponse>;
44
+ populate(method: string, args?: Array<any>): Call;
48
45
  /**
49
- * Resolves when contract is deployed on the network or when no deployment transaction is found
46
+ * Deep parse of the object that has been passed to the method
50
47
  *
51
- * @returns Promise that resolves when contract is deployed on the network or when no deployment transaction is found
52
- * @throws When deployment fails
48
+ * @param struct - struct that needs to be calculated
49
+ * @return {number} - number of members for the given struct
53
50
  */
54
- deployed(): Promise<Contract>;
51
+ private calculateStructMembers;
55
52
  /**
56
53
  * Validates if all arguments that are passed to the method are corresponding to the ones in the abi
57
54
  *
@@ -60,13 +57,6 @@ export declare class Contract implements ContractInterface {
60
57
  * @param args - arguments that are passed to the method
61
58
  */
62
59
  protected validateMethodAndArgs(type: 'INVOKE' | 'CALL', method: string, args?: Array<any>): void;
63
- /**
64
- * Deep parse of the object that has been passed to the method
65
- *
66
- * @param struct - struct that needs to be calculated
67
- * @return {number} - number of members for the given struct
68
- */
69
- private calculateStructMembers;
70
60
  /**
71
61
  * Deep parse of the object that has been passed to the method
72
62
  *
@@ -115,10 +105,4 @@ export declare class Contract implements ContractInterface {
115
105
  * @return - parsed response corresponding to the abi
116
106
  */
117
107
  protected parseResponse(method: string, response: string[]): Result;
118
- invoke(method: string, args?: Array<any>, options?: Overrides): Promise<InvokeFunctionResponse>;
119
- call(method: string, args?: Array<any>, { blockIdentifier, }?: {
120
- blockIdentifier?: BlockIdentifier;
121
- }): Promise<Result>;
122
- estimate(method: string, args?: Array<any>): Promise<import("../types").EstimateFeeResponse>;
123
- populate(method: string, args?: Array<any>): Call;
124
108
  }
@@ -181,7 +181,7 @@ var Contract = /** @class */ (function () {
181
181
  function Contract(abi, address, providerOrAccount) {
182
182
  if (providerOrAccount === void 0) { providerOrAccount = provider_1.defaultProvider; }
183
183
  var _this = this;
184
- this.address = address.toLowerCase();
184
+ this.address = address && address.toLowerCase();
185
185
  this.providerOrAccount = providerOrAccount;
186
186
  this.abi = abi;
187
187
  this.structs = abi
@@ -252,28 +252,12 @@ var Contract = /** @class */ (function () {
252
252
  }
253
253
  });
254
254
  }
255
- /**
256
- * Saves the address of the contract deployed on network that will be used for interaction
257
- *
258
- * @param address - address of the contract
259
- */
260
255
  Contract.prototype.attach = function (address) {
261
256
  this.address = address;
262
257
  };
263
- /**
264
- * Attaches to new Provider or Account
265
- *
266
- * @param providerOrAccount - new Provider or Account to attach to
267
- */
268
258
  Contract.prototype.connect = function (providerOrAccount) {
269
259
  this.providerOrAccount = providerOrAccount;
270
260
  };
271
- /**
272
- * Resolves when contract is deployed on the network or when no deployment transaction is found
273
- *
274
- * @returns Promise that resolves when contract is deployed on the network or when no deployment transaction is found
275
- * @throws When deployment fails
276
- */
277
261
  Contract.prototype.deployed = function () {
278
262
  return __awaiter(this, void 0, void 0, function () {
279
263
  return __generator(this, function (_a) {
@@ -290,6 +274,110 @@ var Contract = /** @class */ (function () {
290
274
  });
291
275
  });
292
276
  };
277
+ Contract.prototype.call = function (method, args, _a) {
278
+ if (args === void 0) { args = []; }
279
+ var _b = _a === void 0 ? {} : _a, _c = _b.blockIdentifier, blockIdentifier = _c === void 0 ? 'pending' : _c;
280
+ return __awaiter(this, void 0, void 0, function () {
281
+ var inputs, calldata;
282
+ var _this = this;
283
+ return __generator(this, function (_d) {
284
+ // ensure contract is connected
285
+ (0, minimalistic_assert_1.default)(this.address !== null, 'contract is not connected to an address');
286
+ // validate method and args
287
+ this.validateMethodAndArgs('CALL', method, args);
288
+ inputs = this.abi.find(function (abi) { return abi.name === method; }).inputs;
289
+ calldata = this.compileCalldata(args, inputs);
290
+ return [2 /*return*/, this.providerOrAccount
291
+ .callContract({
292
+ contractAddress: this.address,
293
+ calldata: calldata,
294
+ entrypoint: method,
295
+ }, blockIdentifier)
296
+ .then(function (x) { return _this.parseResponse(method, x.result); })];
297
+ });
298
+ });
299
+ };
300
+ Contract.prototype.invoke = function (method, args, options) {
301
+ if (args === void 0) { args = []; }
302
+ if (options === void 0) { options = {}; }
303
+ // ensure contract is connected
304
+ (0, minimalistic_assert_1.default)(this.address !== null, 'contract is not connected to an address');
305
+ // validate method and args
306
+ this.validateMethodAndArgs('INVOKE', method, args);
307
+ var inputs = this.abi.find(function (abi) { return abi.name === method; }).inputs;
308
+ var inputsLength = inputs.reduce(function (acc, input) {
309
+ if (!/_len$/.test(input.name)) {
310
+ return acc + 1;
311
+ }
312
+ return acc;
313
+ }, 0);
314
+ if (args.length !== inputsLength) {
315
+ throw Error("Invalid number of arguments, expected ".concat(inputsLength, " arguments, but got ").concat(args.length));
316
+ }
317
+ // compile calldata
318
+ var calldata = this.compileCalldata(args, inputs);
319
+ var invocation = {
320
+ contractAddress: this.address,
321
+ calldata: calldata,
322
+ entrypoint: method,
323
+ };
324
+ if ('execute' in this.providerOrAccount) {
325
+ return this.providerOrAccount.execute(invocation, undefined, {
326
+ maxFee: options.maxFee,
327
+ nonce: options.nonce,
328
+ });
329
+ }
330
+ if (!options.nonce) {
331
+ throw new Error("Nonce is required when invoking a function without an account");
332
+ }
333
+ // eslint-disable-next-line no-console
334
+ console.warn("Invoking ".concat(method, " without an account. This will not work on a public node."));
335
+ return this.providerOrAccount.invokeFunction(__assign(__assign({}, invocation), { signature: options.signature || [] }), {
336
+ nonce: options.nonce,
337
+ });
338
+ };
339
+ Contract.prototype.estimate = function (method, args) {
340
+ if (args === void 0) { args = []; }
341
+ return __awaiter(this, void 0, void 0, function () {
342
+ var invocation;
343
+ var _a;
344
+ return __generator(this, function (_b) {
345
+ // ensure contract is connected
346
+ (0, minimalistic_assert_1.default)(this.address !== null, 'contract is not connected to an address');
347
+ // validate method and args
348
+ this.validateMethodAndArgs('INVOKE', method, args);
349
+ invocation = (_a = this.populateTransaction)[method].apply(_a, __spreadArray([], __read(args), false));
350
+ if ('estimateInvokeFee' in this.providerOrAccount) {
351
+ return [2 /*return*/, this.providerOrAccount.estimateInvokeFee(invocation)];
352
+ }
353
+ throw Error('Contract must be connected to the account contract to estimate');
354
+ });
355
+ });
356
+ };
357
+ Contract.prototype.populate = function (method, args) {
358
+ if (args === void 0) { args = []; }
359
+ var inputs = this.abi.find(function (abi) { return abi.name === method; }).inputs;
360
+ return {
361
+ contractAddress: this.address,
362
+ entrypoint: method,
363
+ calldata: this.compileCalldata(args, inputs),
364
+ };
365
+ };
366
+ /**
367
+ * Deep parse of the object that has been passed to the method
368
+ *
369
+ * @param struct - struct that needs to be calculated
370
+ * @return {number} - number of members for the given struct
371
+ */
372
+ Contract.prototype.calculateStructMembers = function (struct) {
373
+ var _this = this;
374
+ return this.structs[struct].members.reduce(function (acc, member) {
375
+ if (member.type === 'felt') {
376
+ return acc + 1;
377
+ }
378
+ return acc + _this.calculateStructMembers(member.type);
379
+ }, 0);
380
+ };
293
381
  /**
294
382
  * Validates if all arguments that are passed to the method are corresponding to the ones in the abi
295
383
  *
@@ -371,21 +459,6 @@ var Contract = /** @class */ (function () {
371
459
  }
372
460
  });
373
461
  };
374
- /**
375
- * Deep parse of the object that has been passed to the method
376
- *
377
- * @param struct - struct that needs to be calculated
378
- * @return {number} - number of members for the given struct
379
- */
380
- Contract.prototype.calculateStructMembers = function (struct) {
381
- var _this = this;
382
- return this.structs[struct].members.reduce(function (acc, member) {
383
- if (member.type === 'felt') {
384
- return acc + 1;
385
- }
386
- return acc + _this.calculateStructMembers(member.type);
387
- }, 0);
388
- };
389
462
  /**
390
463
  * Deep parse of the object that has been passed to the method
391
464
  *
@@ -562,95 +635,6 @@ var Contract = /** @class */ (function () {
562
635
  return acc;
563
636
  }, []);
564
637
  };
565
- Contract.prototype.invoke = function (method, args, options) {
566
- if (args === void 0) { args = []; }
567
- if (options === void 0) { options = {}; }
568
- // ensure contract is connected
569
- (0, minimalistic_assert_1.default)(this.address !== null, 'contract isnt connected to an address');
570
- // validate method and args
571
- this.validateMethodAndArgs('INVOKE', method, args);
572
- var inputs = this.abi.find(function (abi) { return abi.name === method; }).inputs;
573
- var inputsLength = inputs.reduce(function (acc, input) {
574
- if (!/_len$/.test(input.name)) {
575
- return acc + 1;
576
- }
577
- return acc;
578
- }, 0);
579
- if (args.length !== inputsLength) {
580
- throw Error("Invalid number of arguments, expected ".concat(inputsLength, " arguments, but got ").concat(args.length));
581
- }
582
- // compile calldata
583
- var calldata = this.compileCalldata(args, inputs);
584
- var invocation = {
585
- contractAddress: this.address,
586
- calldata: calldata,
587
- entrypoint: method,
588
- };
589
- if ('execute' in this.providerOrAccount) {
590
- return this.providerOrAccount.execute(invocation, undefined, {
591
- maxFee: options.maxFee,
592
- nonce: options.nonce,
593
- });
594
- }
595
- if (!options.nonce) {
596
- throw new Error("Nonce is required when invoking a function without an account");
597
- }
598
- // eslint-disable-next-line no-console
599
- console.warn("Invoking ".concat(method, " without an account. This will not work on a public node."));
600
- return this.providerOrAccount.invokeFunction(__assign(__assign({}, invocation), { signature: options.signature || [] }), {
601
- nonce: options.nonce,
602
- });
603
- };
604
- Contract.prototype.call = function (method, args, _a) {
605
- if (args === void 0) { args = []; }
606
- var _b = _a === void 0 ? {} : _a, _c = _b.blockIdentifier, blockIdentifier = _c === void 0 ? 'pending' : _c;
607
- return __awaiter(this, void 0, void 0, function () {
608
- var inputs, calldata;
609
- var _this = this;
610
- return __generator(this, function (_d) {
611
- // ensure contract is connected
612
- (0, minimalistic_assert_1.default)(this.address !== null, 'contract isnt connected to an address');
613
- // validate method and args
614
- this.validateMethodAndArgs('CALL', method, args);
615
- inputs = this.abi.find(function (abi) { return abi.name === method; }).inputs;
616
- calldata = this.compileCalldata(args, inputs);
617
- return [2 /*return*/, this.providerOrAccount
618
- .callContract({
619
- contractAddress: this.address,
620
- calldata: calldata,
621
- entrypoint: method,
622
- }, blockIdentifier)
623
- .then(function (x) { return _this.parseResponse(method, x.result); })];
624
- });
625
- });
626
- };
627
- Contract.prototype.estimate = function (method, args) {
628
- if (args === void 0) { args = []; }
629
- return __awaiter(this, void 0, void 0, function () {
630
- var invocation;
631
- var _a;
632
- return __generator(this, function (_b) {
633
- // ensure contract is connected
634
- (0, minimalistic_assert_1.default)(this.address !== null, 'contract isnt connected to an address');
635
- // validate method and args
636
- this.validateMethodAndArgs('INVOKE', method, args);
637
- invocation = (_a = this.populateTransaction)[method].apply(_a, __spreadArray([], __read(args), false));
638
- if ('estimateFee' in this.providerOrAccount) {
639
- return [2 /*return*/, this.providerOrAccount.estimateFee(invocation)];
640
- }
641
- throw Error('Contract must be connected to the account contract to estimate');
642
- });
643
- });
644
- };
645
- Contract.prototype.populate = function (method, args) {
646
- if (args === void 0) { args = []; }
647
- var inputs = this.abi.find(function (abi) { return abi.name === method; }).inputs;
648
- return {
649
- contractAddress: this.address,
650
- entrypoint: method,
651
- calldata: this.compileCalldata(args, inputs),
652
- };
653
- };
654
638
  return Contract;
655
639
  }());
656
640
  exports.Contract = Contract;
@@ -44,6 +44,7 @@ export declare abstract class ContractInterface {
44
44
  *
45
45
  * @param method name of the method
46
46
  * @param args Array of the arguments for the call
47
+ * @param options optional blockIdentifier
47
48
  * @returns Result of the call as an array with key value pars
48
49
  */
49
50
  abstract call(method: string, args?: Array<any>, options?: {
@@ -54,14 +55,16 @@ export declare abstract class ContractInterface {
54
55
  *
55
56
  * @param method name of the method
56
57
  * @param args Array of the arguments for the invoke
58
+ * @param options
57
59
  * @returns Add Transaction Response
58
60
  */
59
61
  abstract invoke(method: string, args?: Array<any>, options?: Overrides): Promise<InvokeFunctionResponse>;
60
62
  /**
61
- * Calls a method on a contract
63
+ * Estimates a method on a contract
62
64
  *
63
65
  * @param method name of the method
64
66
  * @param args Array of the arguments for the call
67
+ * @param options optional blockIdentifier
65
68
  */
66
69
  abstract estimate(method: string, args?: Array<any>, options?: {
67
70
  blockIdentifier?: BlockIdentifier;
@@ -71,7 +74,7 @@ export declare abstract class ContractInterface {
71
74
  *
72
75
  * @param method name of the method
73
76
  * @param args Array of the arguments for the call
74
- * @returns Invocation objet
77
+ * @returns Invocation object
75
78
  */
76
79
  abstract populate(method: string, args?: Array<any>): Invocation;
77
80
  }
@@ -1,5 +1,6 @@
1
1
  import { StarknetChainId } from '../constants';
2
- import { Call, CallContractResponse, ContractClass, DeclareContractPayload, DeclareContractResponse, DeployContractPayload, DeployContractResponse, EstimateFeeResponse, GetBlockResponse, GetCodeResponse, GetTransactionReceiptResponse, GetTransactionResponse, Invocation, InvocationsDetailsWithNonce, InvokeFunctionResponse } from '../types';
2
+ import { Call, CallContractResponse, ContractClass, DeclareContractResponse, DeployContractPayload, DeployContractResponse, EstimateFeeResponse, GetBlockResponse, GetCodeResponse, GetTransactionReceiptResponse, GetTransactionResponse, Invocation, InvocationsDetailsWithNonce, InvokeFunctionResponse } from '../types';
3
+ import { DeclareContractTransaction, DeployAccountContractTransaction } from '../types/lib';
3
4
  import { BigNumberish } from '../utils/number';
4
5
  import { ProviderInterface } from './interface';
5
6
  import { RpcProviderOptions } from './rpc';
@@ -16,7 +17,8 @@ export declare class Provider implements ProviderInterface {
16
17
  getChainId(): Promise<StarknetChainId>;
17
18
  getBlock(blockIdentifier?: BlockIdentifier): Promise<GetBlockResponse>;
18
19
  getClassAt(contractAddress: string, blockIdentifier?: BlockIdentifier): Promise<ContractClass>;
19
- getEstimateFee(invocation: Invocation, invocationDetails: InvocationsDetailsWithNonce, blockIdentifier?: BlockIdentifier): Promise<EstimateFeeResponse>;
20
+ getEstimateFee(invocationWithTxType: Invocation, invocationDetails: InvocationsDetailsWithNonce, blockIdentifier?: BlockIdentifier): Promise<EstimateFeeResponse>;
21
+ getInvokeEstimateFee(invocationWithTxType: Invocation, invocationDetails: InvocationsDetailsWithNonce, blockIdentifier?: BlockIdentifier): Promise<EstimateFeeResponse>;
20
22
  getNonce(contractAddress: string, blockIdentifier?: BlockIdentifier): Promise<BigNumberish>;
21
23
  getStorageAt(contractAddress: string, key: BigNumberish, blockIdentifier?: BlockIdentifier): Promise<BigNumberish>;
22
24
  getTransaction(txHash: BigNumberish): Promise<GetTransactionResponse>;
@@ -24,7 +26,10 @@ export declare class Provider implements ProviderInterface {
24
26
  callContract(request: Call, blockIdentifier?: BlockIdentifier): Promise<CallContractResponse>;
25
27
  invokeFunction(functionInvocation: Invocation, details: InvocationsDetailsWithNonce): Promise<InvokeFunctionResponse>;
26
28
  deployContract(payload: DeployContractPayload): Promise<DeployContractResponse>;
27
- declareContract(payload: DeclareContractPayload): Promise<DeclareContractResponse>;
29
+ deployAccountContract(payload: DeployAccountContractTransaction, details: InvocationsDetailsWithNonce): Promise<DeployContractResponse>;
30
+ declareContract(transaction: DeclareContractTransaction, details: InvocationsDetailsWithNonce): Promise<DeclareContractResponse>;
31
+ getDeclareEstimateFee(transaction: DeclareContractTransaction, details: InvocationsDetailsWithNonce, blockIdentifier?: BlockIdentifier): Promise<EstimateFeeResponse>;
32
+ getDeployAccountEstimateFee(transaction: DeployAccountContractTransaction, details: InvocationsDetailsWithNonce, blockIdentifier?: BlockIdentifier): Promise<EstimateFeeResponse>;
28
33
  getCode(contractAddress: string, blockIdentifier?: BlockIdentifier): Promise<GetCodeResponse>;
29
34
  waitForTransaction(txHash: BigNumberish, retryInterval?: number): Promise<void>;
30
35
  }
@@ -84,11 +84,19 @@ var Provider = /** @class */ (function () {
84
84
  });
85
85
  });
86
86
  };
87
- Provider.prototype.getEstimateFee = function (invocation, invocationDetails, blockIdentifier) {
87
+ Provider.prototype.getEstimateFee = function (invocationWithTxType, invocationDetails, blockIdentifier) {
88
88
  if (blockIdentifier === void 0) { blockIdentifier = 'pending'; }
89
89
  return __awaiter(this, void 0, void 0, function () {
90
90
  return __generator(this, function (_a) {
91
- return [2 /*return*/, this.provider.getEstimateFee(invocation, invocationDetails, blockIdentifier)];
91
+ return [2 /*return*/, this.provider.getEstimateFee(invocationWithTxType, invocationDetails, blockIdentifier)];
92
+ });
93
+ });
94
+ };
95
+ Provider.prototype.getInvokeEstimateFee = function (invocationWithTxType, invocationDetails, blockIdentifier) {
96
+ if (blockIdentifier === void 0) { blockIdentifier = 'pending'; }
97
+ return __awaiter(this, void 0, void 0, function () {
98
+ return __generator(this, function (_a) {
99
+ return [2 /*return*/, this.provider.getInvokeEstimateFee(invocationWithTxType, invocationDetails, blockIdentifier)];
92
100
  });
93
101
  });
94
102
  };
@@ -143,13 +151,32 @@ var Provider = /** @class */ (function () {
143
151
  });
144
152
  });
145
153
  };
146
- Provider.prototype.declareContract = function (payload) {
154
+ Provider.prototype.deployAccountContract = function (payload, details) {
147
155
  return __awaiter(this, void 0, void 0, function () {
148
156
  return __generator(this, function (_a) {
149
- return [2 /*return*/, this.provider.declareContract(payload)];
157
+ return [2 /*return*/, this.provider.deployAccountContract(payload, details)];
150
158
  });
151
159
  });
152
160
  };
161
+ Provider.prototype.declareContract = function (transaction, details) {
162
+ return __awaiter(this, void 0, void 0, function () {
163
+ return __generator(this, function (_a) {
164
+ return [2 /*return*/, this.provider.declareContract(transaction, details)];
165
+ });
166
+ });
167
+ };
168
+ Provider.prototype.getDeclareEstimateFee = function (transaction, details, blockIdentifier) {
169
+ if (blockIdentifier === void 0) { blockIdentifier = 'pending'; }
170
+ return __awaiter(this, void 0, void 0, function () {
171
+ return __generator(this, function (_a) {
172
+ return [2 /*return*/, this.provider.getDeclareEstimateFee(transaction, details, blockIdentifier)];
173
+ });
174
+ });
175
+ };
176
+ Provider.prototype.getDeployAccountEstimateFee = function (transaction, details, blockIdentifier) {
177
+ if (blockIdentifier === void 0) { blockIdentifier = 'pending'; }
178
+ return this.provider.getDeployAccountEstimateFee(transaction, details, blockIdentifier);
179
+ };
153
180
  Provider.prototype.getCode = function (contractAddress, blockIdentifier) {
154
181
  return __awaiter(this, void 0, void 0, function () {
155
182
  return __generator(this, function (_a) {
@@ -1,5 +1,6 @@
1
1
  import { StarknetChainId } from '../constants';
2
- import type { Call, CallContractResponse, ContractClass, DeclareContractPayload, DeclareContractResponse, DeployContractPayload, DeployContractResponse, EstimateFeeResponse, GetBlockResponse, GetCodeResponse, GetTransactionReceiptResponse, GetTransactionResponse, Invocation, InvocationsDetailsWithNonce, InvokeFunctionResponse } from '../types';
2
+ import type { Call, CallContractResponse, ContractClass, DeclareContractResponse, DeployContractPayload, DeployContractResponse, EstimateFeeResponse, GetBlockResponse, GetCodeResponse, GetTransactionReceiptResponse, GetTransactionResponse, Invocation, InvocationsDetailsWithNonce, InvokeFunctionResponse } from '../types';
3
+ import { DeclareContractTransaction, DeployAccountContractPayload, DeployAccountContractTransaction } from '../types/lib';
3
4
  import type { BigNumberish } from '../utils/number';
4
5
  import { BlockIdentifier } from './utils';
5
6
  export declare abstract class ProviderInterface {
@@ -78,14 +79,15 @@ export declare abstract class ProviderInterface {
78
79
  */
79
80
  abstract deployContract(payload: DeployContractPayload): Promise<DeployContractResponse>;
80
81
  /**
81
- * Declares a given compiled contract (json) to starknet
82
+ * Deploys a given compiled Account contract (json) to starknet
82
83
  *
83
84
  * @param payload payload to be deployed containing:
84
85
  * - compiled contract code
85
- * - optional version
86
+ * - constructor calldata
87
+ * - address salt
86
88
  * @returns a confirmation of sending a transaction on the starknet contract
87
89
  */
88
- abstract declareContract(payload: DeclareContractPayload): Promise<DeclareContractResponse>;
90
+ abstract deployAccountContract(payload: DeployAccountContractPayload, details: InvocationsDetailsWithNonce): Promise<DeployContractResponse>;
89
91
  /**
90
92
  * Invokes a function on starknet
91
93
  * @deprecated This method wont be supported as soon as fees are mandatory
@@ -103,7 +105,21 @@ export declare abstract class ProviderInterface {
103
105
  */
104
106
  abstract invokeFunction(invocation: Invocation, details: InvocationsDetailsWithNonce): Promise<InvokeFunctionResponse>;
105
107
  /**
106
- * Estimates the fee for a given transaction
108
+ * Declares a given compiled contract (json) to starknet
109
+ * @param transaction transaction payload to be deployed containing:
110
+ * - compiled contract code
111
+ * - sender address
112
+ * - signature
113
+ * @param details Invocation Details containing:
114
+ * - nonce
115
+ * - optional version
116
+ * - optional maxFee
117
+ * @returns a confirmation of sending a transaction on the starknet contract
118
+ */
119
+ abstract declareContract(transaction: DeclareContractTransaction, details: InvocationsDetailsWithNonce): Promise<DeclareContractResponse>;
120
+ /**
121
+ * Estimates the fee for a given INVOKE transaction
122
+ * @deprecated Please use getInvokeEstimateFee or getDeclareEstimateFee instead
107
123
  *
108
124
  * @param invocation the invocation object containing:
109
125
  * - contractAddress - the address of the contract
@@ -117,6 +133,52 @@ export declare abstract class ProviderInterface {
117
133
  * @returns the estimated fee
118
134
  */
119
135
  abstract getEstimateFee(invocation: Invocation, details: InvocationsDetailsWithNonce, blockIdentifier: BlockIdentifier): Promise<EstimateFeeResponse>;
136
+ /**
137
+ * Estimates the fee for a given INVOKE transaction
138
+ *
139
+ * @param invocation the invocation object containing:
140
+ * - contractAddress - the address of the contract
141
+ * - entrypoint - the entrypoint of the contract
142
+ * - calldata - (defaults to []) the calldata
143
+ * - signature - (defaults to []) the signature
144
+ * @param blockIdentifier - block identifier
145
+ * @param details - optional details containing:
146
+ * - nonce - optional nonce
147
+ * - version - optional version
148
+ * @returns the estimated fee
149
+ */
150
+ abstract getInvokeEstimateFee(invocation: Invocation, details: InvocationsDetailsWithNonce, blockIdentifier: BlockIdentifier): Promise<EstimateFeeResponse>;
151
+ /**
152
+ * Estimates the fee for a given DECLARE transaction
153
+ *
154
+ * @param transaction transaction payload to be declared containing:
155
+ * - compiled contract code
156
+ * - sender address
157
+ * - signature - (defaults to []) the signature
158
+ * @param details - optional details containing:
159
+ * - nonce
160
+ * - version - optional version
161
+ * - optional maxFee
162
+ * @param blockIdentifier - block identifier
163
+ * @returns the estimated fee
164
+ */
165
+ abstract getDeclareEstimateFee(transaction: DeclareContractTransaction, details: InvocationsDetailsWithNonce, blockIdentifier: BlockIdentifier): Promise<EstimateFeeResponse>;
166
+ /**
167
+ * Estimates the fee for a given DEPLOY_ACCOUNT transaction
168
+ *
169
+ * @param transaction transaction payload to be deployed containing:
170
+ * - classHash
171
+ * - constructorCalldata
172
+ * - addressSalt
173
+ * - signature - (defaults to []) the signature
174
+ * @param details - optional details containing:
175
+ * - nonce
176
+ * - version - optional version
177
+ * - optional maxFee
178
+ * @param blockIdentifier - block identifier
179
+ * @returns the estimated fee
180
+ */
181
+ abstract getDeployAccountEstimateFee(transaction: DeployAccountContractTransaction, details: InvocationsDetailsWithNonce, blockIdentifier: BlockIdentifier): Promise<EstimateFeeResponse>;
120
182
  /**
121
183
  * Wait for the transaction to be accepted
122
184
  * @param txHash - transaction hash
@@ -1,16 +1,19 @@
1
1
  import { StarknetChainId } from '../constants';
2
- import { Call, CallContractResponse, DeclareContractPayload, DeclareContractResponse, DeployContractPayload, DeployContractResponse, EstimateFeeResponse, GetBlockResponse, GetCodeResponse, GetTransactionReceiptResponse, GetTransactionResponse, Invocation, InvocationsDetailsWithNonce, InvokeFunctionResponse } from '../types';
2
+ import { Call, CallContractResponse, DeclareContractResponse, DeployContractPayload, DeployContractResponse, EstimateFeeResponse, GetBlockResponse, GetCodeResponse, GetTransactionReceiptResponse, GetTransactionResponse, Invocation, InvocationsDetailsWithNonce, InvokeFunctionResponse } from '../types';
3
3
  import { RPC } from '../types/api';
4
+ import { DeclareContractTransaction, DeployAccountContractPayload, DeployAccountContractTransaction } from '../types/lib';
4
5
  import { BigNumberish } from '../utils/number';
5
6
  import { ProviderInterface } from './interface';
6
7
  import { BlockIdentifier } from './utils';
7
8
  export declare type RpcProviderOptions = {
8
9
  nodeUrl: string;
9
10
  retries?: number;
11
+ headers?: object;
10
12
  };
11
13
  export declare class RpcProvider implements ProviderInterface {
12
14
  nodeUrl: string;
13
15
  chainId: StarknetChainId;
16
+ headers: object;
14
17
  private responseParser;
15
18
  private retries;
16
19
  constructor(optionsOrProvider: RpcProviderOptions);
@@ -33,11 +36,15 @@ export declare class RpcProvider implements ProviderInterface {
33
36
  getTransactionByBlockIdAndIndex(blockIdentifier: BlockIdentifier, index: number): Promise<RPC.GetTransactionByBlockIdAndIndex>;
34
37
  getTransactionReceipt(txHash: string): Promise<GetTransactionReceiptResponse>;
35
38
  getClass(classHash: RPC.Felt): Promise<RPC.ContractClass>;
36
- getClassAt(contractAddress: string, blockIdentifier: BlockIdentifier): Promise<RPC.ContractClass>;
39
+ getClassAt(contractAddress: string, blockIdentifier?: BlockIdentifier): Promise<RPC.ContractClass>;
37
40
  getCode(_contractAddress: string, _blockIdentifier?: BlockIdentifier): Promise<GetCodeResponse>;
38
41
  getEstimateFee(invocation: Invocation, invocationDetails: InvocationsDetailsWithNonce, blockIdentifier?: BlockIdentifier): Promise<EstimateFeeResponse>;
39
- declareContract({ contract, version, }: DeclareContractPayload): Promise<DeclareContractResponse>;
42
+ getInvokeEstimateFee(invocation: Invocation, invocationDetails: InvocationsDetailsWithNonce, blockIdentifier?: BlockIdentifier): Promise<EstimateFeeResponse>;
43
+ getDeclareEstimateFee({ senderAddress, contractDefinition, signature }: DeclareContractTransaction, details: InvocationsDetailsWithNonce, blockIdentifier?: BlockIdentifier): Promise<EstimateFeeResponse>;
44
+ getDeployAccountEstimateFee({ classHash, constructorCalldata, addressSalt, signature }: DeployAccountContractTransaction, details: InvocationsDetailsWithNonce, blockIdentifier?: BlockIdentifier): Promise<EstimateFeeResponse>;
45
+ declareContract({ contractDefinition, signature, senderAddress }: DeclareContractTransaction, details: InvocationsDetailsWithNonce): Promise<DeclareContractResponse>;
40
46
  deployContract({ contract, constructorCalldata, addressSalt, }: DeployContractPayload): Promise<DeployContractResponse>;
47
+ deployAccountContract({ classHash, constructorCalldata, addressSalt, }: DeployAccountContractPayload): Promise<DeployContractResponse>;
41
48
  invokeFunction(functionInvocation: Invocation, details: InvocationsDetailsWithNonce): Promise<InvokeFunctionResponse>;
42
49
  callContract(call: Call, blockIdentifier?: BlockIdentifier): Promise<CallContractResponse>;
43
50
  traceTransaction(transactionHash: RPC.TransactionHash): Promise<RPC.Trace>;