starknet 3.10.1 → 3.11.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 (51) hide show
  1. package/CHANGELOG.md +26 -0
  2. package/__tests__/account.test.ts +3 -1
  3. package/__tests__/accountContract.test.ts +3 -1
  4. package/__tests__/provider.test.ts +7 -7
  5. package/__tests__/utils/address.test.ts +30 -1
  6. package/dist/provider/default.d.ts +2 -6
  7. package/dist/provider/default.js +15 -11
  8. package/dist/provider/interface.d.ts +2 -5
  9. package/dist/signer/index.d.ts +0 -1
  10. package/dist/signer/index.js +0 -1
  11. package/dist/types/api.d.ts +10 -2
  12. package/dist/utils/address.d.ts +5 -2
  13. package/dist/utils/address.js +24 -5
  14. package/dist/utils/encode.js +1 -1
  15. package/package.json +2 -4
  16. package/provider/default.d.ts +2 -9
  17. package/provider/default.js +19 -22
  18. package/provider/interface.d.ts +2 -8
  19. package/signer/index.d.ts +0 -1
  20. package/signer/index.js +0 -1
  21. package/src/provider/default.ts +17 -15
  22. package/src/provider/interface.ts +2 -8
  23. package/src/signer/index.ts +0 -1
  24. package/src/types/api.ts +11 -2
  25. package/src/utils/address.ts +29 -8
  26. package/src/utils/encode.ts +1 -1
  27. package/types/api.d.ts +11 -2
  28. package/utils/address.d.ts +5 -2
  29. package/utils/address.js +35 -5
  30. package/utils/encode.js +3 -1
  31. package/www/code-examples/account.js +8 -5
  32. package/www/code-examples/amm.js +13 -18
  33. package/www/code-examples/erc20.js +6 -3
  34. package/www/docs/API/account.md +94 -0
  35. package/www/docs/API/changelog.md +15 -0
  36. package/www/docs/API/contract.md +73 -2
  37. package/www/docs/API/contractFacotry.md +42 -0
  38. package/www/docs/API/index.md +0 -1
  39. package/www/docs/API/provider.md +204 -1
  40. package/www/docs/API/signer.md +35 -0
  41. package/www/docs/API/utils.md +34 -0
  42. package/www/docusaurus.config.js +3 -4
  43. package/www/guides/account.md +1 -1
  44. package/www/guides/erc20.md +7 -0
  45. package/www/guides/intro.md +1 -0
  46. package/www/sidebars.js +1 -1
  47. package/dist/signer/ledger.d.ts +0 -12
  48. package/dist/signer/ledger.js +0 -140
  49. package/signer/ledger.d.ts +0 -15
  50. package/signer/ledger.js +0 -250
  51. package/src/signer/ledger.ts +0 -86
package/CHANGELOG.md CHANGED
@@ -1,3 +1,29 @@
1
+ # [3.11.0](https://github.com/seanjameshan/starknet.js/compare/v3.10.3...v3.11.0) (2022-05-11)
2
+
3
+ ### Bug Fixes
4
+
5
+ - review ([9ee4987](https://github.com/seanjameshan/starknet.js/commit/9ee498788185a35a75f2b429b3f1ec55dc4ee2a3))
6
+ - tests ([f535edb](https://github.com/seanjameshan/starknet.js/commit/f535edbef8da6050e54575792926488774e3ed0f))
7
+ - transaction receipt ([806eb7d](https://github.com/seanjameshan/starknet.js/commit/806eb7d63a01e158231f7b63cc4fc1fb0c30717e))
8
+ - use npm again ([3b9e176](https://github.com/seanjameshan/starknet.js/commit/3b9e176812f6401e167a207db2d9ff3686260e13))
9
+
10
+ ### Features
11
+
12
+ - add checksum addresses ([2d32ed8](https://github.com/seanjameshan/starknet.js/commit/2d32ed828f908090642a42d9f6620f050a75b43a))
13
+ - use BigNumber for estimate fee amount ([751c2ed](https://github.com/seanjameshan/starknet.js/commit/751c2edf89d019f365f5fba8123a9df0320ff543))
14
+
15
+ ## [3.10.3](https://github.com/seanjameshan/starknet.js/compare/v3.10.2...v3.10.3) (2022-05-04)
16
+
17
+ ### Bug Fixes
18
+
19
+ - **encode:** maximum call stack size exceeded ([3cd8195](https://github.com/seanjameshan/starknet.js/commit/3cd8195d0fcde7d2cf6460959bb2c9f45ef7d066))
20
+
21
+ ## [3.10.2](https://github.com/seanjameshan/starknet.js/compare/v3.10.1...v3.10.2) (2022-04-27)
22
+
23
+ ### Bug Fixes
24
+
25
+ - **tests:** fix getBlock blocks ([c0422b7](https://github.com/seanjameshan/starknet.js/commit/c0422b7d963639d34082731f6efbe3f0dd2c3c4d))
26
+
1
27
  ## [3.10.1](https://github.com/seanjameshan/starknet.js/compare/v3.10.0...v3.10.1) (2022-04-20)
2
28
 
3
29
  ### Bug Fixes
@@ -1,3 +1,5 @@
1
+ import { isBN } from 'bn.js';
2
+
1
3
  import typedDataExample from '../__mocks__/typedDataExample.json';
2
4
  import { Account, Contract, defaultProvider, ec, number, stark } from '../src';
3
5
  import { toBN } from '../src/utils/number';
@@ -50,7 +52,7 @@ describe('deploy and test Wallet', () => {
50
52
  entrypoint: 'transfer',
51
53
  calldata: [erc20.address, '10'],
52
54
  });
53
- expect(typeof amount).toBe('number');
55
+ expect(isBN(amount)).toBe(true);
54
56
  expect(typeof unit).toBe('string');
55
57
  });
56
58
 
@@ -36,7 +36,9 @@ test('build tx', async () => {
36
36
 
37
37
  const selector = hash.getSelectorFromName('transfer');
38
38
 
39
- expect(selector).toMatchInlineSnapshot();
39
+ expect(selector).toMatchInlineSnapshot(
40
+ `"0x83afd3f4caedc6eebf44246fe54e38c95e3179a5ec9ea81740eca5b482d12e"`
41
+ );
40
42
 
41
43
  const calls = [{ contractAddress: '1', entrypoint: 'transfer', calldata: ['6', '7'] }];
42
44
  const calldata = fromCallsToExecuteCalldataWithNonce(calls, 0);
@@ -10,15 +10,15 @@ describe('defaultProvider', () => {
10
10
  expect(typeof GpsStatementVerifier).toBe('string');
11
11
  expect(typeof Starknet).toBe('string');
12
12
  });
13
- test('getBlock(blockHash=0x3bca19c3d5983e21e9537669b15f951f0664f0747a083dc714e0b9648b8575d, blockNumber=undefined)', () => {
13
+ test('getBlock(blockHash=0x26e33ad2807590b93e98a04e703d7d64d4ead13591b50984ae558bdbe8fbcd2, blockNumber=undefined)', () => {
14
14
  return expect(
15
15
  defaultProvider.getBlock(
16
- '0x3bca19c3d5983e21e9537669b15f951f0664f0747a083dc714e0b9648b8575d'
16
+ '0x26e33ad2807590b93e98a04e703d7d64d4ead13591b50984ae558bdbe8fbcd2'
17
17
  )
18
18
  ).resolves.not.toThrow();
19
19
  });
20
- test('getBlock(blockHash=undefined, blockNumber=36657)', () => {
21
- return expect(defaultProvider.getBlock(36657)).resolves.not.toThrow();
20
+ test('getBlock(blockHash=undefined, blockNumber=168890)', () => {
21
+ return expect(defaultProvider.getBlock(168890)).resolves.not.toThrow();
22
22
  });
23
23
  test('getBlock(blockHash=undefined, blockNumber=null)', () => {
24
24
  return expect(defaultProvider.getBlock()).resolves.not.toThrow();
@@ -76,9 +76,9 @@ describe('defaultProvider', () => {
76
76
 
77
77
  test('getTransactionReceipt', async () => {
78
78
  return expect(
79
- defaultProvider.getTransactionReceipt({
80
- txHash: '0x37013e1cb9c133e6fe51b4b371b76b317a480f56d80576730754c1662582348',
81
- })
79
+ defaultProvider.getTransactionReceipt(
80
+ '0x37013e1cb9c133e6fe51b4b371b76b317a480f56d80576730754c1662582348'
81
+ )
82
82
  ).resolves.not.toThrow();
83
83
  });
84
84
 
@@ -1,4 +1,9 @@
1
- import { addAddressPadding, validateAndParseAddress } from '../../src/utils/address';
1
+ import {
2
+ addAddressPadding,
3
+ getChecksumAddress,
4
+ validateAndParseAddress,
5
+ validateChecksumAddress,
6
+ } from '../../src/utils/address';
2
7
  // import { addHexPrefix, removeHexPrefix } from '../../src/utils/encode';
3
8
 
4
9
  describe('validateAndParseAddress', () => {
@@ -14,3 +19,27 @@ describe('validateAndParseAddress', () => {
14
19
  return expect(validateAndParseAddress(addr)).toEqual(`${addAddressPadding(addr)}`);
15
20
  });
16
21
  });
22
+
23
+ describe('address checksums', () => {
24
+ test('should be able to calculate checksum address', () => {
25
+ const checksumAddress = getChecksumAddress(
26
+ '0x2fd23d9182193775423497fc0c472e156c57c69e4089a1967fb288a2d84e914'
27
+ );
28
+ expect(checksumAddress).toEqual(
29
+ '0x02FD23D9182193775423497Fc0c472E156C57C69E4089a1967fb288a2D84e914'
30
+ );
31
+ });
32
+ test('should be able to verify checksum address', () => {
33
+ const isValid = validateChecksumAddress(
34
+ '0x02FD23D9182193775423497Fc0c472E156C57C69E4089a1967fb288a2D84e914'
35
+ );
36
+ expect(isValid).toEqual(true);
37
+ });
38
+ test('calculated checksum address should validate', () => {
39
+ const checksumAddress = getChecksumAddress(
40
+ '0x26cb0b500d175111341fabb53bf7fa4f5a0b8c5cbb31896cec1e8383a5edda8'
41
+ );
42
+ const isValid = validateChecksumAddress(checksumAddress);
43
+ expect(isValid).toEqual(true);
44
+ });
45
+ });
@@ -1,5 +1,5 @@
1
1
  import { StarknetChainId } from '../constants';
2
- import { Abi, AddTransactionResponse, Call, CallContractResponse, DeployContractPayload, Endpoints, GetBlockResponse, GetCodeResponse, GetContractAddressesResponse, GetTransactionResponse, GetTransactionStatusResponse, GetTransactionTraceResponse, Invocation, TransactionReceipt } from '../types';
2
+ import { Abi, AddTransactionResponse, Call, CallContractResponse, DeployContractPayload, Endpoints, GetBlockResponse, GetCodeResponse, GetContractAddressesResponse, GetTransactionResponse, GetTransactionStatusResponse, GetTransactionTraceResponse, Invocation, TransactionReceiptResponse } from '../types';
3
3
  import { BigNumberish } from '../utils/number';
4
4
  import { ProviderInterface } from './interface';
5
5
  import { BlockIdentifier } from './utils';
@@ -90,13 +90,9 @@ export declare class Provider implements ProviderInterface {
90
90
  * [Reference] (https://github.com/starkware-libs/cairo-lang/blob/master/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L104-L111)
91
91
  *
92
92
  * @param txHash
93
- * @param txId
94
93
  * @returns the transaction receipt object
95
94
  */
96
- getTransactionReceipt({ txHash, txId, }: {
97
- txHash?: BigNumberish;
98
- txId?: BigNumberish;
99
- }): Promise<TransactionReceipt>;
95
+ getTransactionReceipt(txHash: BigNumberish): Promise<TransactionReceiptResponse>;
100
96
  /**
101
97
  * Gets the transaction information from a tx id.
102
98
  *
@@ -196,6 +196,16 @@ var Provider = /** @class */ (function () {
196
196
  _d.trys.push([1, 3, , 4]);
197
197
  return [4 /*yield*/, axios_1.default.request({
198
198
  method: method,
199
+ transformResponse: endpoint === 'estimate_fee'
200
+ ? function (res) {
201
+ return (0, json_1.parse)(res, function (_, v) {
202
+ if (v && typeof v === 'bigint') {
203
+ return (0, number_1.toBN)(v.toString());
204
+ }
205
+ return v;
206
+ });
207
+ }
208
+ : axios_1.default.defaults.transformResponse,
199
209
  url: (0, url_join_1.default)(baseUrl, endpoint, queryString),
200
210
  data: (0, json_1.stringify)(request),
201
211
  headers: headers,
@@ -330,20 +340,14 @@ var Provider = /** @class */ (function () {
330
340
  * [Reference] (https://github.com/starkware-libs/cairo-lang/blob/master/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L104-L111)
331
341
  *
332
342
  * @param txHash
333
- * @param txId
334
343
  * @returns the transaction receipt object
335
344
  */
336
- Provider.prototype.getTransactionReceipt = function (_a) {
337
- var txHash = _a.txHash, txId = _a.txId;
345
+ Provider.prototype.getTransactionReceipt = function (txHash) {
338
346
  return __awaiter(this, void 0, void 0, function () {
339
- var data;
340
- return __generator(this, function (_b) {
341
- switch (_b.label) {
342
- case 0: return [4 /*yield*/, axios_1.default.get((0, url_join_1.default)(this.feederGatewayUrl, 'get_transaction_receipt', "?" + (0, utils_1.txIdentifier)(txHash, txId)))];
343
- case 1:
344
- data = (_b.sent()).data;
345
- return [2 /*return*/, data];
346
- }
347
+ var txHashHex;
348
+ return __generator(this, function (_a) {
349
+ txHashHex = (0, number_1.toHex)((0, number_1.toBN)(txHash));
350
+ return [2 /*return*/, this.fetchEndpoint('get_transaction_receipt', { transactionHash: txHashHex })];
347
351
  });
348
352
  });
349
353
  };
@@ -1,5 +1,5 @@
1
1
  import { StarknetChainId } from '../constants';
2
- import type { AddTransactionResponse, Call, CallContractResponse, DeployContractPayload, GetBlockResponse, GetCodeResponse, GetContractAddressesResponse, GetTransactionResponse, GetTransactionStatusResponse, Invocation, TransactionReceipt } from '../types';
2
+ import type { AddTransactionResponse, Call, CallContractResponse, DeployContractPayload, GetBlockResponse, GetCodeResponse, GetContractAddressesResponse, GetTransactionResponse, GetTransactionStatusResponse, Invocation, TransactionReceiptResponse } from '../types';
3
3
  import type { BigNumberish } from '../utils/number';
4
4
  import { BlockIdentifier } from './utils';
5
5
  export declare abstract class ProviderInterface {
@@ -74,10 +74,7 @@ export declare abstract class ProviderInterface {
74
74
  * @returns the transacton object { transaction_id, status, transaction, block_number?, block_number?, transaction_index?, transaction_failure_reason? }
75
75
  */
76
76
  abstract getTransaction(txHash: BigNumberish): Promise<GetTransactionResponse>;
77
- abstract getTransactionReceipt({ txHash, txId, }: {
78
- txHash?: BigNumberish;
79
- txId?: BigNumberish;
80
- }): Promise<TransactionReceipt>;
77
+ abstract getTransactionReceipt(txHash: BigNumberish): Promise<TransactionReceiptResponse>;
81
78
  /**
82
79
  * Deploys a given compiled contract (json) to starknet
83
80
  *
@@ -1,3 +1,2 @@
1
1
  export * from './interface';
2
2
  export * from './default';
3
- export * from './ledger';
@@ -12,4 +12,3 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
12
12
  Object.defineProperty(exports, "__esModule", { value: true });
13
13
  __exportStar(require("./interface"), exports);
14
14
  __exportStar(require("./default"), exports);
15
- __exportStar(require("./ledger"), exports);
@@ -1,3 +1,4 @@
1
+ import BN from 'bn.js';
1
2
  import { BlockIdentifier } from '../provider/utils';
2
3
  import { BigNumberish } from '../utils/number';
3
4
  import { Abi, BlockNumber, CompressedCompiledContract, EntryPointType, RawCalldata, Signature, Status, TransactionStatus } from './lib';
@@ -33,6 +34,13 @@ export declare type Endpoints = {
33
34
  REQUEST: never;
34
35
  RESPONSE: GetTransactionTraceResponse;
35
36
  };
37
+ get_transaction_receipt: {
38
+ QUERY: {
39
+ transactionHash: string;
40
+ };
41
+ REQUEST: never;
42
+ RESPONSE: TransactionReceiptResponse;
43
+ };
36
44
  get_storage_at: {
37
45
  QUERY: {
38
46
  contractAddress: string;
@@ -189,7 +197,7 @@ export declare type AddTransactionResponse = {
189
197
  transaction_hash: string;
190
198
  address?: string;
191
199
  };
192
- export declare type TransactionReceipt = {
200
+ export declare type TransactionReceiptResponse = {
193
201
  status: Status;
194
202
  transaction_hash: string;
195
203
  transaction_index: number;
@@ -199,7 +207,7 @@ export declare type TransactionReceipt = {
199
207
  events: string[];
200
208
  };
201
209
  export declare type EstimateFeeResponse = {
202
- amount: number;
210
+ amount: BN;
203
211
  unit: string;
204
212
  };
205
213
  export declare type RawArgs = {
@@ -1,2 +1,5 @@
1
- export declare function addAddressPadding(address: string): string;
2
- export declare function validateAndParseAddress(address: string): string;
1
+ import { BigNumberish } from './number';
2
+ export declare function addAddressPadding(address: BigNumberish): string;
3
+ export declare function validateAndParseAddress(address: BigNumberish): string;
4
+ export declare function getChecksumAddress(address: BigNumberish): string;
5
+ export declare function validateChecksumAddress(address: string): boolean;
@@ -1,17 +1,17 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.validateAndParseAddress = exports.addAddressPadding = void 0;
3
+ exports.validateChecksumAddress = exports.getChecksumAddress = exports.validateAndParseAddress = exports.addAddressPadding = void 0;
4
+ /* eslint-disable no-bitwise */
5
+ var bytes_1 = require("@ethersproject/bytes");
4
6
  var constants_1 = require("../constants");
5
7
  var encode_1 = require("./encode");
8
+ var hash_1 = require("./hash");
6
9
  var number_1 = require("./number");
7
10
  function addAddressPadding(address) {
8
- return (0, encode_1.addHexPrefix)((0, encode_1.removeHexPrefix)(address).padStart(64, '0'));
11
+ return (0, encode_1.addHexPrefix)((0, encode_1.removeHexPrefix)((0, number_1.toHex)((0, number_1.toBN)(address))).padStart(64, '0'));
9
12
  }
10
13
  exports.addAddressPadding = addAddressPadding;
11
14
  function validateAndParseAddress(address) {
12
- if (typeof address !== 'string') {
13
- throw new Error('Invalid Address Type');
14
- }
15
15
  (0, number_1.assertInRange)(address, constants_1.ZERO, constants_1.MASK_251, 'Starknet Address');
16
16
  var result = addAddressPadding(address);
17
17
  if (!result.match(/^(0x)?[0-9a-fA-F]{64}$/)) {
@@ -20,3 +20,22 @@ function validateAndParseAddress(address) {
20
20
  return result;
21
21
  }
22
22
  exports.validateAndParseAddress = validateAndParseAddress;
23
+ // from https://github.com/ethers-io/ethers.js/blob/fc1e006575d59792fa97b4efb9ea2f8cca1944cf/packages/address/src.ts/index.ts#L12
24
+ function getChecksumAddress(address) {
25
+ var chars = (0, encode_1.removeHexPrefix)(validateAndParseAddress(address)).toLowerCase().split('');
26
+ var hashed = (0, bytes_1.arrayify)((0, hash_1.pedersen)([0, address]), { hexPad: 'left' }); // as the hash will be 251 bits (63 chars) we need to pad it to 64 chars without changing the number value ("left")
27
+ for (var i = 0; i < chars.length; i += 2) {
28
+ if (hashed[i >> 1] >> 4 >= 8) {
29
+ chars[i] = chars[i].toUpperCase();
30
+ }
31
+ if ((hashed[i >> 1] & 0x0f) >= 8) {
32
+ chars[i + 1] = chars[i + 1].toUpperCase();
33
+ }
34
+ }
35
+ return (0, encode_1.addHexPrefix)(chars.join(''));
36
+ }
37
+ exports.getChecksumAddress = getChecksumAddress;
38
+ function validateChecksumAddress(address) {
39
+ return getChecksumAddress(address) === address;
40
+ }
41
+ exports.validateChecksumAddress = validateChecksumAddress;
@@ -30,7 +30,7 @@ exports.utf8ToArray = exports.sanitizeHex = exports.sanitizeBytes = exports.calc
30
30
  exports.IS_BROWSER = typeof window !== 'undefined';
31
31
  var STRING_ZERO = '0';
32
32
  function arrayBufferToString(array) {
33
- return String.fromCharCode.apply(null, array);
33
+ return new Uint8Array(array).reduce(function (data, byte) { return data + String.fromCharCode(byte); }, '');
34
34
  }
35
35
  exports.arrayBufferToString = arrayBufferToString;
36
36
  function btoaUniversal(b) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "starknet",
3
- "version": "3.10.1",
3
+ "version": "3.11.0",
4
4
  "description": "JavaScript library for StarkNet",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -61,9 +61,7 @@
61
61
  "typescript": "^4.4.4"
62
62
  },
63
63
  "dependencies": {
64
- "@ledgerhq/hw-app-eth": "^6.26.0",
65
- "@ledgerhq/hw-transport": "^6.24.1",
66
- "@ledgerhq/hw-transport-webhid": "^6.24.1",
64
+ "@ethersproject/bytes": "^5.6.1",
67
65
  "axios": "^0.23.0",
68
66
  "bn.js": "^5.2.0",
69
67
  "elliptic": "^6.5.4",
@@ -13,7 +13,7 @@ import {
13
13
  GetTransactionStatusResponse,
14
14
  GetTransactionTraceResponse,
15
15
  Invocation,
16
- TransactionReceipt,
16
+ TransactionReceiptResponse,
17
17
  } from '../types';
18
18
  import { BigNumberish } from '../utils/number';
19
19
  import { ProviderInterface } from './interface';
@@ -127,16 +127,9 @@ export declare class Provider implements ProviderInterface {
127
127
  * [Reference] (https://github.com/starkware-libs/cairo-lang/blob/master/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L104-L111)
128
128
  *
129
129
  * @param txHash
130
- * @param txId
131
130
  * @returns the transaction receipt object
132
131
  */
133
- getTransactionReceipt({
134
- txHash,
135
- txId,
136
- }: {
137
- txHash?: BigNumberish;
138
- txId?: BigNumberish;
139
- }): Promise<TransactionReceipt>;
132
+ getTransactionReceipt(txHash: BigNumberish): Promise<TransactionReceiptResponse>;
140
133
  /**
141
134
  * Gets the transaction information from a tx id.
142
135
  *
@@ -315,6 +315,17 @@ var Provider = /** @class */ (function () {
315
315
  4 /*yield*/,
316
316
  axios_1.default.request({
317
317
  method: method,
318
+ transformResponse:
319
+ endpoint === 'estimate_fee'
320
+ ? function (res) {
321
+ return (0, json_1.parse)(res, function (_, v) {
322
+ if (v && typeof v === 'bigint') {
323
+ return (0, number_1.toBN)(v.toString());
324
+ }
325
+ return v;
326
+ });
327
+ }
328
+ : axios_1.default.defaults.transformResponse,
318
329
  url: (0, url_join_1.default)(baseUrl, endpoint, queryString),
319
330
  data: (0, json_1.stringify)(request),
320
331
  headers: headers,
@@ -492,31 +503,17 @@ var Provider = /** @class */ (function () {
492
503
  * [Reference] (https://github.com/starkware-libs/cairo-lang/blob/master/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L104-L111)
493
504
  *
494
505
  * @param txHash
495
- * @param txId
496
506
  * @returns the transaction receipt object
497
507
  */
498
- Provider.prototype.getTransactionReceipt = function (_a) {
499
- var txHash = _a.txHash,
500
- txId = _a.txId;
508
+ Provider.prototype.getTransactionReceipt = function (txHash) {
501
509
  return __awaiter(this, void 0, void 0, function () {
502
- var data;
503
- return __generator(this, function (_b) {
504
- switch (_b.label) {
505
- case 0:
506
- return [
507
- 4 /*yield*/,
508
- axios_1.default.get(
509
- (0, url_join_1.default)(
510
- this.feederGatewayUrl,
511
- 'get_transaction_receipt',
512
- '?' + (0, utils_1.txIdentifier)(txHash, txId)
513
- )
514
- ),
515
- ];
516
- case 1:
517
- data = _b.sent().data;
518
- return [2 /*return*/, data];
519
- }
510
+ var txHashHex;
511
+ return __generator(this, function (_a) {
512
+ txHashHex = (0, number_1.toHex)((0, number_1.toBN)(txHash));
513
+ return [
514
+ 2 /*return*/,
515
+ this.fetchEndpoint('get_transaction_receipt', { transactionHash: txHashHex }),
516
+ ];
520
517
  });
521
518
  });
522
519
  };
@@ -10,7 +10,7 @@ import type {
10
10
  GetTransactionResponse,
11
11
  GetTransactionStatusResponse,
12
12
  Invocation,
13
- TransactionReceipt,
13
+ TransactionReceiptResponse,
14
14
  } from '../types';
15
15
  import type { BigNumberish } from '../utils/number';
16
16
  import { BlockIdentifier } from './utils';
@@ -96,13 +96,7 @@ export declare abstract class ProviderInterface {
96
96
  * @returns the transacton object { transaction_id, status, transaction, block_number?, block_number?, transaction_index?, transaction_failure_reason? }
97
97
  */
98
98
  abstract getTransaction(txHash: BigNumberish): Promise<GetTransactionResponse>;
99
- abstract getTransactionReceipt({
100
- txHash,
101
- txId,
102
- }: {
103
- txHash?: BigNumberish;
104
- txId?: BigNumberish;
105
- }): Promise<TransactionReceipt>;
99
+ abstract getTransactionReceipt(txHash: BigNumberish): Promise<TransactionReceiptResponse>;
106
100
  /**
107
101
  * Deploys a given compiled contract (json) to starknet
108
102
  *
package/signer/index.d.ts CHANGED
@@ -1,3 +1,2 @@
1
1
  export * from './interface';
2
2
  export * from './default';
3
- export * from './ledger';
package/signer/index.js CHANGED
@@ -25,4 +25,3 @@ var __exportStar =
25
25
  Object.defineProperty(exports, '__esModule', { value: true });
26
26
  __exportStar(require('./interface'), exports);
27
27
  __exportStar(require('./default'), exports);
28
- __exportStar(require('./ledger'), exports);
@@ -10,6 +10,7 @@ import {
10
10
  CompiledContract,
11
11
  DeployContractPayload,
12
12
  Endpoints,
13
+ EstimateFeeResponse,
13
14
  GetBlockResponse,
14
15
  GetCodeResponse,
15
16
  GetContractAddressesResponse,
@@ -17,14 +18,14 @@ import {
17
18
  GetTransactionStatusResponse,
18
19
  GetTransactionTraceResponse,
19
20
  Invocation,
20
- TransactionReceipt,
21
+ TransactionReceiptResponse,
21
22
  } from '../types';
22
23
  import { getSelectorFromName } from '../utils/hash';
23
24
  import { parse, stringify } from '../utils/json';
24
25
  import { BigNumberish, bigNumberishArrayToDecimalStringArray, toBN, toHex } from '../utils/number';
25
26
  import { compressProgram, randomAddress } from '../utils/stark';
26
27
  import { ProviderInterface } from './interface';
27
- import { BlockIdentifier, getFormattedBlockIdentifier, txIdentifier } from './utils';
28
+ import { BlockIdentifier, getFormattedBlockIdentifier } from './utils';
28
29
 
29
30
  type NetworkName = 'mainnet-alpha' | 'goerli-alpha';
30
31
 
@@ -153,6 +154,17 @@ export class Provider implements ProviderInterface {
153
154
  try {
154
155
  const { data } = await axios.request<Endpoints[T]['RESPONSE']>({
155
156
  method,
157
+ transformResponse:
158
+ endpoint === 'estimate_fee'
159
+ ? (res): EstimateFeeResponse => {
160
+ return parse(res, (_, v) => {
161
+ if (v && typeof v === 'bigint') {
162
+ return toBN(v.toString());
163
+ }
164
+ return v;
165
+ });
166
+ }
167
+ : axios.defaults.transformResponse,
156
168
  url: urljoin(baseUrl, endpoint, queryString),
157
169
  data: stringify(request),
158
170
  headers,
@@ -272,22 +284,12 @@ export class Provider implements ProviderInterface {
272
284
  * [Reference] (https://github.com/starkware-libs/cairo-lang/blob/master/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L104-L111)
273
285
  *
274
286
  * @param txHash
275
- * @param txId
276
287
  * @returns the transaction receipt object
277
288
  */
278
289
 
279
- public async getTransactionReceipt({
280
- txHash,
281
- txId,
282
- }: {
283
- txHash?: BigNumberish;
284
- txId?: BigNumberish;
285
- }): Promise<TransactionReceipt> {
286
- const { data } = await axios.get<TransactionReceipt>(
287
- urljoin(this.feederGatewayUrl, 'get_transaction_receipt', `?${txIdentifier(txHash, txId)}`)
288
- );
289
-
290
- return data;
290
+ public async getTransactionReceipt(txHash: BigNumberish): Promise<TransactionReceiptResponse> {
291
+ const txHashHex = toHex(toBN(txHash));
292
+ return this.fetchEndpoint('get_transaction_receipt', { transactionHash: txHashHex });
291
293
  }
292
294
 
293
295
  /**
@@ -10,7 +10,7 @@ import type {
10
10
  GetTransactionResponse,
11
11
  GetTransactionStatusResponse,
12
12
  Invocation,
13
- TransactionReceipt,
13
+ TransactionReceiptResponse,
14
14
  } from '../types';
15
15
  import type { BigNumberish } from '../utils/number';
16
16
  import { BlockIdentifier } from './utils';
@@ -109,13 +109,7 @@ export abstract class ProviderInterface {
109
109
  */
110
110
  public abstract getTransaction(txHash: BigNumberish): Promise<GetTransactionResponse>;
111
111
 
112
- public abstract getTransactionReceipt({
113
- txHash,
114
- txId,
115
- }: {
116
- txHash?: BigNumberish;
117
- txId?: BigNumberish;
118
- }): Promise<TransactionReceipt>;
112
+ public abstract getTransactionReceipt(txHash: BigNumberish): Promise<TransactionReceiptResponse>;
119
113
 
120
114
  /**
121
115
  * Deploys a given compiled contract (json) to starknet
@@ -1,3 +1,2 @@
1
1
  export * from './interface';
2
2
  export * from './default';
3
- export * from './ledger';
package/src/types/api.ts CHANGED
@@ -1,3 +1,5 @@
1
+ import BN from 'bn.js';
2
+
1
3
  import { BlockIdentifier } from '../provider/utils';
2
4
  import { BigNumberish } from '../utils/number';
3
5
  import {
@@ -43,6 +45,13 @@ export type Endpoints = {
43
45
  REQUEST: never;
44
46
  RESPONSE: GetTransactionTraceResponse;
45
47
  };
48
+ get_transaction_receipt: {
49
+ QUERY: {
50
+ transactionHash: string;
51
+ };
52
+ REQUEST: never;
53
+ RESPONSE: TransactionReceiptResponse;
54
+ };
46
55
  get_storage_at: {
47
56
  QUERY: {
48
57
  contractAddress: string;
@@ -217,7 +226,7 @@ export type AddTransactionResponse = {
217
226
  address?: string;
218
227
  };
219
228
 
220
- export type TransactionReceipt = {
229
+ export type TransactionReceiptResponse = {
221
230
  status: Status;
222
231
  transaction_hash: string;
223
232
  transaction_index: number;
@@ -228,7 +237,7 @@ export type TransactionReceipt = {
228
237
  };
229
238
 
230
239
  export type EstimateFeeResponse = {
231
- amount: number;
240
+ amount: BN;
232
241
  unit: string;
233
242
  };
234
243