starknet 4.10.0 → 4.12.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/CHANGELOG.md +32 -0
- package/__tests__/account.test.ts +42 -0
- package/__tests__/defaultProvider.test.ts +22 -12
- package/__tests__/fixtures.ts +3 -1
- package/__tests__/rpcProvider.test.ts +6 -4
- package/account/default.js +3 -3
- package/dist/account/default.js +3 -3
- package/dist/provider/default.d.ts +4 -2
- package/dist/provider/default.js +13 -2
- package/dist/provider/interface.d.ts +18 -3
- package/dist/provider/rpc.d.ts +13 -9
- package/dist/provider/rpc.js +63 -29
- package/dist/provider/sequencer.d.ts +2 -0
- package/dist/provider/sequencer.js +15 -0
- package/dist/types/api/openrpc.d.ts +147 -98
- package/dist/types/api/openrpc.js +22 -4
- package/dist/types/lib.d.ts +9 -2
- package/dist/types/lib.js +6 -0
- package/package.json +1 -1
- package/provider/default.d.ts +4 -2
- package/provider/default.js +13 -2
- package/provider/interface.d.ts +18 -3
- package/provider/rpc.d.ts +13 -9
- package/provider/rpc.js +63 -29
- package/provider/sequencer.d.ts +2 -0
- package/provider/sequencer.js +15 -0
- package/src/account/default.ts +8 -4
- package/src/provider/default.ts +21 -3
- package/src/provider/interface.ts +26 -2
- package/src/provider/rpc.ts +70 -42
- package/src/provider/sequencer.ts +11 -0
- package/src/types/api/openrpc.ts +193 -105
- package/src/types/api/rpc.ts +0 -1
- package/src/types/lib.ts +10 -2
- package/types/api/openrpc.d.ts +147 -98
- package/types/api/openrpc.js +22 -4
- package/types/lib.d.ts +9 -2
- package/types/lib.js +6 -0
- package/__tests__/udc.test.ts +0 -41
package/src/provider/rpc.ts
CHANGED
|
@@ -8,7 +8,6 @@ import {
|
|
|
8
8
|
EstimateFeeResponse,
|
|
9
9
|
GetBlockResponse,
|
|
10
10
|
GetCodeResponse,
|
|
11
|
-
GetTransactionReceiptResponse,
|
|
12
11
|
GetTransactionResponse,
|
|
13
12
|
Invocation,
|
|
14
13
|
InvocationsDetailsWithNonce,
|
|
@@ -17,8 +16,8 @@ import {
|
|
|
17
16
|
import { RPC } from '../types/api';
|
|
18
17
|
import {
|
|
19
18
|
DeclareContractTransaction,
|
|
20
|
-
DeployAccountContractPayload,
|
|
21
19
|
DeployAccountContractTransaction,
|
|
20
|
+
InvocationsDetails,
|
|
22
21
|
} from '../types/lib';
|
|
23
22
|
import fetch from '../utils/fetchPonyfill';
|
|
24
23
|
import { getSelectorFromName } from '../utils/hash';
|
|
@@ -65,7 +64,7 @@ export class RpcProvider implements ProviderInterface {
|
|
|
65
64
|
}
|
|
66
65
|
|
|
67
66
|
public fetch(method: any, params: any): Promise<any> {
|
|
68
|
-
return fetch(this.nodeUrl
|
|
67
|
+
return fetch(`${this.nodeUrl}/rpc/v0.2`, {
|
|
69
68
|
method: 'POST',
|
|
70
69
|
body: stringify({ method, jsonrpc: '2.0', params, id: 0 }),
|
|
71
70
|
headers: this.headers,
|
|
@@ -125,8 +124,8 @@ export class RpcProvider implements ProviderInterface {
|
|
|
125
124
|
}
|
|
126
125
|
|
|
127
126
|
public async getClassHashAt(
|
|
128
|
-
|
|
129
|
-
|
|
127
|
+
contractAddress: RPC.ContractAddress,
|
|
128
|
+
blockIdentifier: BlockIdentifier = 'pending'
|
|
130
129
|
): Promise<RPC.Felt> {
|
|
131
130
|
const block_id = new Block(blockIdentifier).identifier;
|
|
132
131
|
return this.fetchEndpoint('starknet_getClassHashAt', {
|
|
@@ -154,7 +153,9 @@ export class RpcProvider implements ProviderInterface {
|
|
|
154
153
|
throw new Error('Pathfinder does not implement this rpc 0.1.0 method');
|
|
155
154
|
}
|
|
156
155
|
|
|
157
|
-
public async getStateUpdate(
|
|
156
|
+
public async getStateUpdate(
|
|
157
|
+
blockIdentifier: BlockIdentifier = 'pending'
|
|
158
|
+
): Promise<RPC.StateUpdate> {
|
|
158
159
|
const block_id = new Block(blockIdentifier).identifier;
|
|
159
160
|
return this.fetchEndpoint('starknet_getStateUpdate', { block_id });
|
|
160
161
|
}
|
|
@@ -190,12 +191,20 @@ export class RpcProvider implements ProviderInterface {
|
|
|
190
191
|
return this.fetchEndpoint('starknet_getTransactionByBlockIdAndIndex', { block_id, index });
|
|
191
192
|
}
|
|
192
193
|
|
|
193
|
-
public async getTransactionReceipt(txHash: string): Promise<
|
|
194
|
+
public async getTransactionReceipt(txHash: string): Promise<RPC.TransactionReceipt> {
|
|
194
195
|
return this.fetchEndpoint('starknet_getTransactionReceipt', { transaction_hash: txHash });
|
|
195
196
|
}
|
|
196
197
|
|
|
197
|
-
public async
|
|
198
|
-
return this.
|
|
198
|
+
public async getClassByHash(classHash: RPC.Felt): Promise<RPC.ContractClass> {
|
|
199
|
+
return this.getClass(classHash);
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
public async getClass(
|
|
203
|
+
classHash: RPC.Felt,
|
|
204
|
+
blockIdentifier: BlockIdentifier = 'pending'
|
|
205
|
+
): Promise<RPC.ContractClass> {
|
|
206
|
+
const block_id = new Block(blockIdentifier).identifier;
|
|
207
|
+
return this.fetchEndpoint('starknet_getClass', { class_hash: classHash, block_id });
|
|
199
208
|
}
|
|
200
209
|
|
|
201
210
|
public async getClassAt(
|
|
@@ -213,7 +222,7 @@ export class RpcProvider implements ProviderInterface {
|
|
|
213
222
|
_contractAddress: string,
|
|
214
223
|
_blockIdentifier?: BlockIdentifier
|
|
215
224
|
): Promise<GetCodeResponse> {
|
|
216
|
-
throw new Error('RPC
|
|
225
|
+
throw new Error('RPC does not implement getCode function');
|
|
217
226
|
}
|
|
218
227
|
|
|
219
228
|
public async getEstimateFee(
|
|
@@ -297,46 +306,58 @@ export class RpcProvider implements ProviderInterface {
|
|
|
297
306
|
details: InvocationsDetailsWithNonce
|
|
298
307
|
): Promise<DeclareContractResponse> {
|
|
299
308
|
return this.fetchEndpoint('starknet_addDeclareTransaction', {
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
309
|
+
declare_transaction: {
|
|
310
|
+
contract_class: {
|
|
311
|
+
program: contractDefinition.program,
|
|
312
|
+
entry_points_by_type: contractDefinition.entry_points_by_type,
|
|
313
|
+
abi: contractDefinition.abi, // rpc 2.0
|
|
314
|
+
},
|
|
315
|
+
type: 'DECLARE',
|
|
316
|
+
version: toHex(toBN(details.version || 0)),
|
|
317
|
+
max_fee: toHex(toBN(details.maxFee || 0)),
|
|
318
|
+
signature: bigNumberishArrayToHexadecimalStringArray(signature || []),
|
|
319
|
+
sender_address: senderAddress,
|
|
320
|
+
nonce: toHex(toBN(details.nonce)),
|
|
304
321
|
},
|
|
305
|
-
version: toHex(toBN(details.version || 0)),
|
|
306
|
-
max_fee: toHex(toBN(details.maxFee || 0)),
|
|
307
|
-
signature: bigNumberishArrayToHexadecimalStringArray(signature || []),
|
|
308
|
-
sender_address: senderAddress,
|
|
309
|
-
nonce: toHex(toBN(details.nonce)),
|
|
310
322
|
});
|
|
311
323
|
}
|
|
312
324
|
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
325
|
+
/**
|
|
326
|
+
* @deprecated This method wont be supported soon, use Account.deploy instead
|
|
327
|
+
*/
|
|
328
|
+
public async deployContract(
|
|
329
|
+
{ contract, constructorCalldata, addressSalt }: DeployContractPayload,
|
|
330
|
+
details?: InvocationsDetails
|
|
331
|
+
): Promise<DeployContractResponse> {
|
|
318
332
|
const contractDefinition = parseContract(contract);
|
|
319
|
-
|
|
320
333
|
return this.fetchEndpoint('starknet_addDeployTransaction', {
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
334
|
+
deploy_transaction: {
|
|
335
|
+
contract_address_salt: addressSalt ?? randomAddress(),
|
|
336
|
+
constructor_calldata: bigNumberishArrayToHexadecimalStringArray(constructorCalldata ?? []),
|
|
337
|
+
contract_class: {
|
|
338
|
+
program: contractDefinition.program,
|
|
339
|
+
entry_points_by_type: contractDefinition.entry_points_by_type,
|
|
340
|
+
abi: contractDefinition.abi,
|
|
341
|
+
},
|
|
342
|
+
type: 'DEPLOY',
|
|
343
|
+
version: toHex(toBN(details?.version || 0)),
|
|
327
344
|
},
|
|
328
345
|
});
|
|
329
346
|
}
|
|
330
347
|
|
|
331
|
-
public async deployAccountContract(
|
|
332
|
-
classHash,
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
}: DeployAccountContractPayload): Promise<DeployContractResponse> {
|
|
348
|
+
public async deployAccountContract(
|
|
349
|
+
{ classHash, constructorCalldata, addressSalt, signature }: DeployAccountContractTransaction,
|
|
350
|
+
details: InvocationsDetailsWithNonce
|
|
351
|
+
): Promise<DeployContractResponse> {
|
|
336
352
|
return this.fetchEndpoint('starknet_addDeployAccountTransaction', {
|
|
337
353
|
constructor_calldata: bigNumberishArrayToHexadecimalStringArray(constructorCalldata || []),
|
|
338
354
|
class_hash: toHex(toBN(classHash)),
|
|
339
355
|
contract_address_salt: toHex(toBN(addressSalt || 0)),
|
|
356
|
+
type: 'DEPLOY',
|
|
357
|
+
max_fee: toHex(toBN(details.maxFee || 0)),
|
|
358
|
+
version: toHex(toBN(details.version || 0)),
|
|
359
|
+
signature: bigNumberishArrayToHexadecimalStringArray(signature || []),
|
|
360
|
+
nonce: toHex(toBN(details.nonce)),
|
|
340
361
|
});
|
|
341
362
|
}
|
|
342
363
|
|
|
@@ -345,13 +366,15 @@ export class RpcProvider implements ProviderInterface {
|
|
|
345
366
|
details: InvocationsDetailsWithNonce
|
|
346
367
|
): Promise<InvokeFunctionResponse> {
|
|
347
368
|
return this.fetchEndpoint('starknet_addInvokeTransaction', {
|
|
348
|
-
|
|
349
|
-
|
|
369
|
+
invoke_transaction: {
|
|
370
|
+
sender_address: functionInvocation.contractAddress,
|
|
350
371
|
calldata: parseCalldata(functionInvocation.calldata),
|
|
372
|
+
type: 'INVOKE',
|
|
373
|
+
max_fee: toHex(toBN(details.maxFee || 0)),
|
|
374
|
+
version: toHex(toBN(details.version || 0)),
|
|
375
|
+
signature: bigNumberishArrayToHexadecimalStringArray(functionInvocation.signature || []),
|
|
376
|
+
nonce: toHex(toBN(details.nonce)),
|
|
351
377
|
},
|
|
352
|
-
signature: bigNumberishArrayToHexadecimalStringArray(functionInvocation.signature || []),
|
|
353
|
-
max_fee: toHex(toBN(details.maxFee || 0)),
|
|
354
|
-
version: toHex(toBN(details.version || 0)),
|
|
355
378
|
});
|
|
356
379
|
}
|
|
357
380
|
|
|
@@ -395,6 +418,11 @@ export class RpcProvider implements ProviderInterface {
|
|
|
395
418
|
// eslint-disable-next-line no-await-in-loop
|
|
396
419
|
const res = await this.getTransactionReceipt(txHash);
|
|
397
420
|
|
|
421
|
+
if (!('status' in res)) {
|
|
422
|
+
const error = new Error('pending transaction');
|
|
423
|
+
throw error;
|
|
424
|
+
}
|
|
425
|
+
|
|
398
426
|
if (res.status && successStates.includes(res.status)) {
|
|
399
427
|
onchain = true;
|
|
400
428
|
} else if (res.status && errorStates.includes(res.status)) {
|
|
@@ -427,7 +455,7 @@ export class RpcProvider implements ProviderInterface {
|
|
|
427
455
|
* @returns Number of transactions
|
|
428
456
|
*/
|
|
429
457
|
public async getTransactionCount(
|
|
430
|
-
blockIdentifier: BlockIdentifier
|
|
458
|
+
blockIdentifier: BlockIdentifier = 'pending'
|
|
431
459
|
): Promise<RPC.GetTransactionCountResponse> {
|
|
432
460
|
const block_id = new Block(blockIdentifier).identifier;
|
|
433
461
|
return this.fetchEndpoint('starknet_getBlockTransactionCount', { block_id });
|
|
@@ -300,6 +300,17 @@ export class SequencerProvider implements ProviderInterface {
|
|
|
300
300
|
);
|
|
301
301
|
}
|
|
302
302
|
|
|
303
|
+
public async getClassHashAt(
|
|
304
|
+
contractAddress: string,
|
|
305
|
+
blockIdentifier: BlockIdentifier = 'pending'
|
|
306
|
+
): Promise<string> {
|
|
307
|
+
return this.fetchEndpoint('get_class_hash_at', { blockIdentifier, contractAddress });
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
public async getClassByHash(classHash: string): Promise<ContractClass> {
|
|
311
|
+
return this.fetchEndpoint('get_class_by_hash', { classHash }).then(parseContract);
|
|
312
|
+
}
|
|
313
|
+
|
|
303
314
|
public async invokeFunction(
|
|
304
315
|
functionInvocation: Invocation,
|
|
305
316
|
details: InvocationsDetailsWithNonce
|