starknet 2.9.0 → 3.2.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 (123) hide show
  1. package/.eslintrc +3 -1
  2. package/CHANGELOG.md +44 -0
  3. package/README.md +16 -14
  4. package/__mocks__/ArgentAccount.json +68548 -51944
  5. package/__mocks__/TestDapp.json +12962 -0
  6. package/__mocks__/contract.json +33191 -0
  7. package/__mocks__/multicall.json +8139 -0
  8. package/__tests__/account.test.ts +101 -122
  9. package/__tests__/accountContract.test.ts +141 -0
  10. package/__tests__/contract.test.ts +183 -34
  11. package/__tests__/fixtures.ts +13 -0
  12. package/__tests__/jest.setup.ts +9 -0
  13. package/__tests__/provider.test.ts +17 -42
  14. package/__tests__/utils/__snapshots__/utils.browser.test.ts.snap +2 -2
  15. package/__tests__/utils/__snapshots__/utils.test.ts.snap +2 -2
  16. package/__tests__/utils/ellipticalCurve.test.ts +20 -13
  17. package/__tests__/utils/utils.test.ts +3 -3
  18. package/account/default.d.ts +66 -0
  19. package/account/default.js +391 -0
  20. package/account/index.d.ts +2 -0
  21. package/account/index.js +27 -0
  22. package/account/interface.d.ts +83 -0
  23. package/account/interface.js +37 -0
  24. package/contract.d.ts +71 -12
  25. package/contract.js +243 -89
  26. package/dist/account/default.d.ts +55 -0
  27. package/dist/account/default.js +246 -0
  28. package/dist/account/index.d.ts +2 -0
  29. package/dist/account/index.js +14 -0
  30. package/dist/account/interface.d.ts +69 -0
  31. package/dist/account/interface.js +27 -0
  32. package/dist/contract.d.ts +71 -9
  33. package/dist/contract.js +214 -65
  34. package/dist/index.d.ts +1 -0
  35. package/dist/index.js +1 -0
  36. package/dist/provider/default.d.ts +23 -13
  37. package/dist/provider/default.js +168 -95
  38. package/dist/provider/interface.d.ts +22 -22
  39. package/dist/provider/utils.d.ts +4 -4
  40. package/dist/provider/utils.js +16 -6
  41. package/dist/signer/default.d.ts +7 -51
  42. package/dist/signer/default.js +16 -181
  43. package/dist/signer/index.d.ts +1 -1
  44. package/dist/signer/index.js +1 -1
  45. package/dist/signer/interface.d.ts +18 -38
  46. package/dist/signer/interface.js +2 -20
  47. package/dist/types/api.d.ts +152 -0
  48. package/dist/{types.js → types/api.js} +0 -0
  49. package/dist/types/index.d.ts +3 -0
  50. package/dist/types/index.js +15 -0
  51. package/dist/types/lib.d.ts +57 -0
  52. package/dist/types/lib.js +2 -0
  53. package/dist/types/signer.d.ts +4 -0
  54. package/dist/types/signer.js +2 -0
  55. package/dist/utils/ellipticCurve.js +1 -1
  56. package/dist/utils/hash.d.ts +12 -2
  57. package/dist/utils/hash.js +37 -9
  58. package/dist/utils/number.d.ts +2 -0
  59. package/dist/utils/number.js +32 -2
  60. package/dist/utils/stark.d.ts +2 -9
  61. package/dist/utils/stark.js +44 -14
  62. package/dist/utils/transaction.d.ts +19 -0
  63. package/dist/utils/transaction.js +75 -0
  64. package/dist/utils/typedData/index.d.ts +1 -1
  65. package/dist/utils/typedData/index.js +2 -3
  66. package/index.d.ts +1 -0
  67. package/index.js +1 -0
  68. package/package.json +9 -3
  69. package/provider/default.d.ts +40 -25
  70. package/provider/default.js +232 -180
  71. package/provider/interface.d.ts +28 -34
  72. package/provider/utils.d.ts +4 -4
  73. package/provider/utils.js +15 -6
  74. package/signer/default.d.ts +11 -51
  75. package/signer/default.js +21 -236
  76. package/signer/index.d.ts +1 -1
  77. package/signer/index.js +1 -1
  78. package/signer/interface.d.ts +22 -38
  79. package/signer/interface.js +3 -32
  80. package/src/account/default.ts +130 -0
  81. package/src/account/index.ts +2 -0
  82. package/src/account/interface.ts +91 -0
  83. package/src/contract.ts +246 -77
  84. package/src/index.ts +1 -0
  85. package/src/provider/default.ts +150 -107
  86. package/src/provider/interface.ts +28 -34
  87. package/src/provider/utils.ts +16 -6
  88. package/src/signer/default.ts +26 -124
  89. package/src/signer/index.ts +1 -1
  90. package/src/signer/interface.ts +22 -42
  91. package/src/types/api.ts +176 -0
  92. package/src/types/index.ts +3 -0
  93. package/src/types/lib.ts +72 -0
  94. package/src/types/signer.ts +5 -0
  95. package/src/utils/ellipticCurve.ts +1 -1
  96. package/src/utils/hash.ts +39 -12
  97. package/src/utils/number.ts +12 -1
  98. package/src/utils/stark.ts +14 -15
  99. package/src/utils/transaction.ts +50 -0
  100. package/src/utils/typedData/index.ts +2 -3
  101. package/types/api.d.ts +167 -0
  102. package/{types.js → types/api.js} +0 -0
  103. package/types/index.d.ts +3 -0
  104. package/types/index.js +28 -0
  105. package/types/lib.d.ts +64 -0
  106. package/types/lib.js +2 -0
  107. package/types/signer.d.ts +4 -0
  108. package/types/signer.js +2 -0
  109. package/utils/ellipticCurve.js +1 -1
  110. package/utils/hash.d.ts +15 -6
  111. package/utils/hash.js +42 -10
  112. package/utils/number.d.ts +4 -0
  113. package/utils/number.js +54 -2
  114. package/utils/stark.d.ts +2 -9
  115. package/utils/stark.js +64 -15
  116. package/utils/transaction.d.ts +19 -0
  117. package/utils/transaction.js +99 -0
  118. package/utils/typedData/index.d.ts +1 -1
  119. package/utils/typedData/index.js +2 -3
  120. package/__tests__/signer.test.ts +0 -125
  121. package/dist/types.d.ts +0 -109
  122. package/src/types.ts +0 -131
  123. package/types.d.ts +0 -116
@@ -1,39 +1,46 @@
1
- import axios from 'axios';
1
+ import axios, { AxiosRequestHeaders } from 'axios';
2
2
  import urljoin from 'url-join';
3
3
 
4
4
  import {
5
+ Abi,
5
6
  AddTransactionResponse,
7
+ Call,
6
8
  CallContractResponse,
7
- CallContractTransaction,
8
9
  CompiledContract,
10
+ DeployContractPayload,
11
+ Endpoints,
9
12
  GetBlockResponse,
10
13
  GetCodeResponse,
11
14
  GetContractAddressesResponse,
12
15
  GetTransactionResponse,
13
16
  GetTransactionStatusResponse,
14
- Signature,
15
- Transaction,
17
+ Invocation,
18
+ TransactionReceipt,
16
19
  } from '../types';
20
+ import { getSelectorFromName } from '../utils/hash';
17
21
  import { parse, stringify } from '../utils/json';
18
- import { BigNumberish, toBN, toHex } from '../utils/number';
19
- import { compressProgram, formatSignature, randomAddress } from '../utils/stark';
22
+ import { BigNumberish, bigNumberishArrayToDecimalStringArray, toBN, toHex } from '../utils/number';
23
+ import { compressProgram, randomAddress } from '../utils/stark';
20
24
  import { ProviderInterface } from './interface';
21
- import { BlockIdentifier, getFormattedBlockIdentifier } from './utils';
25
+ import { BlockIdentifier, getFormattedBlockIdentifier, txIdentifier } from './utils';
22
26
 
23
27
  type NetworkName = 'mainnet-alpha' | 'goerli-alpha';
24
28
 
25
- type ProviderOptions =
26
- | {
27
- network: NetworkName;
28
- }
29
- | {
30
- baseUrl: string;
31
- };
29
+ type ProviderOptions = { network: NetworkName } | { baseUrl: string };
32
30
 
33
31
  function wait(delay: number) {
34
32
  return new Promise((res) => setTimeout(res, delay));
35
33
  }
36
34
 
35
+ function isEmptyQueryObject(obj?: Record<any, any>): obj is undefined {
36
+ return (
37
+ obj === undefined ||
38
+ Object.keys(obj).length === 0 ||
39
+ (Object.keys(obj).length === 1 &&
40
+ Object.entries(obj).every(([k, v]) => k === 'blockIdentifier' && v === null))
41
+ );
42
+ }
43
+
37
44
  export class Provider implements ProviderInterface {
38
45
  public baseUrl: string;
39
46
 
@@ -67,6 +74,77 @@ export class Provider implements ProviderInterface {
67
74
  }
68
75
  }
69
76
 
77
+ private getFetchUrl(endpoint: keyof Endpoints) {
78
+ const gatewayUrlEndpoints = ['add_transaction'];
79
+
80
+ return gatewayUrlEndpoints.includes(endpoint) ? this.gatewayUrl : this.feederGatewayUrl;
81
+ }
82
+
83
+ private getFetchMethod(endpoint: keyof Endpoints) {
84
+ const postMethodEndpoints = ['add_transaction', 'call_contract'];
85
+
86
+ return postMethodEndpoints.includes(endpoint) ? 'POST' : 'GET';
87
+ }
88
+
89
+ private getQueryString(query?: Record<string, any>): string {
90
+ if (isEmptyQueryObject(query)) {
91
+ return '';
92
+ }
93
+ const queryString = Object.entries(query)
94
+ .map(([key, value]) => {
95
+ if (key === 'blockIdentifier') {
96
+ return `${getFormattedBlockIdentifier(value)}`;
97
+ }
98
+ return `${key}=${value}`;
99
+ })
100
+ .join('&');
101
+
102
+ return `?${queryString}`;
103
+ }
104
+
105
+ private getHeaders(method: 'POST' | 'GET'): AxiosRequestHeaders | undefined {
106
+ if (method === 'POST') {
107
+ return {
108
+ 'Content-Type': 'application/json',
109
+ };
110
+ }
111
+ return undefined;
112
+ }
113
+
114
+ // typesafe fetch
115
+ protected async fetchEndpoint<T extends keyof Endpoints>(
116
+ endpoint: T,
117
+ // typescript type magiuc to create a nice fitting function interface
118
+ ...[query, request]: Endpoints[T]['QUERY'] extends never
119
+ ? Endpoints[T]['REQUEST'] extends never
120
+ ? [] // when no query and no request is needed, we can omit the query and request parameters
121
+ : [undefined, Endpoints[T]['REQUEST']]
122
+ : Endpoints[T]['REQUEST'] extends never
123
+ ? [Endpoints[T]['QUERY']] // when no request is needed, we can omit the request parameter
124
+ : [Endpoints[T]['QUERY'], Endpoints[T]['REQUEST']] // when both query and request are needed, we cant omit anything
125
+ ): Promise<Endpoints[T]['RESPONSE']> {
126
+ const baseUrl = this.getFetchUrl(endpoint);
127
+ const method = this.getFetchMethod(endpoint);
128
+ const queryString = this.getQueryString(query);
129
+ const headers = this.getHeaders(method);
130
+
131
+ try {
132
+ const { data } = await axios.request<Endpoints[T]['RESPONSE']>({
133
+ method,
134
+ url: urljoin(baseUrl, endpoint, queryString),
135
+ data: stringify(request),
136
+ headers,
137
+ });
138
+ return data;
139
+ } catch (error: any) {
140
+ const data = error?.response?.data;
141
+ if (data?.message) {
142
+ throw new Error(`${data.code}: ${data.message}`);
143
+ }
144
+ throw error;
145
+ }
146
+ }
147
+
70
148
  /**
71
149
  * Gets the smart contract address on the goerli testnet.
72
150
  *
@@ -74,10 +152,7 @@ export class Provider implements ProviderInterface {
74
152
  * @returns starknet smart contract addresses
75
153
  */
76
154
  public async getContractAddresses(): Promise<GetContractAddressesResponse> {
77
- const { data } = await axios.get<GetContractAddressesResponse>(
78
- urljoin(this.feederGatewayUrl, 'get_contract_addresses')
79
- );
80
- return data;
155
+ return this.fetchEndpoint('get_contract_addresses');
81
156
  }
82
157
 
83
158
  /**
@@ -91,20 +166,21 @@ export class Provider implements ProviderInterface {
91
166
  * @returns the result of the function on the smart contract.
92
167
  */
93
168
  public async callContract(
94
- invokeTransaction: CallContractTransaction,
169
+ { contractAddress, entrypoint, calldata = [] }: Call,
95
170
  blockIdentifier: BlockIdentifier = null
96
171
  ): Promise<CallContractResponse> {
97
- const formattedBlockIdentifier = getFormattedBlockIdentifier(blockIdentifier);
98
-
99
- const { data } = await axios.post<CallContractResponse>(
100
- urljoin(this.feederGatewayUrl, 'call_contract', formattedBlockIdentifier),
172
+ return this.fetchEndpoint(
173
+ 'call_contract',
174
+ {
175
+ blockIdentifier,
176
+ },
101
177
  {
102
178
  signature: [],
103
- calldata: [],
104
- ...invokeTransaction,
179
+ contract_address: contractAddress,
180
+ entry_point_selector: getSelectorFromName(entrypoint),
181
+ calldata,
105
182
  }
106
183
  );
107
- return data;
108
184
  }
109
185
 
110
186
  /**
@@ -117,12 +193,7 @@ export class Provider implements ProviderInterface {
117
193
  * @returns the block object { block_number, previous_block_number, state_root, status, timestamp, transaction_receipts, transactions }
118
194
  */
119
195
  public async getBlock(blockIdentifier: BlockIdentifier = null): Promise<GetBlockResponse> {
120
- const formattedBlockIdentifier = getFormattedBlockIdentifier(blockIdentifier);
121
-
122
- const { data } = await axios.get<GetBlockResponse>(
123
- urljoin(this.feederGatewayUrl, 'get_block', formattedBlockIdentifier)
124
- );
125
- return data;
196
+ return this.fetchEndpoint('get_block', { blockIdentifier });
126
197
  }
127
198
 
128
199
  /**
@@ -139,16 +210,7 @@ export class Provider implements ProviderInterface {
139
210
  contractAddress: string,
140
211
  blockIdentifier: BlockIdentifier = null
141
212
  ): Promise<GetCodeResponse> {
142
- const formattedBlockIdentifier = getFormattedBlockIdentifier(blockIdentifier);
143
-
144
- const { data } = await axios.get<GetCodeResponse>(
145
- urljoin(
146
- this.feederGatewayUrl,
147
- 'get_code',
148
- `?contractAddress=${contractAddress}&${formattedBlockIdentifier}`
149
- )
150
- );
151
- return data;
213
+ return this.fetchEndpoint('get_code', { blockIdentifier, contractAddress });
152
214
  }
153
215
 
154
216
  // TODO: add proper type
@@ -168,16 +230,7 @@ export class Provider implements ProviderInterface {
168
230
  key: number,
169
231
  blockIdentifier: BlockIdentifier = null
170
232
  ): Promise<object> {
171
- const formattedBlockIdentifier = getFormattedBlockIdentifier(blockIdentifier);
172
-
173
- const { data } = await axios.get<object>(
174
- urljoin(
175
- this.feederGatewayUrl,
176
- 'get_storage_at',
177
- `?contractAddress=${contractAddress}&key=${key}&${formattedBlockIdentifier}`
178
- )
179
- );
180
- return data;
233
+ return this.fetchEndpoint('get_storage_at', { blockIdentifier, contractAddress, key });
181
234
  }
182
235
 
183
236
  /**
@@ -189,57 +242,45 @@ export class Provider implements ProviderInterface {
189
242
  * @returns the transaction status object { block_number, tx_status: NOT_RECEIVED | RECEIVED | PENDING | REJECTED | ACCEPTED_ONCHAIN }
190
243
  */
191
244
  public async getTransactionStatus(txHash: BigNumberish): Promise<GetTransactionStatusResponse> {
192
- const txHashBn = toBN(txHash);
193
- const { data } = await axios.get<GetTransactionStatusResponse>(
194
- urljoin(
195
- this.feederGatewayUrl,
196
- 'get_transaction_status',
197
- `?transactionHash=${toHex(txHashBn)}`
198
- )
199
- );
200
- return data;
245
+ const txHashHex = toHex(toBN(txHash));
246
+ return this.fetchEndpoint('get_transaction_status', { transactionHash: txHashHex });
201
247
  }
202
248
 
203
249
  /**
204
- * Gets the transaction information from a tx id.
250
+ * Gets the transaction receipt from a tx hash or tx id.
205
251
  *
206
- * [Reference](https://github.com/starkware-libs/cairo-lang/blob/f464ec4797361b6be8989e36e02ec690e74ef285/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L54-L58)
252
+ * [Reference] (https://github.com/starkware-libs/cairo-lang/blob/master/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L104-L111)
207
253
  *
208
254
  * @param txHash
209
- * @returns the transacton object { transaction_id, status, transaction, block_number?, block_number?, transaction_index?, transaction_failure_reason? }
255
+ * @param txId
256
+ * @returns the transaction receipt object
210
257
  */
211
- public async getTransaction(txHash: BigNumberish): Promise<GetTransactionResponse> {
212
- const txHashBn = toBN(txHash);
213
- const { data } = await axios.get<GetTransactionResponse>(
214
- urljoin(this.feederGatewayUrl, 'get_transaction', `?transactionHash=${toHex(txHashBn)}`)
258
+
259
+ public async getTransactionReceipt({
260
+ txHash,
261
+ txId,
262
+ }: {
263
+ txHash?: BigNumberish;
264
+ txId?: BigNumberish;
265
+ }): Promise<TransactionReceipt> {
266
+ const { data } = await axios.get<TransactionReceipt>(
267
+ urljoin(this.feederGatewayUrl, 'get_transaction_receipt', `?${txIdentifier(txHash, txId)}`)
215
268
  );
269
+
216
270
  return data;
217
271
  }
218
272
 
219
273
  /**
220
- * Invoke a function on the starknet contract
274
+ * Gets the transaction information from a tx id.
221
275
  *
222
- * [Reference](https://github.com/starkware-libs/cairo-lang/blob/f464ec4797361b6be8989e36e02ec690e74ef285/src/starkware/starknet/services/api/gateway/gateway_client.py#L13-L17)
276
+ * [Reference](https://github.com/starkware-libs/cairo-lang/blob/f464ec4797361b6be8989e36e02ec690e74ef285/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L54-L58)
223
277
  *
224
- * @param transaction - transaction to be invoked
225
- * @returns a confirmation of invoking a function on the starknet contract
278
+ * @param txHash
279
+ * @returns the transacton object { transaction_id, status, transaction, block_number?, block_number?, transaction_index?, transaction_failure_reason? }
226
280
  */
227
- public async addTransaction(transaction: Transaction): Promise<AddTransactionResponse> {
228
- const signature =
229
- transaction.type === 'INVOKE_FUNCTION' && formatSignature(transaction.signature);
230
- const contract_address_salt =
231
- transaction.type === 'DEPLOY' && toHex(toBN(transaction.contract_address_salt));
232
-
233
- const { data } = await axios.post<AddTransactionResponse>(
234
- urljoin(this.gatewayUrl, 'add_transaction'),
235
- stringify({
236
- ...transaction, // the tx can contain BigInts, so we use our own `stringify`
237
- ...(Array.isArray(signature) && { signature }), // not needed on deploy tx
238
- ...(contract_address_salt && { contract_address_salt }), // not needed on invoke tx
239
- }),
240
- { headers: { 'Content-Type': 'application/json' } }
241
- );
242
- return data;
281
+ public async getTransaction(txHash: BigNumberish): Promise<GetTransactionResponse> {
282
+ const txHashHex = toHex(toBN(txHash));
283
+ return this.fetchEndpoint('get_transaction', { transactionHash: txHashHex });
243
284
  }
244
285
 
245
286
  /**
@@ -250,27 +291,31 @@ export class Provider implements ProviderInterface {
250
291
  * @returns a confirmation of sending a transaction on the starknet contract
251
292
  */
252
293
  public deployContract(
253
- contract: CompiledContract | string,
254
- constructorCalldata: string[] = [],
255
- addressSalt: BigNumberish = randomAddress()
294
+ payload: DeployContractPayload,
295
+ _abi?: Abi
256
296
  ): Promise<AddTransactionResponse> {
257
297
  const parsedContract =
258
- typeof contract === 'string' ? (parse(contract) as CompiledContract) : contract;
298
+ typeof payload.contract === 'string'
299
+ ? (parse(payload.contract) as CompiledContract)
300
+ : payload.contract;
259
301
  const contractDefinition = {
260
302
  ...parsedContract,
261
303
  program: compressProgram(parsedContract.program),
262
304
  };
263
305
 
264
- return this.addTransaction({
306
+ return this.fetchEndpoint('add_transaction', undefined, {
265
307
  type: 'DEPLOY',
266
- contract_address_salt: addressSalt,
267
- constructor_calldata: constructorCalldata,
308
+ contract_address_salt: payload.addressSalt ?? randomAddress(),
309
+ constructor_calldata: bigNumberishArrayToDecimalStringArray(
310
+ payload.constructorCalldata ?? []
311
+ ),
268
312
  contract_definition: contractDefinition,
269
313
  });
270
314
  }
271
315
 
272
316
  /**
273
317
  * Invokes a function on starknet
318
+ * @deprecated This method wont be supported as soon as fees are mandatory
274
319
  *
275
320
  * @param contractAddress - target contract address for invoke
276
321
  * @param entrypointSelector - target entrypoint selector for
@@ -278,18 +323,13 @@ export class Provider implements ProviderInterface {
278
323
  * @param signature - (optional) signature to send along
279
324
  * @returns response from addTransaction
280
325
  */
281
- public invokeFunction(
282
- contractAddress: string,
283
- entrypointSelector: string,
284
- calldata?: string[],
285
- signature?: Signature
286
- ): Promise<AddTransactionResponse> {
287
- return this.addTransaction({
326
+ public invokeFunction(invocation: Invocation, _abi?: Abi): Promise<AddTransactionResponse> {
327
+ return this.fetchEndpoint('add_transaction', undefined, {
288
328
  type: 'INVOKE_FUNCTION',
289
- contract_address: contractAddress,
290
- entry_point_selector: entrypointSelector,
291
- calldata,
292
- signature,
329
+ contract_address: invocation.contractAddress,
330
+ entry_point_selector: getSelectorFromName(invocation.entrypoint),
331
+ calldata: bigNumberishArrayToDecimalStringArray(invocation.calldata ?? []),
332
+ signature: bigNumberishArrayToDecimalStringArray(invocation.signature ?? []),
293
333
  });
294
334
  }
295
335
 
@@ -306,7 +346,10 @@ export class Provider implements ProviderInterface {
306
346
  if (res.tx_status === 'ACCEPTED_ON_L1' || res.tx_status === 'ACCEPTED_ON_L2') {
307
347
  onchain = true;
308
348
  } else if (res.tx_status === 'REJECTED' || res.tx_status === 'NOT_RECEIVED') {
309
- const error = Error(res.tx_status) as Error & { response: GetTransactionStatusResponse };
349
+ const message = res.tx_failure_reason
350
+ ? `${res.tx_status}: ${res.tx_failure_reason.code}\n${res.tx_failure_reason.error_message}`
351
+ : res.tx_status;
352
+ const error = new Error(message) as Error & { response: GetTransactionStatusResponse };
310
353
  error.response = res;
311
354
  throw error;
312
355
  }
@@ -1,15 +1,15 @@
1
1
  import type {
2
2
  AddTransactionResponse,
3
+ Call,
3
4
  CallContractResponse,
4
- CallContractTransaction,
5
- CompiledContract,
5
+ DeployContractPayload,
6
6
  GetBlockResponse,
7
7
  GetCodeResponse,
8
8
  GetContractAddressesResponse,
9
9
  GetTransactionResponse,
10
10
  GetTransactionStatusResponse,
11
- Signature,
12
- Transaction,
11
+ Invocation,
12
+ TransactionReceipt,
13
13
  } from '../types';
14
14
  import type { BigNumberish } from '../utils/number';
15
15
  import { BlockIdentifier } from './utils';
@@ -34,12 +34,12 @@ export abstract class ProviderInterface {
34
34
  *
35
35
  * [Reference](https://github.com/starkware-libs/cairo-lang/blob/fc97bdd8322a7df043c87c371634b26c15ed6cee/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L25-L39)
36
36
  *
37
- * @param invokeTransaction - transaction to be invoked
38
- * @param blockIdentifier - block identifier
37
+ * @param invokeTransaction transaction to be invoked
38
+ * @param blockIdentifier block identifier
39
39
  * @returns the result of the function on the smart contract.
40
40
  */
41
41
  public abstract callContract(
42
- invokeTransaction: CallContractTransaction,
42
+ invokeTransaction: Call,
43
43
  blockIdentifier?: BlockIdentifier
44
44
  ): Promise<CallContractResponse>;
45
45
 
@@ -48,7 +48,7 @@ export abstract class ProviderInterface {
48
48
  *
49
49
  * [Reference](https://github.com/starkware-libs/cairo-lang/blob/fc97bdd8322a7df043c87c371634b26c15ed6cee/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L41-L53)
50
50
  *
51
- * @param blockIdentifier - block identifier
51
+ * @param blockIdentifier block identifier
52
52
  * @returns the block object { block_number, previous_block_number, state_root, status, timestamp, transaction_receipts, transactions }
53
53
  */
54
54
  public abstract getBlock(blockIdentifier?: BlockIdentifier): Promise<GetBlockResponse>;
@@ -104,44 +104,38 @@ export abstract class ProviderInterface {
104
104
  */
105
105
  public abstract getTransaction(txHash: BigNumberish): Promise<GetTransactionResponse>;
106
106
 
107
- /**
108
- * Invoke a function on the starknet contract
109
- *
110
- * [Reference](https://github.com/starkware-libs/cairo-lang/blob/f464ec4797361b6be8989e36e02ec690e74ef285/src/starkware/starknet/services/api/gateway/gateway_client.py#L13-L17)
111
- *
112
- * @param transaction - transaction to be invoked
113
- * @returns a confirmation of invoking a function on the starknet contract
114
- */
115
- public abstract addTransaction(transaction: Transaction): Promise<AddTransactionResponse>;
107
+ public abstract getTransactionReceipt({
108
+ txHash,
109
+ txId,
110
+ }: {
111
+ txHash?: BigNumberish;
112
+ txId?: BigNumberish;
113
+ }): Promise<TransactionReceipt>;
116
114
 
117
115
  /**
118
116
  * Deploys a given compiled contract (json) to starknet
119
117
  *
120
- * @param contract - a json object containing the compiled contract
121
- * @param address - (optional, defaults to a random address) the address where the contract should be deployed (alpha)
118
+ * @param payload payload to be deployed containing:
119
+ * - compiled contract code
120
+ * - constructor calldata
121
+ * - address salt
122
122
  * @returns a confirmation of sending a transaction on the starknet contract
123
123
  */
124
- public abstract deployContract(
125
- contract: CompiledContract | string,
126
- constructorCalldata: string[],
127
- addressSalt: BigNumberish
128
- ): Promise<AddTransactionResponse>;
124
+ public abstract deployContract(payload: DeployContractPayload): Promise<AddTransactionResponse>;
129
125
 
130
126
  /**
131
127
  * Invokes a function on starknet
128
+ * @deprecated This method wont be supported as soon as fees are mandatory
129
+ *
130
+ * @param invocation the invocation object containing:
131
+ * - contractAddress - the address of the contract
132
+ * - entrypoint - the entrypoint of the contract
133
+ * - calldata - (defaults to []) the calldata
134
+ * - signature - (defaults to []) the signature
132
135
  *
133
- * @param contractAddress - target contract address for invoke
134
- * @param entrypointSelector - target entrypoint selector for
135
- * @param calldata - (optional, default []) calldata
136
- * @param signature - (optional) signature to send along
137
136
  * @returns response from addTransaction
138
137
  */
139
- public abstract invokeFunction(
140
- contractAddress: string,
141
- entrypointSelector: string,
142
- calldata?: string[],
143
- signature?: Signature
144
- ): Promise<AddTransactionResponse>;
138
+ public abstract invokeFunction(invocation: Invocation): Promise<AddTransactionResponse>;
145
139
 
146
140
  public abstract waitForTx(txHash: BigNumberish, retryInterval?: number): Promise<void>;
147
141
  }
@@ -2,21 +2,31 @@ import type { BlockNumber } from '../types';
2
2
  import { BigNumberish, toBN, toHex } from '../utils/number';
3
3
 
4
4
  /**
5
- * TODO
5
+ *
6
6
  * [Reference](https://github.com/starkware-libs/cairo-lang/blob/fc97bdd8322a7df043c87c371634b26c15ed6cee/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L148-L153)
7
7
  *
8
8
  * @param hashValue
9
9
  * @param hashField
10
10
  */
11
- export function formatHash() {}
11
+ export function formatHash(hashValue: BigNumberish): string {
12
+ if (typeof hashValue === 'string') return hashValue;
13
+ return toHex(toBN(hashValue));
14
+ }
12
15
 
13
16
  /**
14
- * TODO
17
+ *
15
18
  * [Reference](https://github.com/starkware-libs/cairo-lang/blob/fc97bdd8322a7df043c87c371634b26c15ed6cee/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L156-L161)
16
19
  * @param txHash
17
20
  * @param txId
18
21
  */
19
- export function txIdentifier() {}
22
+ export function txIdentifier(txHash?: BigNumberish, txId?: BigNumberish): string {
23
+ if (!txHash) {
24
+ return `transactionId=${JSON.stringify(txId)}`;
25
+ }
26
+ const hashString = formatHash(txHash);
27
+
28
+ return `transactionHash=${hashString}`;
29
+ }
20
30
 
21
31
  // hex string and BN are detected as block hashes
22
32
  // decimal string and number are detected as block numbers
@@ -69,7 +79,7 @@ export function getFormattedBlockIdentifier(blockIdentifier: BlockIdentifier = n
69
79
  return '';
70
80
  }
71
81
  if (blockIdentifierObject.type === 'BLOCK_NUMBER') {
72
- return `?blockNumber=${blockIdentifierObject.data}`;
82
+ return `blockNumber=${blockIdentifierObject.data}`;
73
83
  }
74
- return `?blockHash=${toHex(toBN(blockIdentifierObject.data))}`;
84
+ return `blockHash=${toHex(toBN(blockIdentifierObject.data))}`;
75
85
  }