starknet 6.1.5 → 6.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.
package/dist/index.mjs CHANGED
@@ -18,7 +18,7 @@ __export(constants_exports, {
18
18
  RPC_NODES: () => RPC_NODES,
19
19
  StarknetChainId: () => StarknetChainId,
20
20
  TEXT_TO_FELT_MAX_LEN: () => TEXT_TO_FELT_MAX_LEN,
21
- TRANSACTION_VERSION: () => ETransactionVersion,
21
+ TRANSACTION_VERSION: () => ETransactionVersion4,
22
22
  TransactionHashPrefix: () => TransactionHashPrefix,
23
23
  UDC: () => UDC,
24
24
  ZERO: () => ZERO
@@ -27,6 +27,30 @@ __export(constants_exports, {
27
27
  // src/types/api/index.ts
28
28
  var api_exports = {};
29
29
  __export(api_exports, {
30
+ EBlockTag: () => EBlockTag2,
31
+ EDAMode: () => EDAMode2,
32
+ EDataAvailabilityMode: () => EDataAvailabilityMode2,
33
+ ESimulationFlag: () => ESimulationFlag2,
34
+ ETransactionExecutionStatus: () => ETransactionExecutionStatus2,
35
+ ETransactionFinalityStatus: () => ETransactionFinalityStatus2,
36
+ ETransactionStatus: () => ETransactionStatus2,
37
+ ETransactionType: () => ETransactionType2,
38
+ ETransactionVersion: () => ETransactionVersion4,
39
+ ETransactionVersion2: () => ETransactionVersion22,
40
+ ETransactionVersion3: () => ETransactionVersion32,
41
+ Errors: () => errors_exports2,
42
+ JRPC: () => jsonrpc_exports,
43
+ RPCSPEC06: () => rpcspec_0_6_exports,
44
+ RPCSPEC07: () => rpcspec_0_7_exports,
45
+ SPEC: () => components_exports2
46
+ });
47
+
48
+ // src/types/api/jsonrpc/index.ts
49
+ var jsonrpc_exports = {};
50
+
51
+ // src/types/api/rpcspec_0_6/index.ts
52
+ var rpcspec_0_6_exports = {};
53
+ __export(rpcspec_0_6_exports, {
30
54
  EBlockTag: () => EBlockTag,
31
55
  EDAMode: () => EDAMode,
32
56
  EDataAvailabilityMode: () => EDataAvailabilityMode,
@@ -39,13 +63,9 @@ __export(api_exports, {
39
63
  ETransactionVersion2: () => ETransactionVersion2,
40
64
  ETransactionVersion3: () => ETransactionVersion3,
41
65
  Errors: () => errors_exports,
42
- JRPC: () => jsonrpc_exports,
43
66
  SPEC: () => components_exports
44
67
  });
45
68
 
46
- // src/types/api/jsonrpc/index.ts
47
- var jsonrpc_exports = {};
48
-
49
69
  // src/types/api/rpcspec_0_6/errors.ts
50
70
  var errors_exports = {};
51
71
 
@@ -53,77 +73,173 @@ var errors_exports = {};
53
73
  var components_exports = {};
54
74
 
55
75
  // src/types/api/rpcspec_0_6/nonspec.ts
56
- var ETransactionType = /* @__PURE__ */ ((ETransactionType2) => {
57
- ETransactionType2["DECLARE"] = "DECLARE";
58
- ETransactionType2["DEPLOY"] = "DEPLOY";
59
- ETransactionType2["DEPLOY_ACCOUNT"] = "DEPLOY_ACCOUNT";
60
- ETransactionType2["INVOKE"] = "INVOKE";
61
- ETransactionType2["L1_HANDLER"] = "L1_HANDLER";
62
- return ETransactionType2;
76
+ var ETransactionType = /* @__PURE__ */ ((ETransactionType3) => {
77
+ ETransactionType3["DECLARE"] = "DECLARE";
78
+ ETransactionType3["DEPLOY"] = "DEPLOY";
79
+ ETransactionType3["DEPLOY_ACCOUNT"] = "DEPLOY_ACCOUNT";
80
+ ETransactionType3["INVOKE"] = "INVOKE";
81
+ ETransactionType3["L1_HANDLER"] = "L1_HANDLER";
82
+ return ETransactionType3;
63
83
  })(ETransactionType || {});
64
- var ESimulationFlag = /* @__PURE__ */ ((ESimulationFlag2) => {
65
- ESimulationFlag2["SKIP_VALIDATE"] = "SKIP_VALIDATE";
66
- ESimulationFlag2["SKIP_FEE_CHARGE"] = "SKIP_FEE_CHARGE";
67
- return ESimulationFlag2;
84
+ var ESimulationFlag = /* @__PURE__ */ ((ESimulationFlag3) => {
85
+ ESimulationFlag3["SKIP_VALIDATE"] = "SKIP_VALIDATE";
86
+ ESimulationFlag3["SKIP_FEE_CHARGE"] = "SKIP_FEE_CHARGE";
87
+ return ESimulationFlag3;
68
88
  })(ESimulationFlag || {});
69
- var ETransactionStatus = /* @__PURE__ */ ((ETransactionStatus2) => {
70
- ETransactionStatus2["RECEIVED"] = "RECEIVED";
71
- ETransactionStatus2["REJECTED"] = "REJECTED";
72
- ETransactionStatus2["ACCEPTED_ON_L2"] = "ACCEPTED_ON_L2";
73
- ETransactionStatus2["ACCEPTED_ON_L1"] = "ACCEPTED_ON_L1";
74
- return ETransactionStatus2;
89
+ var ETransactionStatus = /* @__PURE__ */ ((ETransactionStatus3) => {
90
+ ETransactionStatus3["RECEIVED"] = "RECEIVED";
91
+ ETransactionStatus3["REJECTED"] = "REJECTED";
92
+ ETransactionStatus3["ACCEPTED_ON_L2"] = "ACCEPTED_ON_L2";
93
+ ETransactionStatus3["ACCEPTED_ON_L1"] = "ACCEPTED_ON_L1";
94
+ return ETransactionStatus3;
75
95
  })(ETransactionStatus || {});
76
- var ETransactionFinalityStatus = /* @__PURE__ */ ((ETransactionFinalityStatus2) => {
77
- ETransactionFinalityStatus2["ACCEPTED_ON_L2"] = "ACCEPTED_ON_L2";
78
- ETransactionFinalityStatus2["ACCEPTED_ON_L1"] = "ACCEPTED_ON_L1";
79
- return ETransactionFinalityStatus2;
96
+ var ETransactionFinalityStatus = /* @__PURE__ */ ((ETransactionFinalityStatus3) => {
97
+ ETransactionFinalityStatus3["ACCEPTED_ON_L2"] = "ACCEPTED_ON_L2";
98
+ ETransactionFinalityStatus3["ACCEPTED_ON_L1"] = "ACCEPTED_ON_L1";
99
+ return ETransactionFinalityStatus3;
80
100
  })(ETransactionFinalityStatus || {});
81
- var ETransactionExecutionStatus = /* @__PURE__ */ ((ETransactionExecutionStatus2) => {
82
- ETransactionExecutionStatus2["SUCCEEDED"] = "SUCCEEDED";
83
- ETransactionExecutionStatus2["REVERTED"] = "REVERTED";
84
- return ETransactionExecutionStatus2;
101
+ var ETransactionExecutionStatus = /* @__PURE__ */ ((ETransactionExecutionStatus3) => {
102
+ ETransactionExecutionStatus3["SUCCEEDED"] = "SUCCEEDED";
103
+ ETransactionExecutionStatus3["REVERTED"] = "REVERTED";
104
+ return ETransactionExecutionStatus3;
85
105
  })(ETransactionExecutionStatus || {});
86
- var EBlockTag = /* @__PURE__ */ ((EBlockTag2) => {
87
- EBlockTag2["LATEST"] = "latest";
88
- EBlockTag2["PENDING"] = "pending";
89
- return EBlockTag2;
106
+ var EBlockTag = /* @__PURE__ */ ((EBlockTag3) => {
107
+ EBlockTag3["LATEST"] = "latest";
108
+ EBlockTag3["PENDING"] = "pending";
109
+ return EBlockTag3;
90
110
  })(EBlockTag || {});
91
- var EDataAvailabilityMode = /* @__PURE__ */ ((EDataAvailabilityMode2) => {
92
- EDataAvailabilityMode2["L1"] = "L1";
93
- EDataAvailabilityMode2["L2"] = "L2";
94
- return EDataAvailabilityMode2;
111
+ var EDataAvailabilityMode = /* @__PURE__ */ ((EDataAvailabilityMode3) => {
112
+ EDataAvailabilityMode3["L1"] = "L1";
113
+ EDataAvailabilityMode3["L2"] = "L2";
114
+ return EDataAvailabilityMode3;
95
115
  })(EDataAvailabilityMode || {});
96
- var EDAMode = /* @__PURE__ */ ((EDAMode3) => {
97
- EDAMode3[EDAMode3["L1"] = 0] = "L1";
98
- EDAMode3[EDAMode3["L2"] = 1] = "L2";
99
- return EDAMode3;
116
+ var EDAMode = /* @__PURE__ */ ((EDAMode4) => {
117
+ EDAMode4[EDAMode4["L1"] = 0] = "L1";
118
+ EDAMode4[EDAMode4["L2"] = 1] = "L2";
119
+ return EDAMode4;
100
120
  })(EDAMode || {});
101
- var ETransactionVersion = /* @__PURE__ */ ((ETransactionVersion4) => {
102
- ETransactionVersion4["V0"] = "0x0";
103
- ETransactionVersion4["V1"] = "0x1";
104
- ETransactionVersion4["V2"] = "0x2";
105
- ETransactionVersion4["V3"] = "0x3";
106
- ETransactionVersion4["F0"] = "0x100000000000000000000000000000000";
107
- ETransactionVersion4["F1"] = "0x100000000000000000000000000000001";
108
- ETransactionVersion4["F2"] = "0x100000000000000000000000000000002";
109
- ETransactionVersion4["F3"] = "0x100000000000000000000000000000003";
110
- return ETransactionVersion4;
121
+ var ETransactionVersion = /* @__PURE__ */ ((ETransactionVersion5) => {
122
+ ETransactionVersion5["V0"] = "0x0";
123
+ ETransactionVersion5["V1"] = "0x1";
124
+ ETransactionVersion5["V2"] = "0x2";
125
+ ETransactionVersion5["V3"] = "0x3";
126
+ ETransactionVersion5["F0"] = "0x100000000000000000000000000000000";
127
+ ETransactionVersion5["F1"] = "0x100000000000000000000000000000001";
128
+ ETransactionVersion5["F2"] = "0x100000000000000000000000000000002";
129
+ ETransactionVersion5["F3"] = "0x100000000000000000000000000000003";
130
+ return ETransactionVersion5;
111
131
  })(ETransactionVersion || {});
112
- var ETransactionVersion2 = /* @__PURE__ */ ((ETransactionVersion23) => {
113
- ETransactionVersion23["V0"] = "0x0";
114
- ETransactionVersion23["V1"] = "0x1";
115
- ETransactionVersion23["V2"] = "0x2";
116
- ETransactionVersion23["F0"] = "0x100000000000000000000000000000000";
117
- ETransactionVersion23["F1"] = "0x100000000000000000000000000000001";
118
- ETransactionVersion23["F2"] = "0x100000000000000000000000000000002";
119
- return ETransactionVersion23;
132
+ var ETransactionVersion2 = /* @__PURE__ */ ((ETransactionVersion24) => {
133
+ ETransactionVersion24["V0"] = "0x0";
134
+ ETransactionVersion24["V1"] = "0x1";
135
+ ETransactionVersion24["V2"] = "0x2";
136
+ ETransactionVersion24["F0"] = "0x100000000000000000000000000000000";
137
+ ETransactionVersion24["F1"] = "0x100000000000000000000000000000001";
138
+ ETransactionVersion24["F2"] = "0x100000000000000000000000000000002";
139
+ return ETransactionVersion24;
120
140
  })(ETransactionVersion2 || {});
121
- var ETransactionVersion3 = /* @__PURE__ */ ((ETransactionVersion33) => {
122
- ETransactionVersion33["V3"] = "0x3";
123
- ETransactionVersion33["F3"] = "0x100000000000000000000000000000003";
124
- return ETransactionVersion33;
141
+ var ETransactionVersion3 = /* @__PURE__ */ ((ETransactionVersion34) => {
142
+ ETransactionVersion34["V3"] = "0x3";
143
+ ETransactionVersion34["F3"] = "0x100000000000000000000000000000003";
144
+ return ETransactionVersion34;
125
145
  })(ETransactionVersion3 || {});
126
146
 
147
+ // src/types/api/rpcspec_0_7/index.ts
148
+ var rpcspec_0_7_exports = {};
149
+ __export(rpcspec_0_7_exports, {
150
+ EBlockTag: () => EBlockTag2,
151
+ EDAMode: () => EDAMode2,
152
+ EDataAvailabilityMode: () => EDataAvailabilityMode2,
153
+ ESimulationFlag: () => ESimulationFlag2,
154
+ ETransactionExecutionStatus: () => ETransactionExecutionStatus2,
155
+ ETransactionFinalityStatus: () => ETransactionFinalityStatus2,
156
+ ETransactionStatus: () => ETransactionStatus2,
157
+ ETransactionType: () => ETransactionType2,
158
+ ETransactionVersion: () => ETransactionVersion4,
159
+ ETransactionVersion2: () => ETransactionVersion22,
160
+ ETransactionVersion3: () => ETransactionVersion32,
161
+ Errors: () => errors_exports2,
162
+ SPEC: () => components_exports2
163
+ });
164
+
165
+ // src/types/api/rpcspec_0_7/errors.ts
166
+ var errors_exports2 = {};
167
+
168
+ // src/types/api/rpcspec_0_7/components.ts
169
+ var components_exports2 = {};
170
+
171
+ // src/types/api/rpcspec_0_7/nonspec.ts
172
+ var ETransactionType2 = /* @__PURE__ */ ((ETransactionType3) => {
173
+ ETransactionType3["DECLARE"] = "DECLARE";
174
+ ETransactionType3["DEPLOY"] = "DEPLOY";
175
+ ETransactionType3["DEPLOY_ACCOUNT"] = "DEPLOY_ACCOUNT";
176
+ ETransactionType3["INVOKE"] = "INVOKE";
177
+ ETransactionType3["L1_HANDLER"] = "L1_HANDLER";
178
+ return ETransactionType3;
179
+ })(ETransactionType2 || {});
180
+ var ESimulationFlag2 = /* @__PURE__ */ ((ESimulationFlag3) => {
181
+ ESimulationFlag3["SKIP_VALIDATE"] = "SKIP_VALIDATE";
182
+ ESimulationFlag3["SKIP_FEE_CHARGE"] = "SKIP_FEE_CHARGE";
183
+ return ESimulationFlag3;
184
+ })(ESimulationFlag2 || {});
185
+ var ETransactionStatus2 = /* @__PURE__ */ ((ETransactionStatus3) => {
186
+ ETransactionStatus3["RECEIVED"] = "RECEIVED";
187
+ ETransactionStatus3["REJECTED"] = "REJECTED";
188
+ ETransactionStatus3["ACCEPTED_ON_L2"] = "ACCEPTED_ON_L2";
189
+ ETransactionStatus3["ACCEPTED_ON_L1"] = "ACCEPTED_ON_L1";
190
+ return ETransactionStatus3;
191
+ })(ETransactionStatus2 || {});
192
+ var ETransactionFinalityStatus2 = /* @__PURE__ */ ((ETransactionFinalityStatus3) => {
193
+ ETransactionFinalityStatus3["ACCEPTED_ON_L2"] = "ACCEPTED_ON_L2";
194
+ ETransactionFinalityStatus3["ACCEPTED_ON_L1"] = "ACCEPTED_ON_L1";
195
+ return ETransactionFinalityStatus3;
196
+ })(ETransactionFinalityStatus2 || {});
197
+ var ETransactionExecutionStatus2 = /* @__PURE__ */ ((ETransactionExecutionStatus3) => {
198
+ ETransactionExecutionStatus3["SUCCEEDED"] = "SUCCEEDED";
199
+ ETransactionExecutionStatus3["REVERTED"] = "REVERTED";
200
+ return ETransactionExecutionStatus3;
201
+ })(ETransactionExecutionStatus2 || {});
202
+ var EBlockTag2 = /* @__PURE__ */ ((EBlockTag3) => {
203
+ EBlockTag3["LATEST"] = "latest";
204
+ EBlockTag3["PENDING"] = "pending";
205
+ return EBlockTag3;
206
+ })(EBlockTag2 || {});
207
+ var EDataAvailabilityMode2 = /* @__PURE__ */ ((EDataAvailabilityMode3) => {
208
+ EDataAvailabilityMode3["L1"] = "L1";
209
+ EDataAvailabilityMode3["L2"] = "L2";
210
+ return EDataAvailabilityMode3;
211
+ })(EDataAvailabilityMode2 || {});
212
+ var EDAMode2 = /* @__PURE__ */ ((EDAMode4) => {
213
+ EDAMode4[EDAMode4["L1"] = 0] = "L1";
214
+ EDAMode4[EDAMode4["L2"] = 1] = "L2";
215
+ return EDAMode4;
216
+ })(EDAMode2 || {});
217
+ var ETransactionVersion4 = /* @__PURE__ */ ((ETransactionVersion5) => {
218
+ ETransactionVersion5["V0"] = "0x0";
219
+ ETransactionVersion5["V1"] = "0x1";
220
+ ETransactionVersion5["V2"] = "0x2";
221
+ ETransactionVersion5["V3"] = "0x3";
222
+ ETransactionVersion5["F0"] = "0x100000000000000000000000000000000";
223
+ ETransactionVersion5["F1"] = "0x100000000000000000000000000000001";
224
+ ETransactionVersion5["F2"] = "0x100000000000000000000000000000002";
225
+ ETransactionVersion5["F3"] = "0x100000000000000000000000000000003";
226
+ return ETransactionVersion5;
227
+ })(ETransactionVersion4 || {});
228
+ var ETransactionVersion22 = /* @__PURE__ */ ((ETransactionVersion24) => {
229
+ ETransactionVersion24["V0"] = "0x0";
230
+ ETransactionVersion24["V1"] = "0x1";
231
+ ETransactionVersion24["V2"] = "0x2";
232
+ ETransactionVersion24["F0"] = "0x100000000000000000000000000000000";
233
+ ETransactionVersion24["F1"] = "0x100000000000000000000000000000001";
234
+ ETransactionVersion24["F2"] = "0x100000000000000000000000000000002";
235
+ return ETransactionVersion24;
236
+ })(ETransactionVersion22 || {});
237
+ var ETransactionVersion32 = /* @__PURE__ */ ((ETransactionVersion34) => {
238
+ ETransactionVersion34["V3"] = "0x3";
239
+ ETransactionVersion34["F3"] = "0x100000000000000000000000000000003";
240
+ return ETransactionVersion34;
241
+ })(ETransactionVersion32 || {});
242
+
127
243
  // src/utils/encode.ts
128
244
  var encode_exports = {};
129
245
  __export(encode_exports, {
@@ -218,11 +334,11 @@ var NetworkName = /* @__PURE__ */ ((NetworkName2) => {
218
334
  NetworkName2["SN_SEPOLIA"] = "SN_SEPOLIA";
219
335
  return NetworkName2;
220
336
  })(NetworkName || {});
221
- var StarknetChainId = /* @__PURE__ */ ((StarknetChainId5) => {
222
- StarknetChainId5["SN_MAIN"] = "0x534e5f4d41494e";
223
- StarknetChainId5["SN_GOERLI"] = "0x534e5f474f45524c49";
224
- StarknetChainId5["SN_SEPOLIA"] = "0x534e5f5345504f4c4941";
225
- return StarknetChainId5;
337
+ var StarknetChainId = /* @__PURE__ */ ((StarknetChainId6) => {
338
+ StarknetChainId6["SN_MAIN"] = "0x534e5f4d41494e";
339
+ StarknetChainId6["SN_GOERLI"] = "0x534e5f474f45524c49";
340
+ StarknetChainId6["SN_SEPOLIA"] = "0x534e5f5345504f4c4941";
341
+ return StarknetChainId6;
226
342
  })(StarknetChainId || {});
227
343
  var TransactionHashPrefix = /* @__PURE__ */ ((TransactionHashPrefix2) => {
228
344
  TransactionHashPrefix2["DECLARE"] = "0x6465636c617265";
@@ -289,6 +405,12 @@ var HttpError = class extends LibraryError {
289
405
  }
290
406
  };
291
407
 
408
+ // src/channel/rpc_0_6.ts
409
+ var rpc_0_6_exports = {};
410
+ __export(rpc_0_6_exports, {
411
+ RpcChannel: () => RpcChannel
412
+ });
413
+
292
414
  // src/types/index.ts
293
415
  var types_exports = {};
294
416
  __export(types_exports, {
@@ -2723,10 +2845,10 @@ function intDAM(dam) {
2723
2845
  function toTransactionVersion(defaultVersion, providedVersion) {
2724
2846
  const providedVersion0xs = providedVersion ? toHex(providedVersion) : void 0;
2725
2847
  const defaultVersion0xs = toHex(defaultVersion);
2726
- if (providedVersion && !Object.values(ETransactionVersion).includes(providedVersion0xs)) {
2848
+ if (providedVersion && !Object.values(ETransactionVersion4).includes(providedVersion0xs)) {
2727
2849
  throw Error(`providedVersion ${providedVersion} is not ETransactionVersion`);
2728
2850
  }
2729
- if (!Object.values(ETransactionVersion).includes(defaultVersion0xs)) {
2851
+ if (!Object.values(ETransactionVersion4).includes(defaultVersion0xs)) {
2730
2852
  throw Error(`defaultVersion ${defaultVersion} is not ETransactionVersion`);
2731
2853
  }
2732
2854
  return providedVersion ? providedVersion0xs : defaultVersion0xs;
@@ -3160,9 +3282,9 @@ var RpcChannel = class {
3160
3282
  const block_id = new Block(blockIdentifier).identifier;
3161
3283
  const simulationFlags = [];
3162
3284
  if (skipValidate)
3163
- simulationFlags.push(api_exports.ESimulationFlag.SKIP_VALIDATE);
3285
+ simulationFlags.push(rpcspec_0_6_exports.ESimulationFlag.SKIP_VALIDATE);
3164
3286
  if (skipFeeCharge)
3165
- simulationFlags.push(api_exports.ESimulationFlag.SKIP_FEE_CHARGE);
3287
+ simulationFlags.push(rpcspec_0_6_exports.ESimulationFlag.SKIP_FEE_CHARGE);
3166
3288
  return this.fetchEndpoint("starknet_simulateTransactions", {
3167
3289
  block_id,
3168
3290
  transactions: invocations.map((it) => this.buildTransaction(it)),
@@ -3176,15 +3298,15 @@ var RpcChannel = class {
3176
3298
  let isErrorState = false;
3177
3299
  const retryInterval = options?.retryInterval ?? 5e3;
3178
3300
  const errorStates = options?.errorStates ?? [
3179
- api_exports.ETransactionStatus.REJECTED
3301
+ rpcspec_0_6_exports.ETransactionStatus.REJECTED
3180
3302
  // TODO: commented out to preserve the long-standing behavior of "reverted" not being treated as an error by default
3181
3303
  // should decide which behavior to keep in the future
3182
3304
  // RPC.ETransactionExecutionStatus.REVERTED,
3183
3305
  ];
3184
3306
  const successStates = options?.successStates ?? [
3185
- api_exports.ETransactionExecutionStatus.SUCCEEDED,
3186
- api_exports.ETransactionStatus.ACCEPTED_ON_L2,
3187
- api_exports.ETransactionStatus.ACCEPTED_ON_L1
3307
+ rpcspec_0_6_exports.ETransactionExecutionStatus.SUCCEEDED,
3308
+ rpcspec_0_6_exports.ETransactionStatus.ACCEPTED_ON_L2,
3309
+ rpcspec_0_6_exports.ETransactionStatus.ACCEPTED_ON_L1
3188
3310
  ];
3189
3311
  let txStatus;
3190
3312
  while (!onchain) {
@@ -3267,9 +3389,9 @@ var RpcChannel = class {
3267
3389
  async getEstimateFee(invocations, { blockIdentifier = this.blockIdentifier, skipValidate = true }) {
3268
3390
  const block_id = new Block(blockIdentifier).identifier;
3269
3391
  let flags = {};
3270
- if (isVersion("0.6", await this.getSpecVersion())) {
3392
+ if (!isVersion("0.5", await this.getSpecVersion())) {
3271
3393
  flags = {
3272
- simulation_flags: skipValidate ? [api_exports.ESimulationFlag.SKIP_VALIDATE] : []
3394
+ simulation_flags: skipValidate ? [rpcspec_0_6_exports.ESimulationFlag.SKIP_VALIDATE] : []
3273
3395
  };
3274
3396
  }
3275
3397
  return this.fetchEndpoint("starknet_estimateFee", {
@@ -3285,9 +3407,9 @@ var RpcChannel = class {
3285
3407
  invoke_transaction: {
3286
3408
  sender_address: functionInvocation.contractAddress,
3287
3409
  calldata: CallData.toHex(functionInvocation.calldata),
3288
- type: api_exports.ETransactionType.INVOKE,
3410
+ type: rpcspec_0_6_exports.ETransactionType.INVOKE,
3289
3411
  max_fee: toHex(details.maxFee || 0),
3290
- version: "0x1" /* V1 */,
3412
+ version: rpcspec_0_6_exports.ETransactionVersion.V1,
3291
3413
  signature: signatureToHexArray(functionInvocation.signature),
3292
3414
  nonce: toHex(details.nonce)
3293
3415
  }
@@ -3295,10 +3417,10 @@ var RpcChannel = class {
3295
3417
  } else {
3296
3418
  promise = this.fetchEndpoint("starknet_addInvokeTransaction", {
3297
3419
  invoke_transaction: {
3298
- type: api_exports.ETransactionType.INVOKE,
3420
+ type: rpcspec_0_6_exports.ETransactionType.INVOKE,
3299
3421
  sender_address: functionInvocation.contractAddress,
3300
3422
  calldata: CallData.toHex(functionInvocation.calldata),
3301
- version: "0x3" /* V3 */,
3423
+ version: rpcspec_0_6_exports.ETransactionVersion.V3,
3302
3424
  signature: signatureToHexArray(functionInvocation.signature),
3303
3425
  nonce: toHex(details.nonce),
3304
3426
  resource_bounds: details.resourceBounds,
@@ -3317,13 +3439,13 @@ var RpcChannel = class {
3317
3439
  if (!isSierra(contract) && !isV3Tx(details)) {
3318
3440
  promise = this.fetchEndpoint("starknet_addDeclareTransaction", {
3319
3441
  declare_transaction: {
3320
- type: api_exports.ETransactionType.DECLARE,
3442
+ type: rpcspec_0_6_exports.ETransactionType.DECLARE,
3321
3443
  contract_class: {
3322
3444
  program: contract.program,
3323
3445
  entry_points_by_type: contract.entry_points_by_type,
3324
3446
  abi: contract.abi
3325
3447
  },
3326
- version: "0x1" /* V1 */,
3448
+ version: rpcspec_0_6_exports.ETransactionVersion.V1,
3327
3449
  max_fee: toHex(details.maxFee || 0),
3328
3450
  signature: signatureToHexArray(signature),
3329
3451
  sender_address: senderAddress,
@@ -3333,7 +3455,7 @@ var RpcChannel = class {
3333
3455
  } else if (isSierra(contract) && !isV3Tx(details)) {
3334
3456
  promise = this.fetchEndpoint("starknet_addDeclareTransaction", {
3335
3457
  declare_transaction: {
3336
- type: api_exports.ETransactionType.DECLARE,
3458
+ type: rpcspec_0_6_exports.ETransactionType.DECLARE,
3337
3459
  contract_class: {
3338
3460
  sierra_program: decompressProgram(contract.sierra_program),
3339
3461
  contract_class_version: contract.contract_class_version,
@@ -3341,7 +3463,7 @@ var RpcChannel = class {
3341
3463
  abi: contract.abi
3342
3464
  },
3343
3465
  compiled_class_hash: compiledClassHash || "",
3344
- version: "0x2" /* V2 */,
3466
+ version: rpcspec_0_6_exports.ETransactionVersion.V2,
3345
3467
  max_fee: toHex(details.maxFee || 0),
3346
3468
  signature: signatureToHexArray(signature),
3347
3469
  sender_address: senderAddress,
@@ -3351,10 +3473,10 @@ var RpcChannel = class {
3351
3473
  } else if (isSierra(contract) && isV3Tx(details)) {
3352
3474
  promise = this.fetchEndpoint("starknet_addDeclareTransaction", {
3353
3475
  declare_transaction: {
3354
- type: api_exports.ETransactionType.DECLARE,
3476
+ type: rpcspec_0_6_exports.ETransactionType.DECLARE,
3355
3477
  sender_address: senderAddress,
3356
3478
  compiled_class_hash: compiledClassHash || "",
3357
- version: "0x3" /* V3 */,
3479
+ version: rpcspec_0_6_exports.ETransactionVersion.V3,
3358
3480
  signature: signatureToHexArray(signature),
3359
3481
  nonce: toHex(details.nonce),
3360
3482
  contract_class: {
@@ -3384,9 +3506,9 @@ var RpcChannel = class {
3384
3506
  constructor_calldata: CallData.toHex(constructorCalldata || []),
3385
3507
  class_hash: toHex(classHash),
3386
3508
  contract_address_salt: toHex(addressSalt || 0),
3387
- type: api_exports.ETransactionType.DEPLOY_ACCOUNT,
3509
+ type: rpcspec_0_6_exports.ETransactionType.DEPLOY_ACCOUNT,
3388
3510
  max_fee: toHex(details.maxFee || 0),
3389
- version: "0x1" /* V1 */,
3511
+ version: rpcspec_0_6_exports.ETransactionVersion.V1,
3390
3512
  signature: signatureToHexArray(signature),
3391
3513
  nonce: toHex(details.nonce)
3392
3514
  }
@@ -3394,8 +3516,8 @@ var RpcChannel = class {
3394
3516
  } else {
3395
3517
  promise = this.fetchEndpoint("starknet_addDeployAccountTransaction", {
3396
3518
  deploy_account_transaction: {
3397
- type: api_exports.ETransactionType.DEPLOY_ACCOUNT,
3398
- version: "0x3" /* V3 */,
3519
+ type: rpcspec_0_6_exports.ETransactionType.DEPLOY_ACCOUNT,
3520
+ version: rpcspec_0_6_exports.ETransactionVersion.V3,
3399
3521
  signature: signatureToHexArray(signature),
3400
3522
  nonce: toHex(details.nonce),
3401
3523
  contract_address_salt: toHex(addressSalt || 0),
@@ -3478,7 +3600,7 @@ var RpcChannel = class {
3478
3600
  if (invocation.type === "INVOKE_FUNCTION" /* INVOKE */) {
3479
3601
  return {
3480
3602
  // v0 v1 v3
3481
- type: api_exports.ETransactionType.INVOKE,
3603
+ type: rpcspec_0_6_exports.ETransactionType.INVOKE,
3482
3604
  // TODO: Diff between sequencer and rpc invoke type
3483
3605
  sender_address: invocation.contractAddress,
3484
3606
  calldata: CallData.toHex(invocation.calldata),
@@ -3524,106 +3646,645 @@ var RpcChannel = class {
3524
3646
  }
3525
3647
  };
3526
3648
 
3527
- // src/utils/responseParser/rpc.ts
3528
- var RPCResponseParser = class {
3529
- parseGetBlockResponse(res) {
3530
- return { status: "PENDING", ...res };
3531
- }
3532
- parseTransactionReceipt(res) {
3533
- if ("actual_fee" in res && typeof res.actual_fee === "string") {
3534
- return {
3535
- ...res,
3536
- actual_fee: {
3537
- amount: res.actual_fee,
3538
- unit: "FRI"
3539
- }
3540
- };
3649
+ // src/channel/rpc_0_7.ts
3650
+ var rpc_0_7_exports = {};
3651
+ __export(rpc_0_7_exports, {
3652
+ RpcChannel: () => RpcChannel2
3653
+ });
3654
+ var defaultOptions2 = {
3655
+ headers: { "Content-Type": "application/json" },
3656
+ blockIdentifier: "pending" /* pending */,
3657
+ retries: 200
3658
+ };
3659
+ var RpcChannel2 = class {
3660
+ nodeUrl;
3661
+ headers;
3662
+ retries;
3663
+ requestId;
3664
+ blockIdentifier;
3665
+ chainId;
3666
+ speckVersion;
3667
+ waitMode;
3668
+ // behave like web2 rpc and return when tx is processed
3669
+ constructor(optionsOrProvider) {
3670
+ const { nodeUrl, retries, headers, blockIdentifier, chainId, waitMode } = optionsOrProvider || {};
3671
+ if (Object.values(NetworkName).includes(nodeUrl)) {
3672
+ this.nodeUrl = getDefaultNodeUrl(nodeUrl, optionsOrProvider?.default);
3673
+ } else if (nodeUrl) {
3674
+ this.nodeUrl = nodeUrl;
3675
+ } else {
3676
+ this.nodeUrl = getDefaultNodeUrl(void 0, optionsOrProvider?.default);
3541
3677
  }
3542
- return res;
3678
+ this.retries = retries || defaultOptions2.retries;
3679
+ this.headers = { ...defaultOptions2.headers, ...headers };
3680
+ this.blockIdentifier = blockIdentifier || defaultOptions2.blockIdentifier;
3681
+ this.chainId = chainId;
3682
+ this.waitMode = waitMode || false;
3683
+ this.requestId = 0;
3543
3684
  }
3544
- parseFeeEstimateResponse(res) {
3545
- const val = res[0];
3546
- return {
3547
- overall_fee: toBigInt(val.overall_fee),
3548
- gas_consumed: toBigInt(val.gas_consumed),
3549
- gas_price: toBigInt(val.gas_price),
3550
- unit: val.unit,
3551
- suggestedMaxFee: estimatedFeeToMaxFee(val.overall_fee),
3552
- resourceBounds: estimateFeeToBounds(val)
3685
+ fetch(method, params, id = 0) {
3686
+ const rpcRequestBody = {
3687
+ id,
3688
+ jsonrpc: "2.0",
3689
+ method,
3690
+ ...params && { params }
3553
3691
  };
3554
- }
3555
- parseFeeEstimateBulkResponse(res) {
3556
- return res.map((val) => ({
3557
- overall_fee: toBigInt(val.overall_fee),
3558
- gas_consumed: toBigInt(val.gas_consumed),
3559
- gas_price: toBigInt(val.gas_price),
3560
- unit: val.unit,
3561
- suggestedMaxFee: estimatedFeeToMaxFee(val.overall_fee),
3562
- resourceBounds: estimateFeeToBounds(val)
3563
- }));
3564
- }
3565
- parseSimulateTransactionResponse(res) {
3566
- return res.map((it) => {
3567
- return {
3568
- ...it,
3569
- suggestedMaxFee: estimatedFeeToMaxFee(BigInt(it.fee_estimation.overall_fee)),
3570
- resourceBounds: estimateFeeToBounds(it.fee_estimation)
3571
- };
3692
+ return fetchPonyfill_default(this.nodeUrl, {
3693
+ method: "POST",
3694
+ body: stringify2(rpcRequestBody),
3695
+ headers: this.headers
3572
3696
  });
3573
3697
  }
3574
- parseContractClassResponse(res) {
3575
- return {
3576
- ...res,
3577
- abi: typeof res.abi === "string" ? JSON.parse(res.abi) : res.abi
3578
- };
3579
- }
3580
- };
3581
-
3582
- // src/provider/rpc.ts
3583
- var RpcProvider = class {
3584
- responseParser = new RPCResponseParser();
3585
- channel;
3586
- constructor(optionsOrProvider) {
3587
- if (optionsOrProvider && "channel" in optionsOrProvider) {
3588
- this.channel = optionsOrProvider.channel;
3589
- } else {
3590
- this.channel = new RpcChannel({ ...optionsOrProvider, waitMode: false });
3698
+ errorHandler(method, params, rpcError, otherError) {
3699
+ if (rpcError) {
3700
+ const { code, message, data } = rpcError;
3701
+ throw new LibraryError(
3702
+ `RPC: ${method} with params ${stringify2(params, null, 2)}
3703
+
3704
+ ${code}: ${message}: ${stringify2(data)}`
3705
+ );
3706
+ }
3707
+ if (otherError instanceof LibraryError) {
3708
+ throw otherError;
3709
+ }
3710
+ if (otherError) {
3711
+ throw Error(otherError.message);
3591
3712
  }
3592
3713
  }
3593
- fetch(method, params, id = 0) {
3594
- return this.channel.fetch(method, params, id);
3714
+ async fetchEndpoint(method, params) {
3715
+ try {
3716
+ const rawResult = await this.fetch(method, params, this.requestId += 1);
3717
+ const { error, result } = await rawResult.json();
3718
+ this.errorHandler(method, params, error);
3719
+ return result;
3720
+ } catch (error) {
3721
+ this.errorHandler(method, params, error?.response?.data, error);
3722
+ throw error;
3723
+ }
3595
3724
  }
3596
3725
  async getChainId() {
3597
- return this.channel.getChainId();
3726
+ this.chainId ??= await this.fetchEndpoint("starknet_chainId");
3727
+ return this.chainId;
3598
3728
  }
3599
3729
  async getSpecVersion() {
3600
- return this.channel.getSpecVersion();
3601
- }
3602
- async getNonceForAddress(contractAddress, blockIdentifier) {
3603
- return this.channel.getNonceForAddress(contractAddress, blockIdentifier);
3730
+ this.speckVersion ??= await this.fetchEndpoint("starknet_specVersion");
3731
+ return this.speckVersion;
3604
3732
  }
3605
- async getBlock(blockIdentifier) {
3606
- return this.channel.getBlockWithTxHashes(blockIdentifier).then(this.responseParser.parseGetBlockResponse);
3733
+ getNonceForAddress(contractAddress, blockIdentifier = this.blockIdentifier) {
3734
+ const contract_address = toHex(contractAddress);
3735
+ const block_id = new Block(blockIdentifier).identifier;
3736
+ return this.fetchEndpoint("starknet_getNonce", {
3737
+ contract_address,
3738
+ block_id
3739
+ });
3607
3740
  }
3608
3741
  /**
3609
3742
  * Get the most recent accepted block hash and number
3610
3743
  */
3611
- async getBlockLatestAccepted() {
3612
- return this.channel.getBlockLatestAccepted();
3744
+ getBlockLatestAccepted() {
3745
+ return this.fetchEndpoint("starknet_blockHashAndNumber");
3613
3746
  }
3614
3747
  /**
3615
3748
  * Get the most recent accepted block number
3616
3749
  * redundant use getBlockLatestAccepted();
3617
3750
  * @returns Number of the latest block
3618
3751
  */
3619
- async getBlockNumber() {
3620
- return this.channel.getBlockNumber();
3752
+ getBlockNumber() {
3753
+ return this.fetchEndpoint("starknet_blockNumber");
3621
3754
  }
3622
- async getBlockWithTxHashes(blockIdentifier) {
3623
- return this.channel.getBlockWithTxHashes(blockIdentifier);
3755
+ getBlockWithTxHashes(blockIdentifier = this.blockIdentifier) {
3756
+ const block_id = new Block(blockIdentifier).identifier;
3757
+ return this.fetchEndpoint("starknet_getBlockWithTxHashes", { block_id });
3624
3758
  }
3625
- async getBlockWithTxs(blockIdentifier) {
3626
- return this.channel.getBlockWithTxs(blockIdentifier);
3759
+ getBlockWithTxs(blockIdentifier = this.blockIdentifier) {
3760
+ const block_id = new Block(blockIdentifier).identifier;
3761
+ return this.fetchEndpoint("starknet_getBlockWithTxs", { block_id });
3762
+ }
3763
+ getBlockWithReceipts(blockIdentifier = this.blockIdentifier) {
3764
+ const block_id = new Block(blockIdentifier).identifier;
3765
+ return this.fetchEndpoint("starknet_getBlockWithReceipts", { block_id });
3766
+ }
3767
+ getBlockStateUpdate(blockIdentifier = this.blockIdentifier) {
3768
+ const block_id = new Block(blockIdentifier).identifier;
3769
+ return this.fetchEndpoint("starknet_getStateUpdate", { block_id });
3770
+ }
3771
+ getBlockTransactionsTraces(blockIdentifier = this.blockIdentifier) {
3772
+ const block_id = new Block(blockIdentifier).identifier;
3773
+ return this.fetchEndpoint("starknet_traceBlockTransactions", { block_id });
3774
+ }
3775
+ getBlockTransactionCount(blockIdentifier = this.blockIdentifier) {
3776
+ const block_id = new Block(blockIdentifier).identifier;
3777
+ return this.fetchEndpoint("starknet_getBlockTransactionCount", { block_id });
3778
+ }
3779
+ getTransactionByHash(txHash) {
3780
+ const transaction_hash = toHex(txHash);
3781
+ return this.fetchEndpoint("starknet_getTransactionByHash", {
3782
+ transaction_hash
3783
+ });
3784
+ }
3785
+ getTransactionByBlockIdAndIndex(blockIdentifier, index) {
3786
+ const block_id = new Block(blockIdentifier).identifier;
3787
+ return this.fetchEndpoint("starknet_getTransactionByBlockIdAndIndex", { block_id, index });
3788
+ }
3789
+ getTransactionReceipt(txHash) {
3790
+ const transaction_hash = toHex(txHash);
3791
+ return this.fetchEndpoint("starknet_getTransactionReceipt", { transaction_hash });
3792
+ }
3793
+ getTransactionTrace(txHash) {
3794
+ const transaction_hash = toHex(txHash);
3795
+ return this.fetchEndpoint("starknet_traceTransaction", { transaction_hash });
3796
+ }
3797
+ /**
3798
+ * Get the status of a transaction
3799
+ */
3800
+ getTransactionStatus(transactionHash) {
3801
+ const transaction_hash = toHex(transactionHash);
3802
+ return this.fetchEndpoint("starknet_getTransactionStatus", { transaction_hash });
3803
+ }
3804
+ /**
3805
+ * @param invocations AccountInvocations
3806
+ * @param simulateTransactionOptions blockIdentifier and flags to skip validation and fee charge<br/>
3807
+ * - blockIdentifier<br/>
3808
+ * - skipValidate (default false)<br/>
3809
+ * - skipFeeCharge (default true)<br/>
3810
+ */
3811
+ simulateTransaction(invocations, {
3812
+ blockIdentifier = this.blockIdentifier,
3813
+ skipValidate = true,
3814
+ skipFeeCharge = true
3815
+ } = {}) {
3816
+ const block_id = new Block(blockIdentifier).identifier;
3817
+ const simulationFlags = [];
3818
+ if (skipValidate)
3819
+ simulationFlags.push(rpcspec_0_7_exports.ESimulationFlag.SKIP_VALIDATE);
3820
+ if (skipFeeCharge)
3821
+ simulationFlags.push(rpcspec_0_7_exports.ESimulationFlag.SKIP_FEE_CHARGE);
3822
+ return this.fetchEndpoint("starknet_simulateTransactions", {
3823
+ block_id,
3824
+ transactions: invocations.map((it) => this.buildTransaction(it)),
3825
+ simulation_flags: simulationFlags
3826
+ });
3827
+ }
3828
+ async waitForTransaction(txHash, options) {
3829
+ const transactionHash = toHex(txHash);
3830
+ let { retries } = this;
3831
+ let onchain = false;
3832
+ let isErrorState = false;
3833
+ const retryInterval = options?.retryInterval ?? 5e3;
3834
+ const errorStates = options?.errorStates ?? [
3835
+ rpcspec_0_7_exports.ETransactionStatus.REJECTED
3836
+ // TODO: commented out to preserve the long-standing behavior of "reverted" not being treated as an error by default
3837
+ // should decide which behavior to keep in the future
3838
+ // RPC.ETransactionExecutionStatus.REVERTED,
3839
+ ];
3840
+ const successStates = options?.successStates ?? [
3841
+ rpcspec_0_7_exports.ETransactionExecutionStatus.SUCCEEDED,
3842
+ rpcspec_0_7_exports.ETransactionStatus.ACCEPTED_ON_L2,
3843
+ rpcspec_0_7_exports.ETransactionStatus.ACCEPTED_ON_L1
3844
+ ];
3845
+ let txStatus;
3846
+ while (!onchain) {
3847
+ await wait(retryInterval);
3848
+ try {
3849
+ txStatus = await this.getTransactionStatus(transactionHash);
3850
+ const executionStatus = txStatus.execution_status;
3851
+ const finalityStatus = txStatus.finality_status;
3852
+ if (!finalityStatus) {
3853
+ const error = new Error("waiting for transaction status");
3854
+ throw error;
3855
+ }
3856
+ if (errorStates.includes(executionStatus) || errorStates.includes(finalityStatus)) {
3857
+ const message = `${executionStatus}: ${finalityStatus}`;
3858
+ const error = new Error(message);
3859
+ error.response = txStatus;
3860
+ isErrorState = true;
3861
+ throw error;
3862
+ } else if (successStates.includes(executionStatus) || successStates.includes(finalityStatus)) {
3863
+ onchain = true;
3864
+ }
3865
+ } catch (error) {
3866
+ if (error instanceof Error && isErrorState) {
3867
+ throw error;
3868
+ }
3869
+ if (retries <= 0) {
3870
+ throw new Error(`waitForTransaction timed-out with retries ${this.retries}`);
3871
+ }
3872
+ }
3873
+ retries -= 1;
3874
+ }
3875
+ let txReceipt = null;
3876
+ while (txReceipt === null) {
3877
+ try {
3878
+ txReceipt = await this.getTransactionReceipt(transactionHash);
3879
+ } catch (error) {
3880
+ if (retries <= 0) {
3881
+ throw new Error(`waitForTransaction timed-out with retries ${this.retries}`);
3882
+ }
3883
+ }
3884
+ retries -= 1;
3885
+ await wait(retryInterval);
3886
+ }
3887
+ return txReceipt;
3888
+ }
3889
+ getStorageAt(contractAddress, key, blockIdentifier = this.blockIdentifier) {
3890
+ const contract_address = toHex(contractAddress);
3891
+ const parsedKey = toStorageKey(key);
3892
+ const block_id = new Block(blockIdentifier).identifier;
3893
+ return this.fetchEndpoint("starknet_getStorageAt", {
3894
+ contract_address,
3895
+ key: parsedKey,
3896
+ block_id
3897
+ });
3898
+ }
3899
+ getClassHashAt(contractAddress, blockIdentifier = this.blockIdentifier) {
3900
+ const contract_address = toHex(contractAddress);
3901
+ const block_id = new Block(blockIdentifier).identifier;
3902
+ return this.fetchEndpoint("starknet_getClassHashAt", {
3903
+ block_id,
3904
+ contract_address
3905
+ });
3906
+ }
3907
+ getClass(classHash, blockIdentifier = this.blockIdentifier) {
3908
+ const class_hash = toHex(classHash);
3909
+ const block_id = new Block(blockIdentifier).identifier;
3910
+ return this.fetchEndpoint("starknet_getClass", {
3911
+ class_hash,
3912
+ block_id
3913
+ });
3914
+ }
3915
+ getClassAt(contractAddress, blockIdentifier = this.blockIdentifier) {
3916
+ const contract_address = toHex(contractAddress);
3917
+ const block_id = new Block(blockIdentifier).identifier;
3918
+ return this.fetchEndpoint("starknet_getClassAt", {
3919
+ block_id,
3920
+ contract_address
3921
+ });
3922
+ }
3923
+ async getEstimateFee(invocations, { blockIdentifier = this.blockIdentifier, skipValidate = true }) {
3924
+ const block_id = new Block(blockIdentifier).identifier;
3925
+ let flags = {};
3926
+ if (!isVersion("0.5", await this.getSpecVersion())) {
3927
+ flags = {
3928
+ simulation_flags: skipValidate ? [rpcspec_0_7_exports.ESimulationFlag.SKIP_VALIDATE] : []
3929
+ };
3930
+ }
3931
+ return this.fetchEndpoint("starknet_estimateFee", {
3932
+ request: invocations.map((it) => this.buildTransaction(it, "fee")),
3933
+ block_id,
3934
+ ...flags
3935
+ });
3936
+ }
3937
+ async invoke(functionInvocation, details) {
3938
+ let promise;
3939
+ if (!isV3Tx(details)) {
3940
+ promise = this.fetchEndpoint("starknet_addInvokeTransaction", {
3941
+ invoke_transaction: {
3942
+ sender_address: functionInvocation.contractAddress,
3943
+ calldata: CallData.toHex(functionInvocation.calldata),
3944
+ type: rpcspec_0_7_exports.ETransactionType.INVOKE,
3945
+ max_fee: toHex(details.maxFee || 0),
3946
+ version: rpcspec_0_7_exports.ETransactionVersion.V1,
3947
+ signature: signatureToHexArray(functionInvocation.signature),
3948
+ nonce: toHex(details.nonce)
3949
+ }
3950
+ });
3951
+ } else {
3952
+ promise = this.fetchEndpoint("starknet_addInvokeTransaction", {
3953
+ invoke_transaction: {
3954
+ type: rpcspec_0_7_exports.ETransactionType.INVOKE,
3955
+ sender_address: functionInvocation.contractAddress,
3956
+ calldata: CallData.toHex(functionInvocation.calldata),
3957
+ version: rpcspec_0_7_exports.ETransactionVersion.V3,
3958
+ signature: signatureToHexArray(functionInvocation.signature),
3959
+ nonce: toHex(details.nonce),
3960
+ resource_bounds: details.resourceBounds,
3961
+ tip: toHex(details.tip),
3962
+ paymaster_data: details.paymasterData.map((it) => toHex(it)),
3963
+ account_deployment_data: details.accountDeploymentData.map((it) => toHex(it)),
3964
+ nonce_data_availability_mode: details.nonceDataAvailabilityMode,
3965
+ fee_data_availability_mode: details.feeDataAvailabilityMode
3966
+ }
3967
+ });
3968
+ }
3969
+ return this.waitMode ? this.waitForTransaction((await promise).transaction_hash) : promise;
3970
+ }
3971
+ async declare({ contract, signature, senderAddress, compiledClassHash }, details) {
3972
+ let promise;
3973
+ if (!isSierra(contract) && !isV3Tx(details)) {
3974
+ promise = this.fetchEndpoint("starknet_addDeclareTransaction", {
3975
+ declare_transaction: {
3976
+ type: rpcspec_0_7_exports.ETransactionType.DECLARE,
3977
+ contract_class: {
3978
+ program: contract.program,
3979
+ entry_points_by_type: contract.entry_points_by_type,
3980
+ abi: contract.abi
3981
+ },
3982
+ version: rpcspec_0_7_exports.ETransactionVersion.V1,
3983
+ max_fee: toHex(details.maxFee || 0),
3984
+ signature: signatureToHexArray(signature),
3985
+ sender_address: senderAddress,
3986
+ nonce: toHex(details.nonce)
3987
+ }
3988
+ });
3989
+ } else if (isSierra(contract) && !isV3Tx(details)) {
3990
+ promise = this.fetchEndpoint("starknet_addDeclareTransaction", {
3991
+ declare_transaction: {
3992
+ type: rpcspec_0_7_exports.ETransactionType.DECLARE,
3993
+ contract_class: {
3994
+ sierra_program: decompressProgram(contract.sierra_program),
3995
+ contract_class_version: contract.contract_class_version,
3996
+ entry_points_by_type: contract.entry_points_by_type,
3997
+ abi: contract.abi
3998
+ },
3999
+ compiled_class_hash: compiledClassHash || "",
4000
+ version: rpcspec_0_7_exports.ETransactionVersion.V2,
4001
+ max_fee: toHex(details.maxFee || 0),
4002
+ signature: signatureToHexArray(signature),
4003
+ sender_address: senderAddress,
4004
+ nonce: toHex(details.nonce)
4005
+ }
4006
+ });
4007
+ } else if (isSierra(contract) && isV3Tx(details)) {
4008
+ promise = this.fetchEndpoint("starknet_addDeclareTransaction", {
4009
+ declare_transaction: {
4010
+ type: rpcspec_0_7_exports.ETransactionType.DECLARE,
4011
+ sender_address: senderAddress,
4012
+ compiled_class_hash: compiledClassHash || "",
4013
+ version: rpcspec_0_7_exports.ETransactionVersion.V3,
4014
+ signature: signatureToHexArray(signature),
4015
+ nonce: toHex(details.nonce),
4016
+ contract_class: {
4017
+ sierra_program: decompressProgram(contract.sierra_program),
4018
+ contract_class_version: contract.contract_class_version,
4019
+ entry_points_by_type: contract.entry_points_by_type,
4020
+ abi: contract.abi
4021
+ },
4022
+ resource_bounds: details.resourceBounds,
4023
+ tip: toHex(details.tip),
4024
+ paymaster_data: details.paymasterData.map((it) => toHex(it)),
4025
+ account_deployment_data: details.accountDeploymentData.map((it) => toHex(it)),
4026
+ nonce_data_availability_mode: details.nonceDataAvailabilityMode,
4027
+ fee_data_availability_mode: details.feeDataAvailabilityMode
4028
+ }
4029
+ });
4030
+ } else {
4031
+ throw Error("declare unspotted parameters");
4032
+ }
4033
+ return this.waitMode ? this.waitForTransaction((await promise).transaction_hash) : promise;
4034
+ }
4035
+ async deployAccount({ classHash, constructorCalldata, addressSalt, signature }, details) {
4036
+ let promise;
4037
+ if (!isV3Tx(details)) {
4038
+ promise = this.fetchEndpoint("starknet_addDeployAccountTransaction", {
4039
+ deploy_account_transaction: {
4040
+ constructor_calldata: CallData.toHex(constructorCalldata || []),
4041
+ class_hash: toHex(classHash),
4042
+ contract_address_salt: toHex(addressSalt || 0),
4043
+ type: rpcspec_0_7_exports.ETransactionType.DEPLOY_ACCOUNT,
4044
+ max_fee: toHex(details.maxFee || 0),
4045
+ version: rpcspec_0_7_exports.ETransactionVersion.V1,
4046
+ signature: signatureToHexArray(signature),
4047
+ nonce: toHex(details.nonce)
4048
+ }
4049
+ });
4050
+ } else {
4051
+ promise = this.fetchEndpoint("starknet_addDeployAccountTransaction", {
4052
+ deploy_account_transaction: {
4053
+ type: rpcspec_0_7_exports.ETransactionType.DEPLOY_ACCOUNT,
4054
+ version: rpcspec_0_7_exports.ETransactionVersion.V3,
4055
+ signature: signatureToHexArray(signature),
4056
+ nonce: toHex(details.nonce),
4057
+ contract_address_salt: toHex(addressSalt || 0),
4058
+ constructor_calldata: CallData.toHex(constructorCalldata || []),
4059
+ class_hash: toHex(classHash),
4060
+ resource_bounds: details.resourceBounds,
4061
+ tip: toHex(details.tip),
4062
+ paymaster_data: details.paymasterData.map((it) => toHex(it)),
4063
+ nonce_data_availability_mode: details.nonceDataAvailabilityMode,
4064
+ fee_data_availability_mode: details.feeDataAvailabilityMode
4065
+ }
4066
+ });
4067
+ }
4068
+ return this.waitMode ? this.waitForTransaction((await promise).transaction_hash) : promise;
4069
+ }
4070
+ callContract(call, blockIdentifier = this.blockIdentifier) {
4071
+ const block_id = new Block(blockIdentifier).identifier;
4072
+ return this.fetchEndpoint("starknet_call", {
4073
+ request: {
4074
+ contract_address: call.contractAddress,
4075
+ entry_point_selector: getSelectorFromName(call.entrypoint),
4076
+ calldata: CallData.toHex(call.calldata)
4077
+ },
4078
+ block_id
4079
+ });
4080
+ }
4081
+ /**
4082
+ * NEW: Estimate the fee for a message from L1
4083
+ * @param message Message From L1
4084
+ */
4085
+ estimateMessageFee(message, blockIdentifier = this.blockIdentifier) {
4086
+ const { from_address, to_address, entry_point_selector, payload } = message;
4087
+ const formattedMessage = {
4088
+ from_address: toHex(from_address),
4089
+ to_address: toHex(to_address),
4090
+ entry_point_selector: getSelector(entry_point_selector),
4091
+ payload: getHexStringArray(payload)
4092
+ };
4093
+ const block_id = new Block(blockIdentifier).identifier;
4094
+ return this.fetchEndpoint("starknet_estimateMessageFee", {
4095
+ message: formattedMessage,
4096
+ block_id
4097
+ });
4098
+ }
4099
+ /**
4100
+ * Returns an object about the sync status, or false if the node is not synching
4101
+ * @returns Object with the stats data
4102
+ */
4103
+ getSyncingStats() {
4104
+ return this.fetchEndpoint("starknet_syncing");
4105
+ }
4106
+ /**
4107
+ * Returns all events matching the given filter
4108
+ * @returns events and the pagination of the events
4109
+ */
4110
+ getEvents(eventFilter) {
4111
+ return this.fetchEndpoint("starknet_getEvents", { filter: eventFilter });
4112
+ }
4113
+ buildTransaction(invocation, versionType) {
4114
+ const defaultVersions = getVersionsByType(versionType);
4115
+ let details;
4116
+ if (!isV3Tx(invocation)) {
4117
+ details = {
4118
+ signature: signatureToHexArray(invocation.signature),
4119
+ nonce: toHex(invocation.nonce),
4120
+ max_fee: toHex(invocation.maxFee || 0)
4121
+ };
4122
+ } else {
4123
+ details = {
4124
+ signature: signatureToHexArray(invocation.signature),
4125
+ nonce: toHex(invocation.nonce),
4126
+ resource_bounds: invocation.resourceBounds,
4127
+ tip: toHex(invocation.tip),
4128
+ paymaster_data: invocation.paymasterData.map((it) => toHex(it)),
4129
+ nonce_data_availability_mode: invocation.nonceDataAvailabilityMode,
4130
+ fee_data_availability_mode: invocation.feeDataAvailabilityMode,
4131
+ account_deployment_data: invocation.accountDeploymentData.map((it) => toHex(it))
4132
+ };
4133
+ }
4134
+ if (invocation.type === "INVOKE_FUNCTION" /* INVOKE */) {
4135
+ return {
4136
+ // v0 v1 v3
4137
+ type: rpcspec_0_7_exports.ETransactionType.INVOKE,
4138
+ // TODO: Diff between sequencer and rpc invoke type
4139
+ sender_address: invocation.contractAddress,
4140
+ calldata: CallData.toHex(invocation.calldata),
4141
+ version: toHex(invocation.version || defaultVersions.v3),
4142
+ ...details
4143
+ };
4144
+ }
4145
+ if (invocation.type === "DECLARE" /* DECLARE */) {
4146
+ if (!isSierra(invocation.contract)) {
4147
+ return {
4148
+ type: invocation.type,
4149
+ contract_class: invocation.contract,
4150
+ sender_address: invocation.senderAddress,
4151
+ version: toHex(invocation.version || defaultVersions.v1),
4152
+ ...details
4153
+ };
4154
+ }
4155
+ return {
4156
+ // Cairo 1 - v2 v3
4157
+ type: invocation.type,
4158
+ contract_class: {
4159
+ ...invocation.contract,
4160
+ sierra_program: decompressProgram(invocation.contract.sierra_program)
4161
+ },
4162
+ compiled_class_hash: invocation.compiledClassHash || "",
4163
+ sender_address: invocation.senderAddress,
4164
+ version: toHex(invocation.version || defaultVersions.v3),
4165
+ ...details
4166
+ };
4167
+ }
4168
+ if (invocation.type === "DEPLOY_ACCOUNT" /* DEPLOY_ACCOUNT */) {
4169
+ const { account_deployment_data, ...restDetails } = details;
4170
+ return {
4171
+ type: invocation.type,
4172
+ constructor_calldata: CallData.toHex(invocation.constructorCalldata || []),
4173
+ class_hash: toHex(invocation.classHash),
4174
+ contract_address_salt: toHex(invocation.addressSalt || 0),
4175
+ version: toHex(invocation.version || defaultVersions.v3),
4176
+ ...restDetails
4177
+ };
4178
+ }
4179
+ throw Error("RPC buildTransaction received unknown TransactionType");
4180
+ }
4181
+ };
4182
+
4183
+ // src/utils/responseParser/rpc.ts
4184
+ var RPCResponseParser = class {
4185
+ parseGetBlockResponse(res) {
4186
+ return { status: "PENDING", ...res };
4187
+ }
4188
+ parseTransactionReceipt(res) {
4189
+ if ("actual_fee" in res && typeof res.actual_fee === "string") {
4190
+ return {
4191
+ ...res,
4192
+ actual_fee: {
4193
+ amount: res.actual_fee,
4194
+ unit: "FRI"
4195
+ }
4196
+ };
4197
+ }
4198
+ return res;
4199
+ }
4200
+ parseFeeEstimateResponse(res) {
4201
+ const val = res[0];
4202
+ return {
4203
+ overall_fee: toBigInt(val.overall_fee),
4204
+ gas_consumed: toBigInt(val.gas_consumed),
4205
+ gas_price: toBigInt(val.gas_price),
4206
+ unit: val.unit,
4207
+ suggestedMaxFee: estimatedFeeToMaxFee(val.overall_fee),
4208
+ resourceBounds: estimateFeeToBounds(val)
4209
+ };
4210
+ }
4211
+ parseFeeEstimateBulkResponse(res) {
4212
+ return res.map((val) => ({
4213
+ overall_fee: toBigInt(val.overall_fee),
4214
+ gas_consumed: toBigInt(val.gas_consumed),
4215
+ gas_price: toBigInt(val.gas_price),
4216
+ unit: val.unit,
4217
+ suggestedMaxFee: estimatedFeeToMaxFee(val.overall_fee),
4218
+ resourceBounds: estimateFeeToBounds(val)
4219
+ }));
4220
+ }
4221
+ parseSimulateTransactionResponse(res) {
4222
+ return res.map((it) => {
4223
+ return {
4224
+ ...it,
4225
+ suggestedMaxFee: estimatedFeeToMaxFee(BigInt(it.fee_estimation.overall_fee)),
4226
+ resourceBounds: estimateFeeToBounds(it.fee_estimation)
4227
+ };
4228
+ });
4229
+ }
4230
+ parseContractClassResponse(res) {
4231
+ return {
4232
+ ...res,
4233
+ abi: typeof res.abi === "string" ? JSON.parse(res.abi) : res.abi
4234
+ };
4235
+ }
4236
+ };
4237
+
4238
+ // src/provider/rpc.ts
4239
+ var RpcProvider = class {
4240
+ responseParser = new RPCResponseParser();
4241
+ channel;
4242
+ constructor(optionsOrProvider) {
4243
+ if (optionsOrProvider && "channel" in optionsOrProvider) {
4244
+ this.channel = optionsOrProvider.channel;
4245
+ } else {
4246
+ this.channel = new RpcChannel2({ ...optionsOrProvider, waitMode: false });
4247
+ }
4248
+ }
4249
+ fetch(method, params, id = 0) {
4250
+ return this.channel.fetch(method, params, id);
4251
+ }
4252
+ async getChainId() {
4253
+ return this.channel.getChainId();
4254
+ }
4255
+ async getSpecVersion() {
4256
+ return this.channel.getSpecVersion();
4257
+ }
4258
+ async getNonceForAddress(contractAddress, blockIdentifier) {
4259
+ return this.channel.getNonceForAddress(contractAddress, blockIdentifier);
4260
+ }
4261
+ async getBlock(blockIdentifier) {
4262
+ return this.channel.getBlockWithTxHashes(blockIdentifier).then(this.responseParser.parseGetBlockResponse);
4263
+ }
4264
+ /**
4265
+ * Get the most recent accepted block hash and number
4266
+ */
4267
+ async getBlockLatestAccepted() {
4268
+ return this.channel.getBlockLatestAccepted();
4269
+ }
4270
+ /**
4271
+ * Get the most recent accepted block number
4272
+ * redundant use getBlockLatestAccepted();
4273
+ * @returns Number of the latest block
4274
+ */
4275
+ async getBlockNumber() {
4276
+ return this.channel.getBlockNumber();
4277
+ }
4278
+ async getBlockWithTxHashes(blockIdentifier) {
4279
+ return this.channel.getBlockWithTxHashes(blockIdentifier);
4280
+ }
4281
+ async getBlockWithTxs(blockIdentifier) {
4282
+ return this.channel.getBlockWithTxs(blockIdentifier);
4283
+ }
4284
+ async getBlockWithReceipts(blockIdentifier) {
4285
+ if (this.channel instanceof rpc_0_6_exports.RpcChannel)
4286
+ throw new LibraryError("Unsupported method for RPC version");
4287
+ return this.channel.getBlockWithReceipts(blockIdentifier);
3627
4288
  }
3628
4289
  getStateUpdate = this.getBlockStateUpdate;
3629
4290
  async getBlockStateUpdate(blockIdentifier) {
@@ -4341,7 +5002,7 @@ var Signer = class {
4341
5002
  async signTransaction(transactions, details) {
4342
5003
  const compiledCalldata = getExecuteCalldata(transactions, details.cairoVersion);
4343
5004
  let msgHash;
4344
- if (Object.values(ETransactionVersion2).includes(details.version)) {
5005
+ if (Object.values(ETransactionVersion22).includes(details.version)) {
4345
5006
  const det = details;
4346
5007
  msgHash = calculateInvokeTransactionHash2({
4347
5008
  ...det,
@@ -4349,7 +5010,7 @@ var Signer = class {
4349
5010
  compiledCalldata,
4350
5011
  version: det.version
4351
5012
  });
4352
- } else if (Object.values(ETransactionVersion3).includes(details.version)) {
5013
+ } else if (Object.values(ETransactionVersion32).includes(details.version)) {
4353
5014
  const det = details;
4354
5015
  msgHash = calculateInvokeTransactionHash2({
4355
5016
  ...det,
@@ -4367,7 +5028,7 @@ var Signer = class {
4367
5028
  async signDeployAccountTransaction(details) {
4368
5029
  const compiledConstructorCalldata = CallData.compile(details.constructorCalldata);
4369
5030
  let msgHash;
4370
- if (Object.values(ETransactionVersion2).includes(details.version)) {
5031
+ if (Object.values(ETransactionVersion22).includes(details.version)) {
4371
5032
  const det = details;
4372
5033
  msgHash = calculateDeployAccountTransactionHash3({
4373
5034
  ...det,
@@ -4375,7 +5036,7 @@ var Signer = class {
4375
5036
  constructorCalldata: compiledConstructorCalldata,
4376
5037
  version: det.version
4377
5038
  });
4378
- } else if (Object.values(ETransactionVersion3).includes(details.version)) {
5039
+ } else if (Object.values(ETransactionVersion32).includes(details.version)) {
4379
5040
  const det = details;
4380
5041
  msgHash = calculateDeployAccountTransactionHash3({
4381
5042
  ...det,
@@ -4392,13 +5053,13 @@ var Signer = class {
4392
5053
  }
4393
5054
  async signDeclareTransaction(details) {
4394
5055
  let msgHash;
4395
- if (Object.values(ETransactionVersion2).includes(details.version)) {
5056
+ if (Object.values(ETransactionVersion22).includes(details.version)) {
4396
5057
  const det = details;
4397
5058
  msgHash = calculateDeclareTransactionHash3({
4398
5059
  ...det,
4399
5060
  version: det.version
4400
5061
  });
4401
- } else if (Object.values(ETransactionVersion3).includes(details.version)) {
5062
+ } else if (Object.values(ETransactionVersion32).includes(details.version)) {
4402
5063
  const det = details;
4403
5064
  msgHash = calculateDeclareTransactionHash3({
4404
5065
  ...det,
@@ -4446,7 +5107,7 @@ var EthSigner = class {
4446
5107
  async signTransaction(transactions, details) {
4447
5108
  const compiledCalldata = getExecuteCalldata(transactions, details.cairoVersion);
4448
5109
  let msgHash;
4449
- if (Object.values(ETransactionVersion2).includes(details.version)) {
5110
+ if (Object.values(ETransactionVersion22).includes(details.version)) {
4450
5111
  const det = details;
4451
5112
  msgHash = calculateInvokeTransactionHash2({
4452
5113
  ...det,
@@ -4454,7 +5115,7 @@ var EthSigner = class {
4454
5115
  compiledCalldata,
4455
5116
  version: det.version
4456
5117
  });
4457
- } else if (Object.values(ETransactionVersion3).includes(details.version)) {
5118
+ } else if (Object.values(ETransactionVersion32).includes(details.version)) {
4458
5119
  const det = details;
4459
5120
  msgHash = calculateInvokeTransactionHash2({
4460
5121
  ...det,
@@ -4472,7 +5133,7 @@ var EthSigner = class {
4472
5133
  async signDeployAccountTransaction(details) {
4473
5134
  const compiledConstructorCalldata = CallData.compile(details.constructorCalldata);
4474
5135
  let msgHash;
4475
- if (Object.values(ETransactionVersion2).includes(details.version)) {
5136
+ if (Object.values(ETransactionVersion22).includes(details.version)) {
4476
5137
  const det = details;
4477
5138
  msgHash = calculateDeployAccountTransactionHash3({
4478
5139
  ...det,
@@ -4480,7 +5141,7 @@ var EthSigner = class {
4480
5141
  constructorCalldata: compiledConstructorCalldata,
4481
5142
  version: det.version
4482
5143
  });
4483
- } else if (Object.values(ETransactionVersion3).includes(details.version)) {
5144
+ } else if (Object.values(ETransactionVersion32).includes(details.version)) {
4484
5145
  const det = details;
4485
5146
  msgHash = calculateDeployAccountTransactionHash3({
4486
5147
  ...det,
@@ -4497,13 +5158,13 @@ var EthSigner = class {
4497
5158
  }
4498
5159
  async signDeclareTransaction(details) {
4499
5160
  let msgHash;
4500
- if (Object.values(ETransactionVersion2).includes(details.version)) {
5161
+ if (Object.values(ETransactionVersion22).includes(details.version)) {
4501
5162
  const det = details;
4502
5163
  msgHash = calculateDeclareTransactionHash3({
4503
5164
  ...det,
4504
5165
  version: det.version
4505
5166
  });
4506
- } else if (Object.values(ETransactionVersion3).includes(details.version)) {
5167
+ } else if (Object.values(ETransactionVersion32).includes(details.version)) {
4507
5168
  const det = details;
4508
5169
  msgHash = calculateDeclareTransactionHash3({
4509
5170
  ...det,
@@ -5652,7 +6313,9 @@ export {
5652
6313
  RpcProvider2 as Provider,
5653
6314
  ProviderInterface,
5654
6315
  api_exports as RPC,
5655
- RpcChannel,
6316
+ rpc_0_6_exports as RPC06,
6317
+ rpc_0_7_exports as RPC07,
6318
+ RpcChannel2 as RpcChannel,
5656
6319
  RpcProvider2 as RpcProvider,
5657
6320
  SIMULATION_FLAG,
5658
6321
  Signer,