starknet 4.10.0 → 4.12.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.
@@ -72,7 +72,7 @@ var RpcProvider = /** @class */ (function () {
72
72
  });
73
73
  }
74
74
  RpcProvider.prototype.fetch = function (method, params) {
75
- return (0, fetchPonyfill_1.default)(this.nodeUrl, {
75
+ return (0, fetchPonyfill_1.default)("".concat(this.nodeUrl, "/rpc/v0.2"), {
76
76
  method: 'POST',
77
77
  body: (0, json_1.stringify)({ method: method, jsonrpc: '2.0', params: params, id: 0 }),
78
78
  headers: this.headers,
@@ -153,7 +153,8 @@ var RpcProvider = /** @class */ (function () {
153
153
  });
154
154
  });
155
155
  };
156
- RpcProvider.prototype.getClassHashAt = function (blockIdentifier, contractAddress) {
156
+ RpcProvider.prototype.getClassHashAt = function (contractAddress, blockIdentifier) {
157
+ if (blockIdentifier === void 0) { blockIdentifier = 'pending'; }
157
158
  return __awaiter(this, void 0, void 0, function () {
158
159
  var block_id;
159
160
  return __generator(this, function (_a) {
@@ -193,6 +194,7 @@ var RpcProvider = /** @class */ (function () {
193
194
  });
194
195
  };
195
196
  RpcProvider.prototype.getStateUpdate = function (blockIdentifier) {
197
+ if (blockIdentifier === void 0) { blockIdentifier = 'pending'; }
196
198
  return __awaiter(this, void 0, void 0, function () {
197
199
  var block_id;
198
200
  return __generator(this, function (_a) {
@@ -247,10 +249,20 @@ var RpcProvider = /** @class */ (function () {
247
249
  });
248
250
  });
249
251
  };
250
- RpcProvider.prototype.getClass = function (classHash) {
252
+ RpcProvider.prototype.getClassByHash = function (classHash) {
251
253
  return __awaiter(this, void 0, void 0, function () {
252
254
  return __generator(this, function (_a) {
253
- return [2 /*return*/, this.fetchEndpoint('starknet_getClass', { class_hash: classHash })];
255
+ return [2 /*return*/, this.getClass(classHash)];
256
+ });
257
+ });
258
+ };
259
+ RpcProvider.prototype.getClass = function (classHash, blockIdentifier) {
260
+ if (blockIdentifier === void 0) { blockIdentifier = 'pending'; }
261
+ return __awaiter(this, void 0, void 0, function () {
262
+ var block_id;
263
+ return __generator(this, function (_a) {
264
+ block_id = new utils_1.Block(blockIdentifier).identifier;
265
+ return [2 /*return*/, this.fetchEndpoint('starknet_getClass', { class_hash: classHash, block_id: block_id })];
254
266
  });
255
267
  });
256
268
  };
@@ -270,7 +282,7 @@ var RpcProvider = /** @class */ (function () {
270
282
  RpcProvider.prototype.getCode = function (_contractAddress, _blockIdentifier) {
271
283
  return __awaiter(this, void 0, void 0, function () {
272
284
  return __generator(this, function (_a) {
273
- throw new Error('RPC 0.1.0 does not implement getCode function');
285
+ throw new Error('RPC does not implement getCode function');
274
286
  });
275
287
  });
276
288
  };
@@ -359,46 +371,61 @@ var RpcProvider = /** @class */ (function () {
359
371
  return __awaiter(this, void 0, void 0, function () {
360
372
  return __generator(this, function (_b) {
361
373
  return [2 /*return*/, this.fetchEndpoint('starknet_addDeclareTransaction', {
362
- contract_class: {
363
- program: contractDefinition.program,
364
- entry_points_by_type: contractDefinition.entry_points_by_type,
365
- abi: contractDefinition.abi, // rpc 2.0
374
+ declare_transaction: {
375
+ contract_class: {
376
+ program: contractDefinition.program,
377
+ entry_points_by_type: contractDefinition.entry_points_by_type,
378
+ abi: contractDefinition.abi, // rpc 2.0
379
+ },
380
+ type: 'DECLARE',
381
+ version: (0, number_1.toHex)((0, number_1.toBN)(details.version || 0)),
382
+ max_fee: (0, number_1.toHex)((0, number_1.toBN)(details.maxFee || 0)),
383
+ signature: (0, number_1.bigNumberishArrayToHexadecimalStringArray)(signature || []),
384
+ sender_address: senderAddress,
385
+ nonce: (0, number_1.toHex)((0, number_1.toBN)(details.nonce)),
366
386
  },
367
- version: (0, number_1.toHex)((0, number_1.toBN)(details.version || 0)),
368
- max_fee: (0, number_1.toHex)((0, number_1.toBN)(details.maxFee || 0)),
369
- signature: (0, number_1.bigNumberishArrayToHexadecimalStringArray)(signature || []),
370
- sender_address: senderAddress,
371
- nonce: (0, number_1.toHex)((0, number_1.toBN)(details.nonce)),
372
387
  })];
373
388
  });
374
389
  });
375
390
  };
376
- RpcProvider.prototype.deployContract = function (_a) {
391
+ /**
392
+ * @deprecated This method wont be supported soon, use Account.deploy instead
393
+ */
394
+ RpcProvider.prototype.deployContract = function (_a, details) {
377
395
  var contract = _a.contract, constructorCalldata = _a.constructorCalldata, addressSalt = _a.addressSalt;
378
396
  return __awaiter(this, void 0, void 0, function () {
379
397
  var contractDefinition;
380
398
  return __generator(this, function (_b) {
381
399
  contractDefinition = (0, provider_1.parseContract)(contract);
382
400
  return [2 /*return*/, this.fetchEndpoint('starknet_addDeployTransaction', {
383
- contract_address_salt: addressSalt !== null && addressSalt !== void 0 ? addressSalt : (0, stark_1.randomAddress)(),
384
- constructor_calldata: (0, number_1.bigNumberishArrayToHexadecimalStringArray)(constructorCalldata !== null && constructorCalldata !== void 0 ? constructorCalldata : []),
385
- contract_definition: {
386
- program: contractDefinition.program,
387
- entry_points_by_type: contractDefinition.entry_points_by_type,
388
- abi: contractDefinition.abi, // rpc 2.0
401
+ deploy_transaction: {
402
+ contract_address_salt: addressSalt !== null && addressSalt !== void 0 ? addressSalt : (0, stark_1.randomAddress)(),
403
+ constructor_calldata: (0, number_1.bigNumberishArrayToHexadecimalStringArray)(constructorCalldata !== null && constructorCalldata !== void 0 ? constructorCalldata : []),
404
+ contract_class: {
405
+ program: contractDefinition.program,
406
+ entry_points_by_type: contractDefinition.entry_points_by_type,
407
+ abi: contractDefinition.abi,
408
+ },
409
+ type: 'DEPLOY',
410
+ version: (0, number_1.toHex)((0, number_1.toBN)((details === null || details === void 0 ? void 0 : details.version) || 0)),
389
411
  },
390
412
  })];
391
413
  });
392
414
  });
393
415
  };
394
- RpcProvider.prototype.deployAccountContract = function (_a) {
395
- var classHash = _a.classHash, constructorCalldata = _a.constructorCalldata, addressSalt = _a.addressSalt;
416
+ RpcProvider.prototype.deployAccountContract = function (_a, details) {
417
+ var classHash = _a.classHash, constructorCalldata = _a.constructorCalldata, addressSalt = _a.addressSalt, signature = _a.signature;
396
418
  return __awaiter(this, void 0, void 0, function () {
397
419
  return __generator(this, function (_b) {
398
420
  return [2 /*return*/, this.fetchEndpoint('starknet_addDeployAccountTransaction', {
399
421
  constructor_calldata: (0, number_1.bigNumberishArrayToHexadecimalStringArray)(constructorCalldata || []),
400
422
  class_hash: (0, number_1.toHex)((0, number_1.toBN)(classHash)),
401
423
  contract_address_salt: (0, number_1.toHex)((0, number_1.toBN)(addressSalt || 0)),
424
+ type: 'DEPLOY',
425
+ max_fee: (0, number_1.toHex)((0, number_1.toBN)(details.maxFee || 0)),
426
+ version: (0, number_1.toHex)((0, number_1.toBN)(details.version || 0)),
427
+ signature: (0, number_1.bigNumberishArrayToHexadecimalStringArray)(signature || []),
428
+ nonce: (0, number_1.toHex)((0, number_1.toBN)(details.nonce)),
402
429
  })];
403
430
  });
404
431
  });
@@ -407,13 +434,15 @@ var RpcProvider = /** @class */ (function () {
407
434
  return __awaiter(this, void 0, void 0, function () {
408
435
  return __generator(this, function (_a) {
409
436
  return [2 /*return*/, this.fetchEndpoint('starknet_addInvokeTransaction', {
410
- function_invocation: {
411
- contract_address: functionInvocation.contractAddress,
437
+ invoke_transaction: {
438
+ sender_address: functionInvocation.contractAddress,
412
439
  calldata: (0, provider_1.parseCalldata)(functionInvocation.calldata),
440
+ type: 'INVOKE',
441
+ max_fee: (0, number_1.toHex)((0, number_1.toBN)(details.maxFee || 0)),
442
+ version: (0, number_1.toHex)((0, number_1.toBN)(details.version || 0)),
443
+ signature: (0, number_1.bigNumberishArrayToHexadecimalStringArray)(functionInvocation.signature || []),
444
+ nonce: (0, number_1.toHex)((0, number_1.toBN)(details.nonce)),
413
445
  },
414
- signature: (0, number_1.bigNumberishArrayToHexadecimalStringArray)(functionInvocation.signature || []),
415
- max_fee: (0, number_1.toHex)((0, number_1.toBN)(details.maxFee || 0)),
416
- version: (0, number_1.toHex)((0, number_1.toBN)(details.version || 0)),
417
446
  })];
418
447
  });
419
448
  });
@@ -459,7 +488,7 @@ var RpcProvider = /** @class */ (function () {
459
488
  RpcProvider.prototype.waitForTransaction = function (txHash, retryInterval) {
460
489
  if (retryInterval === void 0) { retryInterval = 8000; }
461
490
  return __awaiter(this, void 0, void 0, function () {
462
- var retries, onchain, successStates, errorStates, res, message, error, error_2;
491
+ var retries, onchain, successStates, errorStates, res, error, message, error, error_2;
463
492
  return __generator(this, function (_a) {
464
493
  switch (_a.label) {
465
494
  case 0:
@@ -481,6 +510,10 @@ var RpcProvider = /** @class */ (function () {
481
510
  return [4 /*yield*/, this.getTransactionReceipt(txHash)];
482
511
  case 4:
483
512
  res = _a.sent();
513
+ if (!('status' in res)) {
514
+ error = new Error('pending transaction');
515
+ throw error;
516
+ }
484
517
  if (res.status && successStates.includes(res.status)) {
485
518
  onchain = true;
486
519
  }
@@ -519,6 +552,7 @@ var RpcProvider = /** @class */ (function () {
519
552
  * @returns Number of transactions
520
553
  */
521
554
  RpcProvider.prototype.getTransactionCount = function (blockIdentifier) {
555
+ if (blockIdentifier === void 0) { blockIdentifier = 'pending'; }
522
556
  return __awaiter(this, void 0, void 0, function () {
523
557
  var block_id;
524
558
  return __generator(this, function (_a) {
@@ -38,6 +38,8 @@ export declare class SequencerProvider implements ProviderInterface {
38
38
  getTransaction(txHash: BigNumberish): Promise<GetTransactionResponse>;
39
39
  getTransactionReceipt(txHash: BigNumberish): Promise<GetTransactionReceiptResponse>;
40
40
  getClassAt(contractAddress: string, blockIdentifier?: BlockIdentifier): Promise<ContractClass>;
41
+ getClassHashAt(contractAddress: string, blockIdentifier?: BlockIdentifier): Promise<string>;
42
+ getClassByHash(classHash: string): Promise<ContractClass>;
41
43
  invokeFunction(functionInvocation: Invocation, details: InvocationsDetailsWithNonce): Promise<InvokeFunctionResponse>;
42
44
  deployContract({ contract, constructorCalldata, addressSalt, }: DeployContractPayload): Promise<DeployContractResponse>;
43
45
  deployAccountContract({ classHash, constructorCalldata, addressSalt, signature }: DeployAccountContractTransaction, details: InvocationsDetailsWithNonce): Promise<DeployContractResponse>;
@@ -326,6 +326,21 @@ var SequencerProvider = /** @class */ (function () {
326
326
  });
327
327
  });
328
328
  };
329
+ SequencerProvider.prototype.getClassHashAt = function (contractAddress, blockIdentifier) {
330
+ if (blockIdentifier === void 0) { blockIdentifier = 'pending'; }
331
+ return __awaiter(this, void 0, void 0, function () {
332
+ return __generator(this, function (_a) {
333
+ return [2 /*return*/, this.fetchEndpoint('get_class_hash_at', { blockIdentifier: blockIdentifier, contractAddress: contractAddress })];
334
+ });
335
+ });
336
+ };
337
+ SequencerProvider.prototype.getClassByHash = function (classHash) {
338
+ return __awaiter(this, void 0, void 0, function () {
339
+ return __generator(this, function (_a) {
340
+ return [2 /*return*/, this.fetchEndpoint('get_class_by_hash', { classHash: classHash }).then(provider_1.parseContract)];
341
+ });
342
+ });
343
+ };
329
344
  SequencerProvider.prototype.invokeFunction = function (functionInvocation, details) {
330
345
  var _a, _b;
331
346
  return __awaiter(this, void 0, void 0, function () {