starknet 2.3.1 → 2.4.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,9 @@
1
+ # [2.4.0](https://github.com/seanjameshan/starknet.js/compare/v2.3.1...v2.4.0) (2021-12-09)
2
+
3
+ ### Features
4
+
5
+ - allow custom nonce ([17666de](https://github.com/seanjameshan/starknet.js/commit/17666de94db6875bbf8e88555773b8862a4a32cf))
6
+
1
7
  ## [2.3.1](https://github.com/seanjameshan/starknet.js/compare/v2.3.0...v2.3.1) (2021-12-01)
2
8
 
3
9
  ### Bug Fixes
@@ -99,4 +99,21 @@ describe('deploy and test Wallet', () => {
99
99
 
100
100
  expect(number.toBN(res as string).toString()).toStrictEqual(number.toBN(990).toString());
101
101
  });
102
+ test('execute with custom nonce', async () => {
103
+ const { result } = await signer.callContract({
104
+ contract_address: signer.address,
105
+ entry_point_selector: stark.getSelectorFromName('get_nonce'),
106
+ });
107
+ const nonce = parseInt(result[0], 10);
108
+ const { code, transaction_hash } = await signer.addTransaction({
109
+ type: 'INVOKE_FUNCTION',
110
+ contract_address: erc20Address,
111
+ entry_point_selector: stark.getSelectorFromName('transfer'),
112
+ calldata: [erc20Address, '10'],
113
+ nonce,
114
+ });
115
+
116
+ expect(code).toBe('TRANSACTION_RECEIVED');
117
+ await defaultProvider.waitForTx(transaction_hash);
118
+ });
102
119
  });
@@ -25,11 +25,11 @@ export declare class Provider implements ProviderInterface {
25
25
  *
26
26
  * [Reference](https://github.com/starkware-libs/cairo-lang/blob/f464ec4797361b6be8989e36e02ec690e74ef285/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L17-L25)
27
27
  *
28
- * @param invokeTx - transaction to be invoked
28
+ * @param invokeTransaction - transaction to be invoked
29
29
  * @param blockId
30
30
  * @returns the result of the function on the smart contract.
31
31
  */
32
- callContract(invokeTx: CallContractTransaction, blockId?: number): Promise<CallContractResponse>;
32
+ callContract(invokeTransaction: CallContractTransaction, blockId?: number): Promise<CallContractResponse>;
33
33
  /**
34
34
  * Gets the block information from a block ID.
35
35
  *
@@ -83,10 +83,10 @@ export declare class Provider implements ProviderInterface {
83
83
  *
84
84
  * [Reference](https://github.com/starkware-libs/cairo-lang/blob/f464ec4797361b6be8989e36e02ec690e74ef285/src/starkware/starknet/services/api/gateway/gateway_client.py#L13-L17)
85
85
  *
86
- * @param tx - transaction to be invoked
86
+ * @param transaction - transaction to be invoked
87
87
  * @returns a confirmation of invoking a function on the starknet contract
88
88
  */
89
- addTransaction(tx: Transaction): Promise<AddTransactionResponse>;
89
+ addTransaction(transaction: Transaction): Promise<AddTransactionResponse>;
90
90
  /**
91
91
  * Deploys a given compiled contract (json) to starknet
92
92
  *
@@ -109,16 +109,16 @@ var Provider = /** @class */ (function () {
109
109
  *
110
110
  * [Reference](https://github.com/starkware-libs/cairo-lang/blob/f464ec4797361b6be8989e36e02ec690e74ef285/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L17-L25)
111
111
  *
112
- * @param invokeTx - transaction to be invoked
112
+ * @param invokeTransaction - transaction to be invoked
113
113
  * @param blockId
114
114
  * @returns the result of the function on the smart contract.
115
115
  */
116
- Provider.prototype.callContract = function (invokeTx, blockId) {
116
+ Provider.prototype.callContract = function (invokeTransaction, blockId) {
117
117
  return __awaiter(this, void 0, void 0, function () {
118
118
  var data;
119
119
  return __generator(this, function (_a) {
120
120
  switch (_a.label) {
121
- case 0: return [4 /*yield*/, axios_1.default.post((0, url_join_1.default)(this.feederGatewayUrl, 'call_contract', "?blockId=" + (blockId !== null && blockId !== void 0 ? blockId : 'null')), __assign({ signature: [], calldata: [] }, invokeTx))];
121
+ case 0: return [4 /*yield*/, axios_1.default.post((0, url_join_1.default)(this.feederGatewayUrl, 'call_contract', "?blockId=" + (blockId !== null && blockId !== void 0 ? blockId : 'null')), __assign({ signature: [], calldata: [] }, invokeTransaction))];
122
122
  case 1:
123
123
  data = (_a.sent()).data;
124
124
  return [2 /*return*/, data];
@@ -244,18 +244,18 @@ var Provider = /** @class */ (function () {
244
244
  *
245
245
  * [Reference](https://github.com/starkware-libs/cairo-lang/blob/f464ec4797361b6be8989e36e02ec690e74ef285/src/starkware/starknet/services/api/gateway/gateway_client.py#L13-L17)
246
246
  *
247
- * @param tx - transaction to be invoked
247
+ * @param transaction - transaction to be invoked
248
248
  * @returns a confirmation of invoking a function on the starknet contract
249
249
  */
250
- Provider.prototype.addTransaction = function (tx) {
250
+ Provider.prototype.addTransaction = function (transaction) {
251
251
  return __awaiter(this, void 0, void 0, function () {
252
252
  var signature, contract_address_salt, data;
253
253
  return __generator(this, function (_a) {
254
254
  switch (_a.label) {
255
255
  case 0:
256
- signature = tx.type === 'INVOKE_FUNCTION' && (0, stark_1.formatSignature)(tx.signature);
257
- contract_address_salt = tx.type === 'DEPLOY' && (0, number_1.toHex)((0, number_1.toBN)(tx.contract_address_salt));
258
- return [4 /*yield*/, axios_1.default.post((0, url_join_1.default)(this.gatewayUrl, 'add_transaction'), (0, json_1.stringify)(__assign(__assign(__assign({}, tx), (Array.isArray(signature) && { signature: signature })), (contract_address_salt && { contract_address_salt: contract_address_salt }))), { headers: { 'Content-Type': 'application/json' } })];
256
+ signature = transaction.type === 'INVOKE_FUNCTION' && (0, stark_1.formatSignature)(transaction.signature);
257
+ contract_address_salt = transaction.type === 'DEPLOY' && (0, number_1.toHex)((0, number_1.toBN)(transaction.contract_address_salt));
258
+ return [4 /*yield*/, axios_1.default.post((0, url_join_1.default)(this.gatewayUrl, 'add_transaction'), (0, json_1.stringify)(__assign(__assign(__assign({}, transaction), (Array.isArray(signature) && { signature: signature })), (contract_address_salt && { contract_address_salt: contract_address_salt }))), { headers: { 'Content-Type': 'application/json' } })];
259
259
  case 1:
260
260
  data = (_a.sent()).data;
261
261
  return [2 /*return*/, data];
@@ -16,11 +16,11 @@ export declare abstract class ProviderInterface {
16
16
  *
17
17
  * [Reference](https://github.com/starkware-libs/cairo-lang/blob/f464ec4797361b6be8989e36e02ec690e74ef285/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L17-L25)
18
18
  *
19
- * @param invokeTx - transaction to be invoked
19
+ * @param invokeTransaction - transaction to be invoked
20
20
  * @param blockId
21
21
  * @returns the result of the function on the smart contract.
22
22
  */
23
- abstract callContract(invokeTx: CallContractTransaction, blockId?: number): Promise<CallContractResponse>;
23
+ abstract callContract(invokeTransaction: CallContractTransaction, blockId?: number): Promise<CallContractResponse>;
24
24
  /**
25
25
  * Gets the block information from a block ID.
26
26
  *
@@ -74,10 +74,10 @@ export declare abstract class ProviderInterface {
74
74
  *
75
75
  * [Reference](https://github.com/starkware-libs/cairo-lang/blob/f464ec4797361b6be8989e36e02ec690e74ef285/src/starkware/starknet/services/api/gateway/gateway_client.py#L13-L17)
76
76
  *
77
- * @param tx - transaction to be invoked
77
+ * @param transaction - transaction to be invoked
78
78
  * @returns a confirmation of invoking a function on the starknet contract
79
79
  */
80
- abstract addTransaction(tx: Transaction): Promise<AddTransactionResponse>;
80
+ abstract addTransaction(transaction: Transaction): Promise<AddTransactionResponse>;
81
81
  /**
82
82
  * Deploys a given compiled contract (json) to starknet
83
83
  *
@@ -10,8 +10,8 @@ export declare class Signer extends Provider implements SignerInterface {
10
10
  *
11
11
  * [Reference](https://github.com/starkware-libs/cairo-lang/blob/f464ec4797361b6be8989e36e02ec690e74ef285/src/starkware/starknet/services/api/gateway/gateway_client.py#L13-L17)
12
12
  *
13
- * @param tx - transaction to be invoked
13
+ * @param transaction - transaction to be invoked
14
14
  * @returns a confirmation of invoking a function on the starknet contract
15
15
  */
16
- addTransaction(tx: Transaction): Promise<AddTransactionResponse>;
16
+ addTransaction(transaction: Transaction): Promise<AddTransactionResponse>;
17
17
  }
@@ -100,34 +100,39 @@ var Signer = /** @class */ (function (_super) {
100
100
  *
101
101
  * [Reference](https://github.com/starkware-libs/cairo-lang/blob/f464ec4797361b6be8989e36e02ec690e74ef285/src/starkware/starknet/services/api/gateway/gateway_client.py#L13-L17)
102
102
  *
103
- * @param tx - transaction to be invoked
103
+ * @param transaction - transaction to be invoked
104
104
  * @returns a confirmation of invoking a function on the starknet contract
105
105
  */
106
- Signer.prototype.addTransaction = function (tx) {
106
+ Signer.prototype.addTransaction = function (transaction) {
107
107
  return __awaiter(this, void 0, void 0, function () {
108
- var result, nonceBn, calldataDecimal, msgHash, _a, r, s;
108
+ var nonceBn, result, calldataDecimal, msgHash, _a, r, s;
109
109
  return __generator(this, function (_b) {
110
110
  switch (_b.label) {
111
111
  case 0:
112
- if (tx.type === 'DEPLOY')
113
- return [2 /*return*/, _super.prototype.addTransaction.call(this, tx)];
114
- (0, minimalistic_assert_1.default)(!tx.signature, "Adding signatures to a signer tx currently isn't supported");
115
- return [4 /*yield*/, this.callContract({
116
- contract_address: this.address,
117
- entry_point_selector: (0, stark_1.getSelectorFromName)('get_nonce'),
118
- })];
119
- case 1:
112
+ if (transaction.type === 'DEPLOY')
113
+ return [2 /*return*/, _super.prototype.addTransaction.call(this, transaction)];
114
+ (0, minimalistic_assert_1.default)(!transaction.signature, "Adding signatures to a signer transaction currently isn't supported");
115
+ if (!transaction.nonce) return [3 /*break*/, 1];
116
+ nonceBn = (0, number_1.toBN)(transaction.nonce);
117
+ return [3 /*break*/, 3];
118
+ case 1: return [4 /*yield*/, this.callContract({
119
+ contract_address: this.address,
120
+ entry_point_selector: (0, stark_1.getSelectorFromName)('get_nonce'),
121
+ })];
122
+ case 2:
120
123
  result = (_b.sent()).result;
121
124
  nonceBn = (0, number_1.toBN)(result[0]);
122
- calldataDecimal = (tx.calldata || []).map(function (x) { return (0, number_1.toBN)(x).toString(); });
123
- msgHash = (0, encode_1.addHexPrefix)((0, hash_1.hashMessage)(this.address, tx.contract_address, tx.entry_point_selector, calldataDecimal, nonceBn.toString()));
125
+ _b.label = 3;
126
+ case 3:
127
+ calldataDecimal = (transaction.calldata || []).map(function (x) { return (0, number_1.toBN)(x).toString(); });
128
+ msgHash = (0, encode_1.addHexPrefix)((0, hash_1.hashMessage)(this.address, transaction.contract_address, transaction.entry_point_selector, calldataDecimal, nonceBn.toString()));
124
129
  _a = (0, ellipticCurve_1.sign)(this.keyPair, msgHash), r = _a.r, s = _a.s;
125
130
  return [2 /*return*/, _super.prototype.addTransaction.call(this, {
126
131
  type: 'INVOKE_FUNCTION',
127
132
  entry_point_selector: (0, stark_1.getSelectorFromName)('execute'),
128
133
  calldata: __spreadArray(__spreadArray([
129
- tx.contract_address,
130
- tx.entry_point_selector,
134
+ transaction.contract_address,
135
+ transaction.entry_point_selector,
131
136
  calldataDecimal.length.toString()
132
137
  ], __read(calldataDecimal), false), [
133
138
  nonceBn.toString(),
@@ -7,8 +7,8 @@ export declare abstract class SignerInterface extends Provider {
7
7
  *
8
8
  * [Reference](https://github.com/starkware-libs/cairo-lang/blob/f464ec4797361b6be8989e36e02ec690e74ef285/src/starkware/starknet/services/api/gateway/gateway_client.py#L13-L17)
9
9
  *
10
- * @param tx - transaction to be invoked
10
+ * @param transaction - transaction to be invoked
11
11
  * @returns a confirmation of invoking a function on the starknet contract
12
12
  */
13
- abstract addTransaction(tx: Transaction): Promise<AddTransactionResponse>;
13
+ abstract addTransaction(transaction: Transaction): Promise<AddTransactionResponse>;
14
14
  }
package/dist/types.d.ts CHANGED
@@ -7,7 +7,7 @@ export declare type GetContractAddressesResponse = {
7
7
  GpsStatementVerifier: string;
8
8
  };
9
9
  export declare type Status = 'NOT_RECEIVED' | 'RECEIVED' | 'PENDING' | 'REJECTED' | 'ACCEPTED_ONCHAIN';
10
- export declare type TxStatus = 'TRANSACTION_RECEIVED';
10
+ export declare type TransactionStatus = 'TRANSACTION_RECEIVED';
11
11
  export declare type Type = 'DEPLOY' | 'INVOKE_FUNCTION';
12
12
  export declare type EntryPointType = 'EXTERNAL';
13
13
  export declare type CompressedProgram = string;
@@ -44,6 +44,7 @@ export declare type DeployTransaction = {
44
44
  contract_definition: CompressedCompiledContract;
45
45
  contract_address_salt: BigNumberish;
46
46
  constructor_calldata: string[];
47
+ nonce?: BigNumberish;
47
48
  };
48
49
  export declare type InvokeFunctionTransaction = {
49
50
  type: 'INVOKE_FUNCTION';
@@ -52,6 +53,7 @@ export declare type InvokeFunctionTransaction = {
52
53
  entry_point_type?: EntryPointType;
53
54
  entry_point_selector: string;
54
55
  calldata?: string[];
56
+ nonce?: BigNumberish;
55
57
  };
56
58
  export declare type CallContractTransaction = Omit<InvokeFunctionTransaction, 'type'>;
57
59
  export declare type Transaction = DeployTransaction | InvokeFunctionTransaction;
@@ -100,7 +102,7 @@ export declare type GetTransactionResponse = {
100
102
  transaction_hash: string;
101
103
  };
102
104
  export declare type AddTransactionResponse = {
103
- code: TxStatus;
105
+ code: TransactionStatus;
104
106
  transaction_hash: string;
105
107
  address?: string;
106
108
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "starknet",
3
- "version": "2.3.1",
3
+ "version": "2.4.0",
4
4
  "description": "JavaScript library for StarkNet",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -23,6 +23,7 @@
23
23
  "zk",
24
24
  "rollup"
25
25
  ],
26
+ "repository": "github:seanjameshan/starknet.js",
26
27
  "author": "Sean Han",
27
28
  "license": "MIT",
28
29
  "devDependencies": {
@@ -40,11 +40,14 @@ export declare class Provider implements ProviderInterface {
40
40
  *
41
41
  * [Reference](https://github.com/starkware-libs/cairo-lang/blob/f464ec4797361b6be8989e36e02ec690e74ef285/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L17-L25)
42
42
  *
43
- * @param invokeTx - transaction to be invoked
43
+ * @param invokeTransaction - transaction to be invoked
44
44
  * @param blockId
45
45
  * @returns the result of the function on the smart contract.
46
46
  */
47
- callContract(invokeTx: CallContractTransaction, blockId?: number): Promise<CallContractResponse>;
47
+ callContract(
48
+ invokeTransaction: CallContractTransaction,
49
+ blockId?: number
50
+ ): Promise<CallContractResponse>;
48
51
  /**
49
52
  * Gets the block information from a block ID.
50
53
  *
@@ -98,10 +101,10 @@ export declare class Provider implements ProviderInterface {
98
101
  *
99
102
  * [Reference](https://github.com/starkware-libs/cairo-lang/blob/f464ec4797361b6be8989e36e02ec690e74ef285/src/starkware/starknet/services/api/gateway/gateway_client.py#L13-L17)
100
103
  *
101
- * @param tx - transaction to be invoked
104
+ * @param transaction - transaction to be invoked
102
105
  * @returns a confirmation of invoking a function on the starknet contract
103
106
  */
104
- addTransaction(tx: Transaction): Promise<AddTransactionResponse>;
107
+ addTransaction(transaction: Transaction): Promise<AddTransactionResponse>;
105
108
  /**
106
109
  * Deploys a given compiled contract (json) to starknet
107
110
  *
@@ -219,11 +219,11 @@ var Provider = /** @class */ (function () {
219
219
  *
220
220
  * [Reference](https://github.com/starkware-libs/cairo-lang/blob/f464ec4797361b6be8989e36e02ec690e74ef285/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L17-L25)
221
221
  *
222
- * @param invokeTx - transaction to be invoked
222
+ * @param invokeTransaction - transaction to be invoked
223
223
  * @param blockId
224
224
  * @returns the result of the function on the smart contract.
225
225
  */
226
- Provider.prototype.callContract = function (invokeTx, blockId) {
226
+ Provider.prototype.callContract = function (invokeTransaction, blockId) {
227
227
  return __awaiter(this, void 0, void 0, function () {
228
228
  var data;
229
229
  return __generator(this, function (_a) {
@@ -237,7 +237,7 @@ var Provider = /** @class */ (function () {
237
237
  'call_contract',
238
238
  '?blockId=' + (blockId !== null && blockId !== void 0 ? blockId : 'null')
239
239
  ),
240
- __assign({ signature: [], calldata: [] }, invokeTx)
240
+ __assign({ signature: [], calldata: [] }, invokeTransaction)
241
241
  ),
242
242
  ];
243
243
  case 1:
@@ -421,19 +421,21 @@ var Provider = /** @class */ (function () {
421
421
  *
422
422
  * [Reference](https://github.com/starkware-libs/cairo-lang/blob/f464ec4797361b6be8989e36e02ec690e74ef285/src/starkware/starknet/services/api/gateway/gateway_client.py#L13-L17)
423
423
  *
424
- * @param tx - transaction to be invoked
424
+ * @param transaction - transaction to be invoked
425
425
  * @returns a confirmation of invoking a function on the starknet contract
426
426
  */
427
- Provider.prototype.addTransaction = function (tx) {
427
+ Provider.prototype.addTransaction = function (transaction) {
428
428
  return __awaiter(this, void 0, void 0, function () {
429
429
  var signature, contract_address_salt, data;
430
430
  return __generator(this, function (_a) {
431
431
  switch (_a.label) {
432
432
  case 0:
433
- signature = tx.type === 'INVOKE_FUNCTION' && (0, stark_1.formatSignature)(tx.signature);
433
+ signature =
434
+ transaction.type === 'INVOKE_FUNCTION' &&
435
+ (0, stark_1.formatSignature)(transaction.signature);
434
436
  contract_address_salt =
435
- tx.type === 'DEPLOY' &&
436
- (0, number_1.toHex)((0, number_1.toBN)(tx.contract_address_salt));
437
+ transaction.type === 'DEPLOY' &&
438
+ (0, number_1.toHex)((0, number_1.toBN)(transaction.contract_address_salt));
437
439
  return [
438
440
  4 /*yield*/,
439
441
  axios_1.default.post(
@@ -441,7 +443,7 @@ var Provider = /** @class */ (function () {
441
443
  (0, json_1.stringify)(
442
444
  __assign(
443
445
  __assign(
444
- __assign({}, tx),
446
+ __assign({}, transaction),
445
447
  Array.isArray(signature) && { signature: signature }
446
448
  ),
447
449
  contract_address_salt && { contract_address_salt: contract_address_salt }
@@ -27,12 +27,12 @@ export declare abstract class ProviderInterface {
27
27
  *
28
28
  * [Reference](https://github.com/starkware-libs/cairo-lang/blob/f464ec4797361b6be8989e36e02ec690e74ef285/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L17-L25)
29
29
  *
30
- * @param invokeTx - transaction to be invoked
30
+ * @param invokeTransaction - transaction to be invoked
31
31
  * @param blockId
32
32
  * @returns the result of the function on the smart contract.
33
33
  */
34
34
  abstract callContract(
35
- invokeTx: CallContractTransaction,
35
+ invokeTransaction: CallContractTransaction,
36
36
  blockId?: number
37
37
  ): Promise<CallContractResponse>;
38
38
  /**
@@ -88,10 +88,10 @@ export declare abstract class ProviderInterface {
88
88
  *
89
89
  * [Reference](https://github.com/starkware-libs/cairo-lang/blob/f464ec4797361b6be8989e36e02ec690e74ef285/src/starkware/starknet/services/api/gateway/gateway_client.py#L13-L17)
90
90
  *
91
- * @param tx - transaction to be invoked
91
+ * @param transaction - transaction to be invoked
92
92
  * @returns a confirmation of invoking a function on the starknet contract
93
93
  */
94
- abstract addTransaction(tx: Transaction): Promise<AddTransactionResponse>;
94
+ abstract addTransaction(transaction: Transaction): Promise<AddTransactionResponse>;
95
95
  /**
96
96
  * Deploys a given compiled contract (json) to starknet
97
97
  *
@@ -10,8 +10,8 @@ export declare class Signer extends Provider implements SignerInterface {
10
10
  *
11
11
  * [Reference](https://github.com/starkware-libs/cairo-lang/blob/f464ec4797361b6be8989e36e02ec690e74ef285/src/starkware/starknet/services/api/gateway/gateway_client.py#L13-L17)
12
12
  *
13
- * @param tx - transaction to be invoked
13
+ * @param transaction - transaction to be invoked
14
14
  * @returns a confirmation of invoking a function on the starknet contract
15
15
  */
16
- addTransaction(tx: Transaction): Promise<AddTransactionResponse>;
16
+ addTransaction(transaction: Transaction): Promise<AddTransactionResponse>;
17
17
  }
package/signer/default.js CHANGED
@@ -216,19 +216,23 @@ var Signer = /** @class */ (function (_super) {
216
216
  *
217
217
  * [Reference](https://github.com/starkware-libs/cairo-lang/blob/f464ec4797361b6be8989e36e02ec690e74ef285/src/starkware/starknet/services/api/gateway/gateway_client.py#L13-L17)
218
218
  *
219
- * @param tx - transaction to be invoked
219
+ * @param transaction - transaction to be invoked
220
220
  * @returns a confirmation of invoking a function on the starknet contract
221
221
  */
222
- Signer.prototype.addTransaction = function (tx) {
222
+ Signer.prototype.addTransaction = function (transaction) {
223
223
  return __awaiter(this, void 0, void 0, function () {
224
- var result, nonceBn, calldataDecimal, msgHash, _a, r, s;
224
+ var nonceBn, result, calldataDecimal, msgHash, _a, r, s;
225
225
  return __generator(this, function (_b) {
226
226
  switch (_b.label) {
227
227
  case 0:
228
- if (tx.type === 'DEPLOY')
229
- return [2 /*return*/, _super.prototype.addTransaction.call(this, tx)];
228
+ if (transaction.type === 'DEPLOY')
229
+ return [2 /*return*/, _super.prototype.addTransaction.call(this, transaction)];
230
230
  (0,
231
- minimalistic_assert_1.default)(!tx.signature, "Adding signatures to a signer tx currently isn't supported");
231
+ minimalistic_assert_1.default)(!transaction.signature, "Adding signatures to a signer transaction currently isn't supported");
232
+ if (!transaction.nonce) return [3 /*break*/, 1];
233
+ nonceBn = (0, number_1.toBN)(transaction.nonce);
234
+ return [3 /*break*/, 3];
235
+ case 1:
232
236
  return [
233
237
  4 /*yield*/,
234
238
  this.callContract({
@@ -236,17 +240,19 @@ var Signer = /** @class */ (function (_super) {
236
240
  entry_point_selector: (0, stark_1.getSelectorFromName)('get_nonce'),
237
241
  }),
238
242
  ];
239
- case 1:
243
+ case 2:
240
244
  result = _b.sent().result;
241
245
  nonceBn = (0, number_1.toBN)(result[0]);
242
- calldataDecimal = (tx.calldata || []).map(function (x) {
246
+ _b.label = 3;
247
+ case 3:
248
+ calldataDecimal = (transaction.calldata || []).map(function (x) {
243
249
  return (0, number_1.toBN)(x).toString();
244
250
  });
245
251
  msgHash = (0, encode_1.addHexPrefix)(
246
252
  (0, hash_1.hashMessage)(
247
253
  this.address,
248
- tx.contract_address,
249
- tx.entry_point_selector,
254
+ transaction.contract_address,
255
+ transaction.entry_point_selector,
250
256
  calldataDecimal,
251
257
  nonceBn.toString()
252
258
  )
@@ -260,8 +266,8 @@ var Signer = /** @class */ (function (_super) {
260
266
  calldata: __spreadArray(
261
267
  __spreadArray(
262
268
  [
263
- tx.contract_address,
264
- tx.entry_point_selector,
269
+ transaction.contract_address,
270
+ transaction.entry_point_selector,
265
271
  calldataDecimal.length.toString(),
266
272
  ],
267
273
  __read(calldataDecimal),
@@ -7,8 +7,8 @@ export declare abstract class SignerInterface extends Provider {
7
7
  *
8
8
  * [Reference](https://github.com/starkware-libs/cairo-lang/blob/f464ec4797361b6be8989e36e02ec690e74ef285/src/starkware/starknet/services/api/gateway/gateway_client.py#L13-L17)
9
9
  *
10
- * @param tx - transaction to be invoked
10
+ * @param transaction - transaction to be invoked
11
11
  * @returns a confirmation of invoking a function on the starknet contract
12
12
  */
13
- abstract addTransaction(tx: Transaction): Promise<AddTransactionResponse>;
13
+ abstract addTransaction(transaction: Transaction): Promise<AddTransactionResponse>;
14
14
  }
@@ -83,12 +83,12 @@ export class Provider implements ProviderInterface {
83
83
  *
84
84
  * [Reference](https://github.com/starkware-libs/cairo-lang/blob/f464ec4797361b6be8989e36e02ec690e74ef285/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L17-L25)
85
85
  *
86
- * @param invokeTx - transaction to be invoked
86
+ * @param invokeTransaction - transaction to be invoked
87
87
  * @param blockId
88
88
  * @returns the result of the function on the smart contract.
89
89
  */
90
90
  public async callContract(
91
- invokeTx: CallContractTransaction,
91
+ invokeTransaction: CallContractTransaction,
92
92
  blockId?: number
93
93
  ): Promise<CallContractResponse> {
94
94
  const { data } = await axios.post<CallContractResponse>(
@@ -96,7 +96,7 @@ export class Provider implements ProviderInterface {
96
96
  {
97
97
  signature: [],
98
98
  calldata: [],
99
- ...invokeTx,
99
+ ...invokeTransaction,
100
100
  }
101
101
  );
102
102
  return data;
@@ -204,17 +204,19 @@ export class Provider implements ProviderInterface {
204
204
  *
205
205
  * [Reference](https://github.com/starkware-libs/cairo-lang/blob/f464ec4797361b6be8989e36e02ec690e74ef285/src/starkware/starknet/services/api/gateway/gateway_client.py#L13-L17)
206
206
  *
207
- * @param tx - transaction to be invoked
207
+ * @param transaction - transaction to be invoked
208
208
  * @returns a confirmation of invoking a function on the starknet contract
209
209
  */
210
- public async addTransaction(tx: Transaction): Promise<AddTransactionResponse> {
211
- const signature = tx.type === 'INVOKE_FUNCTION' && formatSignature(tx.signature);
212
- const contract_address_salt = tx.type === 'DEPLOY' && toHex(toBN(tx.contract_address_salt));
210
+ public async addTransaction(transaction: Transaction): Promise<AddTransactionResponse> {
211
+ const signature =
212
+ transaction.type === 'INVOKE_FUNCTION' && formatSignature(transaction.signature);
213
+ const contract_address_salt =
214
+ transaction.type === 'DEPLOY' && toHex(toBN(transaction.contract_address_salt));
213
215
 
214
216
  const { data } = await axios.post<AddTransactionResponse>(
215
217
  urljoin(this.gatewayUrl, 'add_transaction'),
216
218
  stringify({
217
- ...tx, // the tx can contain BigInts, so we use our own `stringify`
219
+ ...transaction, // the tx can contain BigInts, so we use our own `stringify`
218
220
  ...(Array.isArray(signature) && { signature }), // not needed on deploy tx
219
221
  ...(contract_address_salt && { contract_address_salt }), // not needed on invoke tx
220
222
  }),
@@ -32,12 +32,12 @@ export abstract class ProviderInterface {
32
32
  *
33
33
  * [Reference](https://github.com/starkware-libs/cairo-lang/blob/f464ec4797361b6be8989e36e02ec690e74ef285/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L17-L25)
34
34
  *
35
- * @param invokeTx - transaction to be invoked
35
+ * @param invokeTransaction - transaction to be invoked
36
36
  * @param blockId
37
37
  * @returns the result of the function on the smart contract.
38
38
  */
39
39
  public abstract callContract(
40
- invokeTx: CallContractTransaction,
40
+ invokeTransaction: CallContractTransaction,
41
41
  blockId?: number
42
42
  ): Promise<CallContractResponse>;
43
43
 
@@ -104,10 +104,10 @@ export abstract class ProviderInterface {
104
104
  *
105
105
  * [Reference](https://github.com/starkware-libs/cairo-lang/blob/f464ec4797361b6be8989e36e02ec690e74ef285/src/starkware/starknet/services/api/gateway/gateway_client.py#L13-L17)
106
106
  *
107
- * @param tx - transaction to be invoked
107
+ * @param transaction - transaction to be invoked
108
108
  * @returns a confirmation of invoking a function on the starknet contract
109
109
  */
110
- public abstract addTransaction(tx: Transaction): Promise<AddTransactionResponse>;
110
+ public abstract addTransaction(transaction: Transaction): Promise<AddTransactionResponse>;
111
111
 
112
112
  /**
113
113
  * Deploys a given compiled contract (json) to starknet
@@ -25,26 +25,35 @@ export class Signer extends Provider implements SignerInterface {
25
25
  *
26
26
  * [Reference](https://github.com/starkware-libs/cairo-lang/blob/f464ec4797361b6be8989e36e02ec690e74ef285/src/starkware/starknet/services/api/gateway/gateway_client.py#L13-L17)
27
27
  *
28
- * @param tx - transaction to be invoked
28
+ * @param transaction - transaction to be invoked
29
29
  * @returns a confirmation of invoking a function on the starknet contract
30
30
  */
31
- public override async addTransaction(tx: Transaction): Promise<AddTransactionResponse> {
32
- if (tx.type === 'DEPLOY') return super.addTransaction(tx);
31
+ public override async addTransaction(transaction: Transaction): Promise<AddTransactionResponse> {
32
+ if (transaction.type === 'DEPLOY') return super.addTransaction(transaction);
33
33
 
34
- assert(!tx.signature, "Adding signatures to a signer tx currently isn't supported");
34
+ assert(
35
+ !transaction.signature,
36
+ "Adding signatures to a signer transaction currently isn't supported"
37
+ );
35
38
 
36
- const { result } = await this.callContract({
37
- contract_address: this.address,
38
- entry_point_selector: getSelectorFromName('get_nonce'),
39
- });
40
- const nonceBn = toBN(result[0]);
41
- const calldataDecimal = (tx.calldata || []).map((x) => toBN(x).toString());
39
+ let nonceBn;
40
+ if (transaction.nonce) {
41
+ nonceBn = toBN(transaction.nonce);
42
+ } else {
43
+ const { result } = await this.callContract({
44
+ contract_address: this.address,
45
+ entry_point_selector: getSelectorFromName('get_nonce'),
46
+ });
47
+ nonceBn = toBN(result[0]);
48
+ }
49
+
50
+ const calldataDecimal = (transaction.calldata || []).map((x) => toBN(x).toString());
42
51
 
43
52
  const msgHash = addHexPrefix(
44
53
  hashMessage(
45
54
  this.address,
46
- tx.contract_address,
47
- tx.entry_point_selector,
55
+ transaction.contract_address,
56
+ transaction.entry_point_selector,
48
57
  calldataDecimal,
49
58
  nonceBn.toString()
50
59
  )
@@ -56,8 +65,8 @@ export class Signer extends Provider implements SignerInterface {
56
65
  type: 'INVOKE_FUNCTION',
57
66
  entry_point_selector: getSelectorFromName('execute'),
58
67
  calldata: [
59
- tx.contract_address,
60
- tx.entry_point_selector,
68
+ transaction.contract_address,
69
+ transaction.entry_point_selector,
61
70
  calldataDecimal.length.toString(),
62
71
  ...calldataDecimal,
63
72
  nonceBn.toString(),
@@ -8,8 +8,10 @@ export abstract class SignerInterface extends Provider {
8
8
  *
9
9
  * [Reference](https://github.com/starkware-libs/cairo-lang/blob/f464ec4797361b6be8989e36e02ec690e74ef285/src/starkware/starknet/services/api/gateway/gateway_client.py#L13-L17)
10
10
  *
11
- * @param tx - transaction to be invoked
11
+ * @param transaction - transaction to be invoked
12
12
  * @returns a confirmation of invoking a function on the starknet contract
13
13
  */
14
- public abstract override addTransaction(tx: Transaction): Promise<AddTransactionResponse>;
14
+ public abstract override addTransaction(
15
+ transaction: Transaction
16
+ ): Promise<AddTransactionResponse>;
15
17
  }
package/src/types.ts CHANGED
@@ -11,7 +11,7 @@ export type GetContractAddressesResponse = {
11
11
  };
12
12
 
13
13
  export type Status = 'NOT_RECEIVED' | 'RECEIVED' | 'PENDING' | 'REJECTED' | 'ACCEPTED_ONCHAIN';
14
- export type TxStatus = 'TRANSACTION_RECEIVED';
14
+ export type TransactionStatus = 'TRANSACTION_RECEIVED';
15
15
  export type Type = 'DEPLOY' | 'INVOKE_FUNCTION';
16
16
  export type EntryPointType = 'EXTERNAL';
17
17
  export type CompressedProgram = string;
@@ -51,6 +51,7 @@ export type DeployTransaction = {
51
51
  contract_definition: CompressedCompiledContract;
52
52
  contract_address_salt: BigNumberish;
53
53
  constructor_calldata: string[];
54
+ nonce?: BigNumberish;
54
55
  };
55
56
 
56
57
  export type InvokeFunctionTransaction = {
@@ -60,6 +61,7 @@ export type InvokeFunctionTransaction = {
60
61
  entry_point_type?: EntryPointType;
61
62
  entry_point_selector: string;
62
63
  calldata?: string[];
64
+ nonce?: BigNumberish;
63
65
  };
64
66
 
65
67
  export type CallContractTransaction = Omit<InvokeFunctionTransaction, 'type'>;
@@ -116,7 +118,7 @@ export type GetTransactionResponse = {
116
118
  };
117
119
 
118
120
  export type AddTransactionResponse = {
119
- code: TxStatus;
121
+ code: TransactionStatus;
120
122
  transaction_hash: string;
121
123
  address?: string;
122
124
  };
package/types.d.ts CHANGED
@@ -13,7 +13,7 @@ export declare type Status =
13
13
  | 'PENDING'
14
14
  | 'REJECTED'
15
15
  | 'ACCEPTED_ONCHAIN';
16
- export declare type TxStatus = 'TRANSACTION_RECEIVED';
16
+ export declare type TransactionStatus = 'TRANSACTION_RECEIVED';
17
17
  export declare type Type = 'DEPLOY' | 'INVOKE_FUNCTION';
18
18
  export declare type EntryPointType = 'EXTERNAL';
19
19
  export declare type CompressedProgram = string;
@@ -50,6 +50,7 @@ export declare type DeployTransaction = {
50
50
  contract_definition: CompressedCompiledContract;
51
51
  contract_address_salt: BigNumberish;
52
52
  constructor_calldata: string[];
53
+ nonce?: BigNumberish;
53
54
  };
54
55
  export declare type InvokeFunctionTransaction = {
55
56
  type: 'INVOKE_FUNCTION';
@@ -58,6 +59,7 @@ export declare type InvokeFunctionTransaction = {
58
59
  entry_point_type?: EntryPointType;
59
60
  entry_point_selector: string;
60
61
  calldata?: string[];
62
+ nonce?: BigNumberish;
61
63
  };
62
64
  export declare type CallContractTransaction = Omit<InvokeFunctionTransaction, 'type'>;
63
65
  export declare type Transaction = DeployTransaction | InvokeFunctionTransaction;
@@ -106,7 +108,7 @@ export declare type GetTransactionResponse = {
106
108
  transaction_hash: string;
107
109
  };
108
110
  export declare type AddTransactionResponse = {
109
- code: TxStatus;
111
+ code: TransactionStatus;
110
112
  transaction_hash: string;
111
113
  address?: string;
112
114
  };