/
interface.ts
363 lines (339 loc) · 11.7 KB
/
interface.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
import { StarknetChainId } from '../constants';
import type {
AccountInvocations,
BigNumberish,
BlockIdentifier,
Call,
CallContractResponse,
ContractClassResponse,
ContractVersion,
DeclareContractResponse,
DeclareContractTransaction,
DeployAccountContractPayload,
DeployAccountContractTransaction,
DeployContractResponse,
EstimateFeeResponse,
EstimateFeeResponseBulk,
GetBlockResponse,
GetCodeResponse,
GetTransactionReceiptResponse,
GetTransactionResponse,
Invocation,
InvocationsDetailsWithNonce,
InvokeFunctionResponse,
Nonce,
SimulateTransactionResponse,
StateUpdateResponse,
Storage,
getContractVersionOptions,
getEstimateFeeBulkOptions,
getSimulateTransactionOptions,
waitForTransactionOptions,
} from '../types';
export abstract class ProviderInterface {
/**
* Gets the Starknet chain Id
*
* @returns the chain Id
*/
public abstract getChainId(): Promise<StarknetChainId>;
/**
* Calls a function on the Starknet contract.
*
* @param call transaction to be called
* @param blockIdentifier block identifier
* @returns the result of the function on the smart contract.
*/
public abstract callContract(
call: Call,
blockIdentifier?: BlockIdentifier
): Promise<CallContractResponse>;
/**
* Gets the block information
*
* @param blockIdentifier block identifier
* @returns the block object
*/
public abstract getBlock(blockIdentifier: BlockIdentifier): Promise<GetBlockResponse>;
/**
* @deprecated The method should not be used
*/
public abstract getCode(
contractAddress: string,
blockIdentifier?: BlockIdentifier
): Promise<GetCodeResponse>;
/**
* Gets the contract class of the deployed contract.
*
* @param contractAddress - contract address
* @param blockIdentifier - block identifier
* @returns Contract class of compiled contract
*/
public abstract getClassAt(
contractAddress: string,
blockIdentifier?: BlockIdentifier
): Promise<ContractClassResponse>;
/**
* Returns the contract class hash in the given block for the contract deployed at the given address
*
* @param contractAddress - contract address
* @param blockIdentifier - block identifier
* @returns Class hash
*/
public abstract getClassHashAt(
contractAddress: string,
blockIdentifier?: BlockIdentifier
): Promise<string>;
/**
* Returns the contract class deployed under the given class hash.
*
* @param classHash - class hash
* @returns Contract class of compiled contract
*/
public abstract getClassByHash(classHash: string): Promise<ContractClassResponse>;
/**
* Returns the nonce associated with the given address in the given block
*
* @param contractAddress - contract address
* @returns the hex nonce
*/
public abstract getNonceForAddress(
contractAddress: string,
blockIdentifier?: BlockIdentifier
): Promise<Nonce>;
/**
* Get the value of the storage (contract's variable) at the given address and key
*
* @param contractAddress
* @param key - from getStorageVarAddress('<STORAGE_VARIABLE_NAME>') (WIP)
* @param blockIdentifier - block identifier
* @returns the value of the storage variable
*/
public abstract getStorageAt(
contractAddress: string,
key: BigNumberish,
blockIdentifier?: BlockIdentifier
): Promise<Storage>;
/**
* Gets the transaction information from a tx id.
*
* @param txHash
* @returns the transaction object \{ transaction_id, status, transaction, block_number?, block_number?, transaction_index?, transaction_failure_reason? \}
*/
public abstract getTransaction(transactionHash: BigNumberish): Promise<GetTransactionResponse>;
/**
* Gets the transaction receipt from a tx hash.
*
* @param txHash
* @returns the transaction receipt object
*/
public abstract getTransactionReceipt(
transactionHash: BigNumberish
): Promise<GetTransactionReceiptResponse>;
/**
* Deploys a given compiled Account contract (json) to starknet
*
* @param payload payload to be deployed containing:
* - compiled contract code
* - constructor calldata
* - address salt
* @returns a confirmation of sending a transaction on the starknet contract
*/
public abstract deployAccountContract(
payload: DeployAccountContractPayload,
details: InvocationsDetailsWithNonce
): Promise<DeployContractResponse>;
/**
* Invokes a function on starknet
* @deprecated This method wont be supported as soon as fees are mandatory. Should not be used outside of Account class
*
* @param invocation the invocation object containing:
* - contractAddress - the address of the contract
* - entrypoint - the entrypoint of the contract
* - calldata - (defaults to []) the calldata
* - signature - (defaults to []) the signature
* @param details - optional details containing:
* - nonce - optional nonce
* - version - optional version
* - maxFee - optional maxFee
* @returns response from addTransaction
*/
public abstract invokeFunction(
invocation: Invocation,
details: InvocationsDetailsWithNonce
): Promise<InvokeFunctionResponse>;
/**
* Declares a given compiled contract (json) to starknet
* @param transaction transaction payload to be deployed containing:
* - compiled contract code
* - sender address
* - signature
* @param details Invocation Details containing:
* - nonce
* - optional version
* - optional maxFee
* @returns a confirmation of sending a transaction on the starknet contract
*/
public abstract declareContract(
transaction: DeclareContractTransaction,
details: InvocationsDetailsWithNonce
): Promise<DeclareContractResponse>;
/**
* Estimates the fee for a given INVOKE transaction
* @deprecated Please use getInvokeEstimateFee or getDeclareEstimateFee instead. Should not be used outside of Account class
*
* @param invocation the invocation object containing:
* - contractAddress - the address of the contract
* - entrypoint - the entrypoint of the contract
* - calldata - (defaults to []) the calldata
* - signature - (defaults to []) the signature
* @param details - optional details containing:
* - nonce - optional nonce
* - version - optional version
* @param blockIdentifier - (optional) block identifier
* @param skipValidate - (optional) skip cairo __validate__ method
* @returns the estimated fee
*/
public abstract getEstimateFee(
invocation: Invocation,
details: InvocationsDetailsWithNonce,
blockIdentifier: BlockIdentifier,
skipValidate?: boolean
): Promise<EstimateFeeResponse>;
/**
* Estimates the fee for a given INVOKE transaction
*
* @param invocation the invocation object containing:
* - contractAddress - the address of the contract
* - entrypoint - the entrypoint of the contract
* - calldata - (defaults to []) the calldata
* - signature - (defaults to []) the signature
* @param details - optional details containing:
* - nonce - optional nonce
* - version - optional version
* @param blockIdentifier - (optional) block identifier
* @param skipValidate - (optional) skip cairo __validate__ method
* @returns the estimated fee
*/
public abstract getInvokeEstimateFee(
invocation: Invocation,
details: InvocationsDetailsWithNonce,
blockIdentifier?: BlockIdentifier,
skipValidate?: boolean
): Promise<EstimateFeeResponse>;
/**
* Estimates the fee for a given DECLARE transaction
*
* @param transaction transaction payload to be declared containing:
* - compiled contract code
* - sender address
* - signature - (defaults to []) the signature
* @param details - optional details containing:
* - nonce
* - version - optional version
* - optional maxFee
* @param blockIdentifier - (optional) block identifier
* @param skipValidate - (optional) skip cairo __validate__ method
* @returns the estimated fee
*/
public abstract getDeclareEstimateFee(
transaction: DeclareContractTransaction,
details: InvocationsDetailsWithNonce,
blockIdentifier?: BlockIdentifier,
skipValidate?: boolean
): Promise<EstimateFeeResponse>;
/**
* Estimates the fee for a given DEPLOY_ACCOUNT transaction
*
* @param transaction transaction payload to be deployed containing:
* - classHash
* - constructorCalldata
* - addressSalt
* - signature - (defaults to []) the signature
* @param details - optional details containing:
* - nonce
* - version - optional version
* - optional maxFee
* @param blockIdentifier - (optional) block identifier
* @param skipValidate - (optional) skip cairo __validate__ method
* @returns the estimated fee
*/
public abstract getDeployAccountEstimateFee(
transaction: DeployAccountContractTransaction,
details: InvocationsDetailsWithNonce,
blockIdentifier?: BlockIdentifier,
skipValidate?: boolean
): Promise<EstimateFeeResponse>;
/**
* Estimates the fee for a list of INVOKE transaction
*
* @param invocations AccountInvocations - Complete invocations array with account details
* @param options getEstimateFeeBulkOptions
* - (optional) blockIdentifier - BlockIdentifier
* - (optional) skipValidate - boolean (default false)
* @returns the estimated fee
*/
public abstract getEstimateFeeBulk(
invocations: AccountInvocations,
options?: getEstimateFeeBulkOptions
): Promise<EstimateFeeResponseBulk>;
/**
* Wait for the transaction to be accepted
* @param txHash - transaction hash
* @param options waitForTransactionOptions
* - (optional) retryInterval: number | undefined;
* - (optional) successStates: TransactionStatus[] | undefined;
* @return GetTransactionReceiptResponse
*/
public abstract waitForTransaction(
txHash: BigNumberish,
options?: waitForTransactionOptions
): Promise<GetTransactionReceiptResponse>;
/**
* Simulates the transaction and returns the transaction trace and estimated fee.
*
* @param invocations AccountInvocations - Complete invocations array with account details
* @param options - getSimulateTransactionOptions
* - (optional) blockIdentifier - block identifier
* - (optional) skipValidate - skip cairo __validate__ method
* - (optional) skipExecute - skip cairo __execute__ method
* @returns an array of transaction trace and estimated fee
*/
public abstract getSimulateTransaction(
invocations: AccountInvocations,
options?: getSimulateTransactionOptions
): Promise<SimulateTransactionResponse>;
/**
* Gets the state changes in a specific block (result of executing the requested block)
*
* @param blockIdentifier - block identifier
* @returns StateUpdateResponse
*/
public abstract getStateUpdate(blockIdentifier?: BlockIdentifier): Promise<StateUpdateResponse>;
/**
* Gets the contract version from the provided address
* @param contractAddress string
* @param classHash undefined
* @param options - getContractVersionOptions
* - (optional) compiler - (default true) extract compiler version using type tactic from abi
* - (optional) blockIdentifier - block identifier
*/
public abstract getContractVersion(
contractAddress: string,
classHash?: undefined,
options?: getContractVersionOptions
): Promise<ContractVersion>;
/**
* Gets the contract version from the provided address
* @param contractAddress undefined
* @param classHash
* @param options - getContractVersionOptions
* - (optional) compiler - (default true) extract compiler version using type tactic from abi
* - (optional) blockIdentifier - block identifier
*/
public abstract getContractVersion(
contractAddress: undefined,
classHash: string,
options?: getContractVersionOptions
): Promise<ContractVersion>;
}