starknet 3.13.1 → 3.14.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 CHANGED
@@ -1,3 +1,13 @@
1
+ # [3.14.0](https://github.com/0xs34n/starknet.js/compare/v3.13.1...v3.14.0) (2022-06-15)
2
+
3
+ ### Bug Fixes
4
+
5
+ - remove redundant \_abi from declareContract() ([53d6578](https://github.com/0xs34n/starknet.js/commit/53d6578b932ed6046b5e0df83d748673d7efc3d5))
6
+
7
+ ### Features
8
+
9
+ - support contract declaration API introduced at SN 0.9.0 ([ca6203f](https://github.com/0xs34n/starknet.js/commit/ca6203f93471d7fb421d580e07d6de7c183e40f3))
10
+
1
11
  ## [3.13.1](https://github.com/0xs34n/starknet.js/compare/v3.13.0...v3.13.1) (2022-06-14)
2
12
 
3
13
  ### Bug Fixes
@@ -1,6 +1,6 @@
1
1
  import { defaultProvider, stark } from '../src';
2
2
  import { toBN } from '../src/utils/number';
3
- import { compiledArgentAccount } from './fixtures';
3
+ import { compiledArgentAccount, compiledErc20 } from './fixtures';
4
4
 
5
5
  const { compileCalldata } = stark;
6
6
 
@@ -123,6 +123,16 @@ describe('defaultProvider', () => {
123
123
  });
124
124
 
125
125
  describe('addTransaction()', () => {
126
+ test('declareContract()', async () => {
127
+ const response = await defaultProvider.declareContract({
128
+ contract: compiledErc20,
129
+ });
130
+
131
+ expect(response.code).toBe('TRANSACTION_RECEIVED');
132
+ expect(response.transaction_hash).toBeDefined();
133
+ expect(response.class_hash).toBeDefined();
134
+ });
135
+
126
136
  test('deployContract()', async () => {
127
137
  const response = await defaultProvider.deployContract({
128
138
  contract: compiledArgentAccount,
@@ -424,6 +424,7 @@ var Account = /** @class */ (function (_super) {
424
424
  switch (_a.label) {
425
425
  case 0:
426
426
  if (transaction.type === 'DEPLOY') throw new Error('No DEPLOYS');
427
+ if (transaction.type === 'DECLARE') throw new Error('No DECLARES');
427
428
  (0,
428
429
  minimalistic_assert_1.default)(!transaction.signature, "Adding signatures to a signer transaction currently isn't supported");
429
430
  if (!transaction.nonce) return [3 /*break*/, 1];
package/constants.d.ts CHANGED
@@ -10,6 +10,7 @@ export declare enum StarknetChainId {
10
10
  TESTNET = '0x534e5f474f45524c49',
11
11
  }
12
12
  export declare enum TransactionHashPrefix {
13
+ DECLARE = '0x6465636c617265',
13
14
  DEPLOY = '0x6465706c6f79',
14
15
  INVOKE = '0x696e766f6b65',
15
16
  L1_HANDLER = '0x6c315f68616e646c6572',
package/constants.js CHANGED
@@ -37,6 +37,7 @@ var StarknetChainId;
37
37
  })((StarknetChainId = exports.StarknetChainId || (exports.StarknetChainId = {})));
38
38
  var TransactionHashPrefix;
39
39
  (function (TransactionHashPrefix) {
40
+ TransactionHashPrefix['DECLARE'] = '0x6465636c617265';
40
41
  TransactionHashPrefix['DEPLOY'] = '0x6465706c6f79';
41
42
  TransactionHashPrefix['INVOKE'] = '0x696e766f6b65';
42
43
  TransactionHashPrefix['L1_HANDLER'] = '0x6c315f68616e646c6572';
@@ -267,6 +267,8 @@ var Account = /** @class */ (function (_super) {
267
267
  case 0:
268
268
  if (transaction.type === 'DEPLOY')
269
269
  throw new Error('No DEPLOYS');
270
+ if (transaction.type === 'DECLARE')
271
+ throw new Error('No DECLARES');
270
272
  (0, minimalistic_assert_1.default)(!transaction.signature, "Adding signatures to a signer transaction currently isn't supported");
271
273
  if (!transaction.nonce) return [3 /*break*/, 1];
272
274
  nonceBn = (0, number_1.toBN)(transaction.nonce);
@@ -10,6 +10,7 @@ export declare enum StarknetChainId {
10
10
  TESTNET = "0x534e5f474f45524c49"
11
11
  }
12
12
  export declare enum TransactionHashPrefix {
13
+ DECLARE = "0x6465636c617265",
13
14
  DEPLOY = "0x6465706c6f79",
14
15
  INVOKE = "0x696e766f6b65",
15
16
  L1_HANDLER = "0x6c315f68616e646c6572"
package/dist/constants.js CHANGED
@@ -16,6 +16,7 @@ var StarknetChainId;
16
16
  })(StarknetChainId = exports.StarknetChainId || (exports.StarknetChainId = {}));
17
17
  var TransactionHashPrefix;
18
18
  (function (TransactionHashPrefix) {
19
+ TransactionHashPrefix["DECLARE"] = "0x6465636c617265";
19
20
  TransactionHashPrefix["DEPLOY"] = "0x6465706c6f79";
20
21
  TransactionHashPrefix["INVOKE"] = "0x696e766f6b65";
21
22
  TransactionHashPrefix["L1_HANDLER"] = "0x6c315f68616e646c6572";
@@ -1,5 +1,5 @@
1
1
  import { StarknetChainId } from '../constants';
2
- import { Abi, AddTransactionResponse, Call, CallContractResponse, DeployContractPayload, Endpoints, GetBlockResponse, GetCodeResponse, GetContractAddressesResponse, GetTransactionResponse, GetTransactionStatusResponse, GetTransactionTraceResponse, Invocation, TransactionReceiptResponse } from '../types';
2
+ import { Abi, AddTransactionResponse, Call, CallContractResponse, DeclareContractPayload, DeployContractPayload, Endpoints, GetBlockResponse, GetCodeResponse, GetContractAddressesResponse, GetTransactionResponse, GetTransactionStatusResponse, GetTransactionTraceResponse, Invocation, TransactionReceiptResponse } from '../types';
3
3
  import { BigNumberish } from '../utils/number';
4
4
  import { ProviderInterface } from './interface';
5
5
  import { BlockIdentifier } from './utils';
@@ -110,6 +110,13 @@ export declare class Provider implements ProviderInterface {
110
110
  * @returns the transaction trace
111
111
  */
112
112
  getTransactionTrace(txHash: BigNumberish): Promise<GetTransactionTraceResponse>;
113
+ /**
114
+ * Declare a given compiled contract (json) on starknet
115
+ *
116
+ * @param contract - a json object containing the compiled contract
117
+ * @returns a confirmation of sending a transaction on the starknet contract
118
+ */
119
+ declareContract(payload: DeclareContractPayload): Promise<AddTransactionResponse>;
113
120
  /**
114
121
  * Deploys a given compiled contract (json) to starknet
115
122
  *
@@ -370,6 +370,25 @@ var Provider = /** @class */ (function () {
370
370
  });
371
371
  });
372
372
  };
373
+ /**
374
+ * Declare a given compiled contract (json) on starknet
375
+ *
376
+ * @param contract - a json object containing the compiled contract
377
+ * @returns a confirmation of sending a transaction on the starknet contract
378
+ */
379
+ Provider.prototype.declareContract = function (payload) {
380
+ var parsedContract = typeof payload.contract === 'string'
381
+ ? (0, json_1.parse)(payload.contract)
382
+ : payload.contract;
383
+ var contractDefinition = __assign(__assign({}, parsedContract), { program: (0, stark_1.compressProgram)(parsedContract.program) });
384
+ return this.fetchEndpoint('add_transaction', undefined, {
385
+ type: 'DECLARE',
386
+ contract_class: contractDefinition,
387
+ nonce: (0, number_1.toHex)(constants_1.ZERO),
388
+ signature: [],
389
+ sender_address: (0, number_1.toHex)(constants_1.ONE),
390
+ });
391
+ };
373
392
  /**
374
393
  * Deploys a given compiled contract (json) to starknet
375
394
  *
@@ -84,6 +84,13 @@ export declare type GetContractAddressesResponse = {
84
84
  Starknet: string;
85
85
  GpsStatementVerifier: string;
86
86
  };
87
+ export declare type DeclareTransaction = {
88
+ type: 'DECLARE';
89
+ contract_class: CompressedCompiledContract;
90
+ nonce: BigNumberish;
91
+ sender_address: BigNumberish;
92
+ signature: Signature;
93
+ };
87
94
  export declare type DeployTransaction = {
88
95
  type: 'DEPLOY';
89
96
  contract_definition: CompressedCompiledContract;
@@ -127,7 +134,7 @@ export declare type ExecutionResources = {
127
134
  n_memory_holes: number;
128
135
  };
129
136
  export declare type CallContractTransaction = Omit<InvokeFunctionTransaction, 'type' | 'entry_point_type' | 'nonce'>;
130
- export declare type Transaction = DeployTransaction | InvokeFunctionTransaction;
137
+ export declare type Transaction = DeclareTransaction | DeployTransaction | InvokeFunctionTransaction;
131
138
  export declare type CallContractResponse = {
132
139
  result: string[];
133
140
  };
@@ -196,6 +203,7 @@ export declare type AddTransactionResponse = {
196
203
  code: TransactionStatus;
197
204
  transaction_hash: string;
198
205
  address?: string;
206
+ class_hash?: string;
199
207
  };
200
208
  export declare type TransactionReceiptResponse = {
201
209
  status: Status;
@@ -8,6 +8,9 @@ export declare type DeployContractPayload = {
8
8
  constructorCalldata?: RawCalldata;
9
9
  addressSalt?: BigNumberish;
10
10
  };
11
+ export declare type DeclareContractPayload = {
12
+ contract: CompiledContract | string;
13
+ };
11
14
  export declare type Invocation = {
12
15
  contractAddress: string;
13
16
  entrypoint: string;
@@ -22,7 +25,7 @@ export declare type InvocationsDetails = {
22
25
  };
23
26
  export declare type Status = 'NOT_RECEIVED' | 'RECEIVED' | 'PENDING' | 'ACCEPTED_ON_L2' | 'ACCEPTED_ON_L1' | 'REJECTED';
24
27
  export declare type TransactionStatus = 'TRANSACTION_RECEIVED';
25
- export declare type Type = 'DEPLOY' | 'INVOKE_FUNCTION';
28
+ export declare type Type = 'DECLARE' | 'DEPLOY' | 'INVOKE_FUNCTION';
26
29
  export declare type EntryPointType = 'EXTERNAL';
27
30
  export declare type CompressedProgram = string;
28
31
  export declare type AbiEntry = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "starknet",
3
- "version": "3.13.1",
3
+ "version": "3.14.0",
4
4
  "description": "JavaScript library for StarkNet",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -4,6 +4,7 @@ import {
4
4
  AddTransactionResponse,
5
5
  Call,
6
6
  CallContractResponse,
7
+ DeclareContractPayload,
7
8
  DeployContractPayload,
8
9
  Endpoints,
9
10
  GetBlockResponse,
@@ -147,6 +148,13 @@ export declare class Provider implements ProviderInterface {
147
148
  * @returns the transaction trace
148
149
  */
149
150
  getTransactionTrace(txHash: BigNumberish): Promise<GetTransactionTraceResponse>;
151
+ /**
152
+ * Declare a given compiled contract (json) on starknet
153
+ *
154
+ * @param contract - a json object containing the compiled contract
155
+ * @returns a confirmation of sending a transaction on the starknet contract
156
+ */
157
+ declareContract(payload: DeclareContractPayload): Promise<AddTransactionResponse>;
150
158
  /**
151
159
  * Deploys a given compiled contract (json) to starknet
152
160
  *
@@ -536,6 +536,26 @@ var Provider = /** @class */ (function () {
536
536
  });
537
537
  });
538
538
  };
539
+ /**
540
+ * Declare a given compiled contract (json) on starknet
541
+ *
542
+ * @param contract - a json object containing the compiled contract
543
+ * @returns a confirmation of sending a transaction on the starknet contract
544
+ */
545
+ Provider.prototype.declareContract = function (payload) {
546
+ var parsedContract =
547
+ typeof payload.contract === 'string' ? (0, json_1.parse)(payload.contract) : payload.contract;
548
+ var contractDefinition = __assign(__assign({}, parsedContract), {
549
+ program: (0, stark_1.compressProgram)(parsedContract.program),
550
+ });
551
+ return this.fetchEndpoint('add_transaction', undefined, {
552
+ type: 'DECLARE',
553
+ contract_class: contractDefinition,
554
+ nonce: (0, number_1.toHex)(constants_1.ZERO),
555
+ signature: [],
556
+ sender_address: (0, number_1.toHex)(constants_1.ONE),
557
+ });
558
+ };
539
559
  /**
540
560
  * Deploys a given compiled contract (json) to starknet
541
561
  *
@@ -143,6 +143,7 @@ export class Account extends Provider implements AccountInterface {
143
143
  */
144
144
  public async LEGACY_addTransaction(transaction: Transaction): Promise<AddTransactionResponse> {
145
145
  if (transaction.type === 'DEPLOY') throw new Error('No DEPLOYS');
146
+ if (transaction.type === 'DECLARE') throw new Error('No DECLARES');
146
147
 
147
148
  assert(
148
149
  !transaction.signature,
package/src/constants.ts CHANGED
@@ -13,6 +13,7 @@ export enum StarknetChainId {
13
13
  TESTNET = '0x534e5f474f45524c49', // encodeShortString('SN_GOERLI'),
14
14
  }
15
15
  export enum TransactionHashPrefix {
16
+ DECLARE = '0x6465636c617265', // encodeShortString('declare'),
16
17
  DEPLOY = '0x6465706c6f79', // encodeShortString('deploy'),
17
18
  INVOKE = '0x696e766f6b65', // encodeShortString('invoke'),
18
19
  L1_HANDLER = '0x6c315f68616e646c6572', // encodeShortString('l1_handler'),
@@ -1,13 +1,14 @@
1
1
  import fetch from 'cross-fetch';
2
2
  import urljoin from 'url-join';
3
3
 
4
- import { StarknetChainId } from '../constants';
4
+ import { ONE, StarknetChainId, ZERO } from '../constants';
5
5
  import {
6
6
  Abi,
7
7
  AddTransactionResponse,
8
8
  Call,
9
9
  CallContractResponse,
10
10
  CompiledContract,
11
+ DeclareContractPayload,
11
12
  DeployContractPayload,
12
13
  Endpoints,
13
14
  GetBlockResponse,
@@ -309,6 +310,31 @@ export class Provider implements ProviderInterface {
309
310
  return this.fetchEndpoint('get_transaction_trace', { transactionHash: txHashHex });
310
311
  }
311
312
 
313
+ /**
314
+ * Declare a given compiled contract (json) on starknet
315
+ *
316
+ * @param contract - a json object containing the compiled contract
317
+ * @returns a confirmation of sending a transaction on the starknet contract
318
+ */
319
+ public declareContract(payload: DeclareContractPayload): Promise<AddTransactionResponse> {
320
+ const parsedContract =
321
+ typeof payload.contract === 'string'
322
+ ? (parse(payload.contract) as CompiledContract)
323
+ : payload.contract;
324
+ const contractDefinition = {
325
+ ...parsedContract,
326
+ program: compressProgram(parsedContract.program),
327
+ };
328
+
329
+ return this.fetchEndpoint('add_transaction', undefined, {
330
+ type: 'DECLARE',
331
+ contract_class: contractDefinition,
332
+ nonce: toHex(ZERO),
333
+ signature: [],
334
+ sender_address: toHex(ONE),
335
+ });
336
+ }
337
+
312
338
  /**
313
339
  * Deploys a given compiled contract (json) to starknet
314
340
  *
package/src/types/api.ts CHANGED
@@ -97,6 +97,14 @@ export type GetContractAddressesResponse = {
97
97
  GpsStatementVerifier: string;
98
98
  };
99
99
 
100
+ export type DeclareTransaction = {
101
+ type: 'DECLARE';
102
+ contract_class: CompressedCompiledContract;
103
+ nonce: BigNumberish;
104
+ sender_address: BigNumberish;
105
+ signature: Signature;
106
+ };
107
+
100
108
  export type DeployTransaction = {
101
109
  type: 'DEPLOY';
102
110
  contract_definition: CompressedCompiledContract;
@@ -148,7 +156,7 @@ export type CallContractTransaction = Omit<
148
156
  'type' | 'entry_point_type' | 'nonce'
149
157
  >;
150
158
 
151
- export type Transaction = DeployTransaction | InvokeFunctionTransaction;
159
+ export type Transaction = DeclareTransaction | DeployTransaction | InvokeFunctionTransaction;
152
160
 
153
161
  export type CallContractResponse = {
154
162
  result: string[];
@@ -224,6 +232,7 @@ export type AddTransactionResponse = {
224
232
  code: TransactionStatus;
225
233
  transaction_hash: string;
226
234
  address?: string;
235
+ class_hash?: string;
227
236
  };
228
237
 
229
238
  export type TransactionReceiptResponse = {
package/src/types/lib.ts CHANGED
@@ -12,6 +12,10 @@ export type DeployContractPayload = {
12
12
  addressSalt?: BigNumberish;
13
13
  };
14
14
 
15
+ export type DeclareContractPayload = {
16
+ contract: CompiledContract | string;
17
+ };
18
+
15
19
  export type Invocation = {
16
20
  contractAddress: string;
17
21
  entrypoint: string;
@@ -35,7 +39,7 @@ export type Status =
35
39
  | 'ACCEPTED_ON_L1'
36
40
  | 'REJECTED';
37
41
  export type TransactionStatus = 'TRANSACTION_RECEIVED';
38
- export type Type = 'DEPLOY' | 'INVOKE_FUNCTION';
42
+ export type Type = 'DECLARE' | 'DEPLOY' | 'INVOKE_FUNCTION';
39
43
  export type EntryPointType = 'EXTERNAL';
40
44
  export type CompressedProgram = string;
41
45
 
package/types/api.d.ts CHANGED
@@ -94,6 +94,13 @@ export declare type GetContractAddressesResponse = {
94
94
  Starknet: string;
95
95
  GpsStatementVerifier: string;
96
96
  };
97
+ export declare type DeclareTransaction = {
98
+ type: 'DECLARE';
99
+ contract_class: CompressedCompiledContract;
100
+ nonce: BigNumberish;
101
+ sender_address: BigNumberish;
102
+ signature: Signature;
103
+ };
97
104
  export declare type DeployTransaction = {
98
105
  type: 'DEPLOY';
99
106
  contract_definition: CompressedCompiledContract;
@@ -140,7 +147,10 @@ export declare type CallContractTransaction = Omit<
140
147
  InvokeFunctionTransaction,
141
148
  'type' | 'entry_point_type' | 'nonce'
142
149
  >;
143
- export declare type Transaction = DeployTransaction | InvokeFunctionTransaction;
150
+ export declare type Transaction =
151
+ | DeclareTransaction
152
+ | DeployTransaction
153
+ | InvokeFunctionTransaction;
144
154
  export declare type CallContractResponse = {
145
155
  result: string[];
146
156
  };
@@ -209,6 +219,7 @@ export declare type AddTransactionResponse = {
209
219
  code: TransactionStatus;
210
220
  transaction_hash: string;
211
221
  address?: string;
222
+ class_hash?: string;
212
223
  };
213
224
  export declare type TransactionReceiptResponse = {
214
225
  status: Status;
package/types/lib.d.ts CHANGED
@@ -9,6 +9,9 @@ export declare type DeployContractPayload = {
9
9
  constructorCalldata?: RawCalldata;
10
10
  addressSalt?: BigNumberish;
11
11
  };
12
+ export declare type DeclareContractPayload = {
13
+ contract: CompiledContract | string;
14
+ };
12
15
  export declare type Invocation = {
13
16
  contractAddress: string;
14
17
  entrypoint: string;
@@ -29,7 +32,7 @@ export declare type Status =
29
32
  | 'ACCEPTED_ON_L1'
30
33
  | 'REJECTED';
31
34
  export declare type TransactionStatus = 'TRANSACTION_RECEIVED';
32
- export declare type Type = 'DEPLOY' | 'INVOKE_FUNCTION';
35
+ export declare type Type = 'DECLARE' | 'DEPLOY' | 'INVOKE_FUNCTION';
33
36
  export declare type EntryPointType = 'EXTERNAL';
34
37
  export declare type CompressedProgram = string;
35
38
  export declare type AbiEntry = {
@@ -198,9 +198,26 @@ Gets the transaction trace from a tx hash.
198
198
 
199
199
  <hr/>
200
200
 
201
+ provider.**declareContract**(payload) => _Promise < AddTransactionResponse >_
202
+
203
+ Declares a contract on Starknet
204
+
205
+ ###### _AddTransactionResponse_
206
+
207
+ ```
208
+ {
209
+ code: 'TRANSACTION_RECEIVED';
210
+ transaction_hash: string;
211
+ class_hash: string;
212
+ };
213
+
214
+ <hr/>
215
+
216
+ ```
217
+
201
218
  provider.**deployContract**(payload [ , abi ]) => _Promise < AddTransactionResponse >_
202
219
 
203
- Gets the transaction trace from a tx hash.
220
+ Deploys a contract on Starknet
204
221
 
205
222
  ###### _AddTransactionResponse_
206
223