starknet 4.6.0 → 4.7.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 (78) hide show
  1. package/CHANGELOG.md +25 -0
  2. package/__tests__/account.test.ts +2 -5
  3. package/__tests__/contract.test.ts +0 -1
  4. package/__tests__/defaultProvider.test.ts +9 -1
  5. package/__tests__/sequencerProvider.test.ts +10 -8
  6. package/__tests__/utils/ellipticalCurve.test.ts +7 -8
  7. package/account/default.d.ts +3 -2
  8. package/account/default.js +22 -29
  9. package/account/interface.d.ts +2 -1
  10. package/contract/contractFactory.d.ts +1 -2
  11. package/contract/default.d.ts +2 -2
  12. package/contract/default.js +7 -3
  13. package/dist/account/default.d.ts +3 -2
  14. package/dist/account/default.js +22 -29
  15. package/dist/account/interface.d.ts +2 -1
  16. package/dist/contract/contractFactory.d.ts +1 -2
  17. package/dist/contract/default.d.ts +2 -2
  18. package/dist/contract/default.js +7 -3
  19. package/dist/provider/default.d.ts +4 -3
  20. package/dist/provider/default.js +9 -3
  21. package/dist/provider/interface.d.ts +10 -3
  22. package/dist/provider/rpc.d.ts +12 -10
  23. package/dist/provider/rpc.js +80 -72
  24. package/dist/provider/sequencer.d.ts +4 -3
  25. package/dist/provider/sequencer.js +14 -6
  26. package/dist/signer/default.d.ts +2 -2
  27. package/dist/signer/default.js +2 -2
  28. package/dist/signer/interface.d.ts +2 -2
  29. package/dist/types/api/openrpc.d.ts +17 -27
  30. package/dist/types/api/rpc.d.ts +4 -128
  31. package/dist/types/api/sequencer.d.ts +15 -4
  32. package/dist/types/lib.d.ts +10 -4
  33. package/dist/types/provider.d.ts +3 -2
  34. package/dist/utils/hash.d.ts +2 -2
  35. package/dist/utils/hash.js +5 -5
  36. package/dist/utils/responseParser/rpc.d.ts +2 -5
  37. package/dist/utils/responseParser/rpc.js +2 -38
  38. package/package.json +1 -1
  39. package/provider/default.d.ts +4 -3
  40. package/provider/default.js +9 -3
  41. package/provider/interface.d.ts +10 -3
  42. package/provider/rpc.d.ts +12 -10
  43. package/provider/rpc.js +80 -72
  44. package/provider/sequencer.d.ts +4 -3
  45. package/provider/sequencer.js +14 -6
  46. package/signer/default.d.ts +2 -2
  47. package/signer/default.js +2 -2
  48. package/signer/interface.d.ts +2 -2
  49. package/src/account/default.ts +21 -20
  50. package/src/account/interface.ts +2 -1
  51. package/src/contract/contractFactory.ts +1 -2
  52. package/src/contract/default.ts +16 -8
  53. package/src/provider/default.ts +12 -5
  54. package/src/provider/interface.ts +15 -4
  55. package/src/provider/rpc.ts +89 -73
  56. package/src/provider/sequencer.ts +16 -8
  57. package/src/signer/default.ts +8 -8
  58. package/src/signer/interface.ts +2 -2
  59. package/src/types/api/openrpc.ts +20 -25
  60. package/src/types/api/rpc.ts +4 -128
  61. package/src/types/api/sequencer.ts +17 -4
  62. package/src/types/lib.ts +7 -5
  63. package/src/types/provider.ts +3 -2
  64. package/src/utils/hash.ts +7 -6
  65. package/src/utils/responseParser/rpc.ts +7 -25
  66. package/types/api/openrpc.d.ts +17 -27
  67. package/types/api/rpc.d.ts +4 -128
  68. package/types/api/sequencer.d.ts +15 -4
  69. package/types/lib.d.ts +10 -4
  70. package/types/provider.d.ts +3 -2
  71. package/utils/hash.d.ts +2 -2
  72. package/utils/hash.js +5 -5
  73. package/utils/responseParser/rpc.d.ts +2 -5
  74. package/utils/responseParser/rpc.js +2 -38
  75. package/www/docs/API/account.md +3 -3
  76. package/www/docs/API/contract.md +2 -2
  77. package/www/docs/API/provider.md +6 -0
  78. package/www/docs/API/utils.md +2 -2
@@ -1,4 +1,5 @@
1
1
  import { ProviderInterface } from '../provider';
2
+ import { BlockIdentifier } from '../provider/utils';
2
3
  import { SignerInterface } from '../signer';
3
4
  import {
4
5
  Abi,
@@ -92,5 +93,5 @@ export abstract class AccountInterface extends ProviderInterface {
92
93
  */
93
94
  public abstract verifyMessageHash(hash: BigNumberish, signature: Signature): Promise<boolean>;
94
95
 
95
- public abstract getNonce(): Promise<string>;
96
+ public abstract getNonce(blockIdentifier?: BlockIdentifier): Promise<BigNumberish>;
96
97
  }
@@ -3,7 +3,6 @@ import assert from 'minimalistic-assert';
3
3
  import { AccountInterface } from '../account';
4
4
  import { ProviderInterface, defaultProvider } from '../provider';
5
5
  import { Abi, CompiledContract, RawCalldata } from '../types';
6
- import { BigNumberish } from '../utils/number';
7
6
  import { Contract } from './default';
8
7
 
9
8
  export class ContractFactory {
@@ -32,7 +31,7 @@ export class ContractFactory {
32
31
  */
33
32
  public async deploy(
34
33
  constructorCalldata?: RawCalldata,
35
- addressSalt?: BigNumberish
34
+ addressSalt?: string | undefined
36
35
  ): Promise<Contract> {
37
36
  const { contract_address, transaction_hash } = await this.providerOrAccount.deployContract({
38
37
  contract: this.compiledContract,
@@ -9,10 +9,10 @@ import {
9
9
  AbiEntry,
10
10
  Args,
11
11
  AsyncContractFunction,
12
+ Call,
12
13
  Calldata,
13
14
  ContractFunction,
14
15
  FunctionAbi,
15
- Invocation,
16
16
  InvokeFunctionResponse,
17
17
  Overrides,
18
18
  ParsedStruct,
@@ -125,7 +125,7 @@ export class Contract implements ContractInterface {
125
125
  address: string,
126
126
  providerOrAccount: ProviderInterface | AccountInterface = defaultProvider
127
127
  ) {
128
- this.address = address;
128
+ this.address = address.toLowerCase();
129
129
  this.providerOrAccount = providerOrAccount;
130
130
  this.abi = abi;
131
131
  this.structs = abi
@@ -578,13 +578,22 @@ export class Contract implements ContractInterface {
578
578
  });
579
579
  }
580
580
 
581
+ if (!options.nonce) {
582
+ throw new Error(`Nonce is required when invoking a function without an account`);
583
+ }
584
+
581
585
  // eslint-disable-next-line no-console
582
586
  console.warn(`Invoking ${method} without an account. This will not work on a public node.`);
583
587
 
584
- return this.providerOrAccount.invokeFunction({
585
- ...invocation,
586
- signature: options.signature || [],
587
- });
588
+ return this.providerOrAccount.invokeFunction(
589
+ {
590
+ ...invocation,
591
+ signature: options.signature || [],
592
+ },
593
+ {
594
+ nonce: options.nonce,
595
+ }
596
+ );
588
597
  }
589
598
 
590
599
  public async call(
@@ -630,13 +639,12 @@ export class Contract implements ContractInterface {
630
639
  throw Error('Contract must be connected to the account contract to estimate');
631
640
  }
632
641
 
633
- public populate(method: string, args: Array<any> = []): Invocation {
642
+ public populate(method: string, args: Array<any> = []): Call {
634
643
  const { inputs } = this.abi.find((abi) => abi.name === method) as FunctionAbi;
635
644
  return {
636
645
  contractAddress: this.address,
637
646
  entrypoint: method,
638
647
  calldata: this.compileCalldata(args, inputs),
639
- signature: [],
640
648
  };
641
649
  }
642
650
  }
@@ -13,7 +13,7 @@ import {
13
13
  GetTransactionReceiptResponse,
14
14
  GetTransactionResponse,
15
15
  Invocation,
16
- InvocationsDetails,
16
+ InvocationsDetailsWithNonce,
17
17
  InvokeFunctionResponse,
18
18
  } from '../types';
19
19
  import { BigNumberish } from '../utils/number';
@@ -63,10 +63,17 @@ export class Provider implements ProviderInterface {
63
63
 
64
64
  public async getEstimateFee(
65
65
  invocation: Invocation,
66
- blockIdentifier: BlockIdentifier = 'pending',
67
- invocationDetails: InvocationsDetails = {}
66
+ invocationDetails: InvocationsDetailsWithNonce,
67
+ blockIdentifier: BlockIdentifier = 'pending'
68
68
  ): Promise<EstimateFeeResponse> {
69
- return this.provider.getEstimateFee(invocation, blockIdentifier, invocationDetails);
69
+ return this.provider.getEstimateFee(invocation, invocationDetails, blockIdentifier);
70
+ }
71
+
72
+ public async getNonce(
73
+ contractAddress: string,
74
+ blockIdentifier?: BlockIdentifier
75
+ ): Promise<BigNumberish> {
76
+ return this.provider.getNonce(contractAddress, blockIdentifier);
70
77
  }
71
78
 
72
79
  public async getStorageAt(
@@ -94,7 +101,7 @@ export class Provider implements ProviderInterface {
94
101
 
95
102
  public async invokeFunction(
96
103
  functionInvocation: Invocation,
97
- details: InvocationsDetails
104
+ details: InvocationsDetailsWithNonce
98
105
  ): Promise<InvokeFunctionResponse> {
99
106
  return this.provider.invokeFunction(functionInvocation, details);
100
107
  }
@@ -13,7 +13,7 @@ import type {
13
13
  GetTransactionReceiptResponse,
14
14
  GetTransactionResponse,
15
15
  Invocation,
16
- InvocationsDetails,
16
+ InvocationsDetailsWithNonce,
17
17
  InvokeFunctionResponse,
18
18
  } from '../types';
19
19
  import type { BigNumberish } from '../utils/number';
@@ -69,6 +69,17 @@ export abstract class ProviderInterface {
69
69
  blockIdentifier?: BlockIdentifier
70
70
  ): Promise<ContractClass>;
71
71
 
72
+ /**
73
+ * Gets the nonce of a contract with respect to a specific block
74
+ *
75
+ * @param contractAddress - contract address
76
+ * @returns the hex nonce
77
+ */
78
+ public abstract getNonce(
79
+ contractAddress: string,
80
+ blockIdentifier?: BlockIdentifier
81
+ ): Promise<BigNumberish>;
82
+
72
83
  /**
73
84
  * Gets the contract's storage variable at a specific key.
74
85
  *
@@ -141,7 +152,7 @@ export abstract class ProviderInterface {
141
152
  */
142
153
  public abstract invokeFunction(
143
154
  invocation: Invocation,
144
- details?: InvocationsDetails
155
+ details: InvocationsDetailsWithNonce
145
156
  ): Promise<InvokeFunctionResponse>;
146
157
 
147
158
  /**
@@ -160,8 +171,8 @@ export abstract class ProviderInterface {
160
171
  */
161
172
  public abstract getEstimateFee(
162
173
  invocation: Invocation,
163
- blockIdentifier: BlockIdentifier,
164
- details?: InvocationsDetails
174
+ details: InvocationsDetailsWithNonce,
175
+ blockIdentifier: BlockIdentifier
165
176
  ): Promise<EstimateFeeResponse>;
166
177
 
167
178
  /**
@@ -12,7 +12,7 @@ import {
12
12
  GetTransactionReceiptResponse,
13
13
  GetTransactionResponse,
14
14
  Invocation,
15
- InvocationsDetails,
15
+ InvocationsDetailsWithNonce,
16
16
  InvokeFunctionResponse,
17
17
  } from '../types';
18
18
  import { RPC } from '../types/api';
@@ -31,7 +31,10 @@ import { randomAddress } from '../utils/stark';
31
31
  import { ProviderInterface } from './interface';
32
32
  import { Block, BlockIdentifier } from './utils';
33
33
 
34
- export type RpcProviderOptions = { nodeUrl: string };
34
+ export type RpcProviderOptions = {
35
+ nodeUrl: string;
36
+ retries?: number;
37
+ };
35
38
 
36
39
  export class RpcProvider implements ProviderInterface {
37
40
  public nodeUrl: string;
@@ -41,9 +44,12 @@ export class RpcProvider implements ProviderInterface {
41
44
 
42
45
  private responseParser = new RPCResponseParser();
43
46
 
47
+ private retries: number;
48
+
44
49
  constructor(optionsOrProvider: RpcProviderOptions) {
45
- const { nodeUrl } = optionsOrProvider;
50
+ const { nodeUrl, retries } = optionsOrProvider;
46
51
  this.nodeUrl = nodeUrl;
52
+ this.retries = retries || 200;
47
53
 
48
54
  this.getChainId().then((chainId) => {
49
55
  this.chainId = chainId;
@@ -67,13 +73,13 @@ export class RpcProvider implements ProviderInterface {
67
73
 
68
74
  protected async fetchEndpoint<T extends keyof RPC.Methods>(
69
75
  method: T,
70
- request?: RPC.Methods[T]['REQUEST']
71
- ): Promise<RPC.Methods[T]['RESPONSE']> {
76
+ params?: RPC.Methods[T]['params']
77
+ ): Promise<RPC.Methods[T]['result']> {
72
78
  try {
73
- const rawResult = await this.fetch(method, request);
79
+ const rawResult = await this.fetch(method, params);
74
80
  const { error, result } = await rawResult.json();
75
81
  this.errorHandler(error);
76
- return result as RPC.Methods[T]['RESPONSE'];
82
+ return result as RPC.Methods[T]['result'];
77
83
  } catch (error: any) {
78
84
  this.errorHandler(error?.response?.data);
79
85
  throw error;
@@ -99,27 +105,37 @@ export class RpcProvider implements ProviderInterface {
99
105
  public async getBlockWithTxHashes(
100
106
  blockIdentifier: BlockIdentifier = 'pending'
101
107
  ): Promise<RPC.GetBlockWithTxHashesResponse> {
102
- const block = new Block(blockIdentifier);
103
- return this.fetchEndpoint('starknet_getBlockWithTxHashes', [block.identifier]);
108
+ const block_id = new Block(blockIdentifier).identifier;
109
+ return this.fetchEndpoint('starknet_getBlockWithTxHashes', { block_id });
104
110
  }
105
111
 
106
112
  public async getBlockWithTxs(
107
113
  blockIdentifier: BlockIdentifier = 'pending'
108
114
  ): Promise<RPC.GetBlockWithTxs> {
109
- const block = new Block(blockIdentifier);
110
- return this.fetchEndpoint('starknet_getBlockWithTxs', [block.identifier]);
115
+ const block_id = new Block(blockIdentifier).identifier;
116
+ return this.fetchEndpoint('starknet_getBlockWithTxs', { block_id });
111
117
  }
112
118
 
113
119
  public async getClassHashAt(
114
120
  blockIdentifier: BlockIdentifier,
115
121
  contractAddress: RPC.ContractAddress
116
122
  ): Promise<RPC.Felt> {
117
- const block = new Block(blockIdentifier);
118
- return this.fetchEndpoint('starknet_getClassHashAt', [block.identifier, contractAddress]);
123
+ const block_id = new Block(blockIdentifier).identifier;
124
+ return this.fetchEndpoint('starknet_getClassHashAt', {
125
+ block_id,
126
+ contract_address: contractAddress,
127
+ });
119
128
  }
120
129
 
121
- public async getNonce(contractAddress: string): Promise<any> {
122
- return this.fetchEndpoint('starknet_getNonce', [contractAddress]);
130
+ public async getNonce(
131
+ contractAddress: string,
132
+ blockIdentifier: BlockIdentifier = 'pending'
133
+ ): Promise<RPC.Nonce> {
134
+ const block_id = new Block(blockIdentifier).identifier;
135
+ return this.fetchEndpoint('starknet_getNonce', {
136
+ contract_address: contractAddress,
137
+ block_id,
138
+ });
123
139
  }
124
140
 
125
141
  public async getPendingTransactions(): Promise<RPC.PendingTransactions> {
@@ -131,8 +147,8 @@ export class RpcProvider implements ProviderInterface {
131
147
  }
132
148
 
133
149
  public async getStateUpdate(blockIdentifier: BlockIdentifier): Promise<RPC.StateUpdate> {
134
- const block = new Block(blockIdentifier);
135
- return this.fetchEndpoint('starknet_getStateUpdate', [block.identifier]);
150
+ const block_id = new Block(blockIdentifier).identifier;
151
+ return this.fetchEndpoint('starknet_getStateUpdate', { block_id });
136
152
  }
137
153
 
138
154
  public async getStorageAt(
@@ -141,49 +157,50 @@ export class RpcProvider implements ProviderInterface {
141
157
  blockIdentifier: BlockIdentifier = 'pending'
142
158
  ): Promise<BigNumberish> {
143
159
  const parsedKey = toHex(toBN(key));
144
- const block = new Block(blockIdentifier);
145
- return this.fetchEndpoint('starknet_getStorageAt', [
146
- contractAddress,
147
- parsedKey,
148
- block.identifier,
149
- ]);
160
+ const block_id = new Block(blockIdentifier).identifier;
161
+ return this.fetchEndpoint('starknet_getStorageAt', {
162
+ contract_address: contractAddress,
163
+ key: parsedKey,
164
+ block_id,
165
+ });
150
166
  }
151
167
 
152
168
  // Methods from Interface
153
- public async getTransaction(txHash: BigNumberish): Promise<GetTransactionResponse> {
169
+ public async getTransaction(txHash: string): Promise<GetTransactionResponse> {
154
170
  return this.getTransactionByHash(txHash).then(this.responseParser.parseGetTransactionResponse);
155
171
  }
156
172
 
157
- public async getTransactionByHash(
158
- txHash: BigNumberish
159
- ): Promise<RPC.GetTransactionByHashResponse> {
160
- return this.fetchEndpoint('starknet_getTransactionByHash', [txHash]);
173
+ public async getTransactionByHash(txHash: string): Promise<RPC.GetTransactionByHashResponse> {
174
+ return this.fetchEndpoint('starknet_getTransactionByHash', { transaction_hash: txHash });
161
175
  }
162
176
 
163
177
  public async getTransactionByBlockIdAndIndex(
164
178
  blockIdentifier: BlockIdentifier,
165
179
  index: number
166
180
  ): Promise<RPC.GetTransactionByBlockIdAndIndex> {
167
- const block = new Block(blockIdentifier);
168
- return this.fetchEndpoint('starknet_getTransactionByBlockIdAndIndex', [
169
- block.identifier,
170
- index,
171
- ]);
181
+ const block_id = new Block(blockIdentifier).identifier;
182
+ return this.fetchEndpoint('starknet_getTransactionByBlockIdAndIndex', { block_id, index });
172
183
  }
173
184
 
174
- public async getTransactionReceipt(txHash: BigNumberish): Promise<GetTransactionReceiptResponse> {
175
- return this.fetchEndpoint('starknet_getTransactionReceipt', [txHash]).then(
185
+ public async getTransactionReceipt(txHash: string): Promise<GetTransactionReceiptResponse> {
186
+ return this.fetchEndpoint('starknet_getTransactionReceipt', { transaction_hash: txHash }).then(
176
187
  this.responseParser.parseGetTransactionReceiptResponse
177
188
  );
178
189
  }
179
190
 
180
191
  public async getClass(classHash: RPC.Felt): Promise<RPC.ContractClass> {
181
- return this.fetchEndpoint('starknet_getClass', [classHash]);
192
+ return this.fetchEndpoint('starknet_getClass', { class_hash: classHash });
182
193
  }
183
194
 
184
- public async getClassAt(contractAddress: string, blockIdentifier: BlockIdentifier): Promise<any> {
185
- const block = new Block(blockIdentifier);
186
- return this.fetchEndpoint('starknet_getClassAt', [block.identifier, contractAddress]);
195
+ public async getClassAt(
196
+ contractAddress: string,
197
+ blockIdentifier: BlockIdentifier
198
+ ): Promise<RPC.ContractClass> {
199
+ const block_id = new Block(blockIdentifier).identifier;
200
+ return this.fetchEndpoint('starknet_getClassAt', {
201
+ block_id,
202
+ contract_address: contractAddress,
203
+ });
187
204
  }
188
205
 
189
206
  public async getCode(
@@ -195,20 +212,20 @@ export class RpcProvider implements ProviderInterface {
195
212
 
196
213
  public async getEstimateFee(
197
214
  invocation: Invocation,
198
- blockIdentifier: BlockIdentifier = 'pending',
199
- invocationDetails: InvocationsDetails = {}
215
+ invocationDetails: InvocationsDetailsWithNonce,
216
+ blockIdentifier: BlockIdentifier = 'pending'
200
217
  ): Promise<EstimateFeeResponse> {
201
218
  const block_id = new Block(blockIdentifier).identifier;
202
- return this.fetchEndpoint('starknet_estimateFee', [
203
- {
219
+ return this.fetchEndpoint('starknet_estimateFee', {
220
+ request: {
204
221
  contract_address: invocation.contractAddress,
205
- entry_point_selector: getSelectorFromName(invocation.entrypoint),
206
222
  calldata: parseCalldata(invocation.calldata),
207
223
  signature: bigNumberishArrayToHexadecimalStringArray(invocation.signature || []),
208
224
  version: toHex(toBN(invocationDetails?.version || 0)),
225
+ max_fee: toHex(toBN(invocationDetails?.maxFee || 0)),
209
226
  },
210
227
  block_id,
211
- ]).then(this.responseParser.parseFeeEstimateResponse);
228
+ }).then(this.responseParser.parseFeeEstimateResponse);
212
229
  }
213
230
 
214
231
  public async declareContract({
@@ -217,14 +234,14 @@ export class RpcProvider implements ProviderInterface {
217
234
  }: DeclareContractPayload): Promise<DeclareContractResponse> {
218
235
  const contractDefinition = parseContract(contract);
219
236
 
220
- return this.fetchEndpoint('starknet_addDeclareTransaction', [
221
- {
237
+ return this.fetchEndpoint('starknet_addDeclareTransaction', {
238
+ contract_class: {
222
239
  program: contractDefinition.program,
223
240
  entry_points_by_type: contractDefinition.entry_points_by_type,
224
241
  abi: contractDefinition.abi, // rpc 2.0
225
242
  },
226
- toHex(toBN(version || 0)),
227
- ]).then(this.responseParser.parseDeclareContractResponse);
243
+ version: toHex(toBN(version || 0)),
244
+ });
228
245
  }
229
246
 
230
247
  public async deployContract({
@@ -234,31 +251,30 @@ export class RpcProvider implements ProviderInterface {
234
251
  }: DeployContractPayload): Promise<DeployContractResponse> {
235
252
  const contractDefinition = parseContract(contract);
236
253
 
237
- return this.fetchEndpoint('starknet_addDeployTransaction', [
238
- addressSalt ?? randomAddress(),
239
- bigNumberishArrayToHexadecimalStringArray(constructorCalldata ?? []),
240
- {
254
+ return this.fetchEndpoint('starknet_addDeployTransaction', {
255
+ contract_address_salt: addressSalt ?? randomAddress(),
256
+ constructor_calldata: bigNumberishArrayToHexadecimalStringArray(constructorCalldata ?? []),
257
+ contract_definition: {
241
258
  program: contractDefinition.program,
242
259
  entry_points_by_type: contractDefinition.entry_points_by_type,
243
260
  abi: contractDefinition.abi, // rpc 2.0
244
261
  },
245
- ]).then(this.responseParser.parseDeployContractResponse);
262
+ });
246
263
  }
247
264
 
248
265
  public async invokeFunction(
249
266
  functionInvocation: Invocation,
250
- details: InvocationsDetails
267
+ details: InvocationsDetailsWithNonce
251
268
  ): Promise<InvokeFunctionResponse> {
252
- return this.fetchEndpoint('starknet_addInvokeTransaction', [
253
- {
269
+ return this.fetchEndpoint('starknet_addInvokeTransaction', {
270
+ function_invocation: {
254
271
  contract_address: functionInvocation.contractAddress,
255
- entry_point_selector: getSelectorFromName(functionInvocation.entrypoint),
256
272
  calldata: parseCalldata(functionInvocation.calldata),
257
273
  },
258
- bigNumberishArrayToHexadecimalStringArray(functionInvocation.signature || []),
259
- toHex(toBN(details.maxFee || 0)),
260
- toHex(toBN(details.version || 0)),
261
- ]).then(this.responseParser.parseInvokeFunctionResponse);
274
+ signature: bigNumberishArrayToHexadecimalStringArray(functionInvocation.signature || []),
275
+ max_fee: toHex(toBN(details.maxFee || 0)),
276
+ version: toHex(toBN(details.version || 0)),
277
+ });
262
278
  }
263
279
 
264
280
  // Methods from Interface
@@ -267,29 +283,29 @@ export class RpcProvider implements ProviderInterface {
267
283
  blockIdentifier: BlockIdentifier = 'pending'
268
284
  ): Promise<CallContractResponse> {
269
285
  const block_id = new Block(blockIdentifier).identifier;
270
- const result = await this.fetchEndpoint('starknet_call', [
271
- {
286
+ const result = await this.fetchEndpoint('starknet_call', {
287
+ request: {
272
288
  contract_address: call.contractAddress,
273
289
  entry_point_selector: getSelectorFromName(call.entrypoint),
274
290
  calldata: parseCalldata(call.calldata),
275
291
  },
276
292
  block_id,
277
- ]);
293
+ });
278
294
 
279
295
  return this.responseParser.parseCallContractResponse(result);
280
296
  }
281
297
 
282
298
  public async traceTransaction(transactionHash: RPC.TransactionHash): Promise<RPC.Trace> {
283
- return this.fetchEndpoint('starknet_traceTransaction', [transactionHash]);
299
+ return this.fetchEndpoint('starknet_traceTransaction', { transaction_hash: transactionHash });
284
300
  }
285
301
 
286
302
  public async traceBlockTransactions(blockHash: RPC.BlockHash): Promise<RPC.Traces> {
287
- return this.fetchEndpoint('starknet_traceBlockTransactions', [blockHash]);
303
+ return this.fetchEndpoint('starknet_traceBlockTransactions', { block_hash: blockHash });
288
304
  }
289
305
 
290
- public async waitForTransaction(txHash: BigNumberish, retryInterval: number = 8000) {
306
+ public async waitForTransaction(txHash: string, retryInterval: number = 8000) {
307
+ let { retries } = this;
291
308
  let onchain = false;
292
- let retries = 200;
293
309
 
294
310
  while (!onchain) {
295
311
  const successStates = ['ACCEPTED_ON_L1', 'ACCEPTED_ON_L2', 'PENDING'];
@@ -315,7 +331,7 @@ export class RpcProvider implements ProviderInterface {
315
331
  }
316
332
 
317
333
  if (retries === 0) {
318
- throw error;
334
+ throw new Error('waitForTransaction timedout with retries');
319
335
  }
320
336
  }
321
337
 
@@ -335,8 +351,8 @@ export class RpcProvider implements ProviderInterface {
335
351
  public async getTransactionCount(
336
352
  blockIdentifier: BlockIdentifier
337
353
  ): Promise<RPC.GetTransactionCountResponse> {
338
- const block = new Block(blockIdentifier);
339
- return this.fetchEndpoint('starknet_getBlockTransactionCount', [block.identifier]);
354
+ const block_id = new Block(blockIdentifier).identifier;
355
+ return this.fetchEndpoint('starknet_getBlockTransactionCount', { block_id });
340
356
  }
341
357
 
342
358
  /**
@@ -366,6 +382,6 @@ export class RpcProvider implements ProviderInterface {
366
382
  * @returns events and the pagination of the events
367
383
  */
368
384
  public async getEvents(eventFilter: RPC.EventFilter): Promise<RPC.GetEventsResponse> {
369
- return this.fetchEndpoint('starknet_getEvents', [eventFilter]);
385
+ return this.fetchEndpoint('starknet_getEvents', { filter: eventFilter });
370
386
  }
371
387
  }
@@ -14,7 +14,7 @@ import {
14
14
  GetTransactionReceiptResponse,
15
15
  GetTransactionResponse,
16
16
  Invocation,
17
- InvocationsDetails,
17
+ InvocationsDetailsWithNonce,
18
18
  InvokeFunctionResponse,
19
19
  } from '../types';
20
20
  import {
@@ -234,6 +234,13 @@ export class SequencerProvider implements ProviderInterface {
234
234
  );
235
235
  }
236
236
 
237
+ public async getNonce(
238
+ contractAddress: string,
239
+ blockIdentifier: BlockIdentifier = 'pending'
240
+ ): Promise<BigNumberish> {
241
+ return this.fetchEndpoint('get_nonce', { contractAddress, blockIdentifier });
242
+ }
243
+
237
244
  public async getStorageAt(
238
245
  contractAddress: string,
239
246
  key: BigNumberish,
@@ -272,16 +279,16 @@ export class SequencerProvider implements ProviderInterface {
272
279
 
273
280
  public async invokeFunction(
274
281
  functionInvocation: Invocation,
275
- details: InvocationsDetails
282
+ details: InvocationsDetailsWithNonce
276
283
  ): Promise<InvokeFunctionResponse> {
277
284
  return this.fetchEndpoint('add_transaction', undefined, {
278
285
  type: 'INVOKE_FUNCTION',
279
286
  contract_address: functionInvocation.contractAddress,
280
- entry_point_selector: getSelectorFromName(functionInvocation.entrypoint),
281
287
  calldata: bigNumberishArrayToDecimalStringArray(functionInvocation.calldata ?? []),
282
288
  signature: bigNumberishArrayToDecimalStringArray(functionInvocation.signature ?? []),
289
+ nonce: toHex(toBN(details.nonce)),
283
290
  max_fee: toHex(toBN(details.maxFee || 0)),
284
- version: toHex(toBN(details.version || 0)),
291
+ version: toHex(toBN(details.version || 1)),
285
292
  }).then(this.responseParser.parseInvokeFunctionResponse);
286
293
  }
287
294
 
@@ -316,18 +323,19 @@ export class SequencerProvider implements ProviderInterface {
316
323
 
317
324
  public async getEstimateFee(
318
325
  invocation: Invocation,
319
- blockIdentifier: BlockIdentifier = 'pending',
320
- invocationDetails: InvocationsDetails = {}
326
+ invocationDetails: InvocationsDetailsWithNonce,
327
+ blockIdentifier: BlockIdentifier = 'pending'
321
328
  ): Promise<EstimateFeeResponse> {
322
329
  return this.fetchEndpoint(
323
330
  'estimate_fee',
324
331
  { blockIdentifier },
325
332
  {
333
+ type: 'INVOKE_FUNCTION',
326
334
  contract_address: invocation.contractAddress,
327
- entry_point_selector: getSelectorFromName(invocation.entrypoint),
328
335
  calldata: invocation.calldata ?? [],
329
336
  signature: bigNumberishArrayToDecimalStringArray(invocation.signature || []),
330
- version: toHex(toBN(invocationDetails?.version || 0)),
337
+ version: toHex(toBN(invocationDetails?.version || 1)),
338
+ nonce: toHex(toBN(invocationDetails.nonce)),
331
339
  }
332
340
  ).then(this.responseParser.parseFeeEstimateResponse);
333
341
  }
@@ -1,7 +1,7 @@
1
- import { Abi, Invocation, InvocationsSignerDetails, KeyPair, Signature } from '../types';
1
+ import { Abi, Call, InvocationsSignerDetails, KeyPair, Signature } from '../types';
2
2
  import { genKeyPair, getStarkKey, sign } from '../utils/ellipticCurve';
3
- import { calculcateTransactionHash, getSelectorFromName } from '../utils/hash';
4
- import { fromCallsToExecuteCalldataWithNonce } from '../utils/transaction';
3
+ import { calculateTransactionHash } from '../utils/hash';
4
+ import { fromCallsToExecuteCalldata } from '../utils/transaction';
5
5
  import { TypedData, getMessageHash } from '../utils/typedData';
6
6
  import { SignerInterface } from './interface';
7
7
 
@@ -17,7 +17,7 @@ export class Signer implements SignerInterface {
17
17
  }
18
18
 
19
19
  public async signTransaction(
20
- transactions: Invocation[],
20
+ transactions: Call[],
21
21
  transactionsDetail: InvocationsSignerDetails,
22
22
  abis?: Abi[]
23
23
  ): Promise<Signature> {
@@ -26,15 +26,15 @@ export class Signer implements SignerInterface {
26
26
  }
27
27
  // now use abi to display decoded data somewhere, but as this signer is headless, we can't do that
28
28
 
29
- const calldata = fromCallsToExecuteCalldataWithNonce(transactions, transactionsDetail.nonce);
29
+ const calldata = fromCallsToExecuteCalldata(transactions);
30
30
 
31
- const msgHash = calculcateTransactionHash(
31
+ const msgHash = calculateTransactionHash(
32
32
  transactionsDetail.walletAddress,
33
33
  transactionsDetail.version,
34
- getSelectorFromName('__execute__'),
35
34
  calldata,
36
35
  transactionsDetail.maxFee,
37
- transactionsDetail.chainId
36
+ transactionsDetail.chainId,
37
+ transactionsDetail.nonce
38
38
  );
39
39
 
40
40
  return sign(this.keyPair, msgHash);
@@ -1,4 +1,4 @@
1
- import { Abi, Invocation, InvocationsSignerDetails, Signature } from '../types';
1
+ import { Abi, Call, InvocationsSignerDetails, Signature } from '../types';
2
2
  import { TypedData } from '../utils/typedData';
3
3
 
4
4
  export abstract class SignerInterface {
@@ -33,7 +33,7 @@ export abstract class SignerInterface {
33
33
  * @returns signature
34
34
  */
35
35
  public abstract signTransaction(
36
- transactions: Invocation[],
36
+ transactions: Call[],
37
37
  transactionsDetail: InvocationsSignerDetails,
38
38
  abis?: Abi[]
39
39
  ): Promise<Signature>;