starknet 4.4.0 → 4.5.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,28 @@
1
+ # [4.5.0](https://github.com/0xs34n/starknet.js/compare/v4.4.2...v4.5.0) (2022-09-09)
2
+
3
+ ### Bug Fixes
4
+
5
+ - prevent undefined rpc chainId in account ([9f69229](https://github.com/0xs34n/starknet.js/commit/9f69229fcb5205bb3fd1fcc7eb7c627faa300561))
6
+ - repair chain fix ([d7758a6](https://github.com/0xs34n/starknet.js/commit/d7758a6d180cd1af89f8aefb37bce077b92c5fd5))
7
+
8
+ ### Features
9
+
10
+ - optional abi field for deploy and declare rpc transactions ([ce62648](https://github.com/0xs34n/starknet.js/commit/ce626481cb6bc3dea77963482820ae6f50c82566))
11
+
12
+ ## [4.4.2](https://github.com/0xs34n/starknet.js/compare/v4.4.1...v4.4.2) (2022-09-07)
13
+
14
+ ### Bug Fixes
15
+
16
+ - dont import fetch from crosshatch ([a3ef41c](https://github.com/0xs34n/starknet.js/commit/a3ef41cac0e818f7429e6dd7654722ede1dc3796))
17
+ - use custom fetch ponyfill ([78f904a](https://github.com/0xs34n/starknet.js/commit/78f904a1d5aeb5efaba7fbdd853802529c80594b))
18
+ - use isomorphic-unfetch ([c63b6a1](https://github.com/0xs34n/starknet.js/commit/c63b6a138616936cf7a70f9098af5df290983c74))
19
+
20
+ ## [4.4.1](https://github.com/0xs34n/starknet.js/compare/v4.4.0...v4.4.1) (2022-09-01)
21
+
22
+ ### Bug Fixes
23
+
24
+ - supply calldata as hexadecimal string array ([44cb4c5](https://github.com/0xs34n/starknet.js/commit/44cb4c5f108a2ea8fcd77147f053e068189d4f33))
25
+
1
26
  # [4.4.0](https://github.com/0xs34n/starknet.js/compare/v4.3.1...v4.4.0) (2022-09-01)
2
27
 
3
28
  ### Bug Fixes
@@ -1,11 +1,23 @@
1
- import { RpcProvider } from '../src';
2
- import { describeIfRpc, getTestProvider } from './fixtures';
1
+ import { Account, RpcProvider, ec } from '../src';
2
+ import {
3
+ compiledOpenZeppelinAccount,
4
+ describeIfRpc,
5
+ getTestAccount,
6
+ getTestProvider,
7
+ } from './fixtures';
3
8
 
4
9
  describeIfRpc('RPCProvider', () => {
5
10
  let rpcProvider: RpcProvider;
11
+ let accountPublicKey: string;
6
12
 
7
13
  beforeAll(async () => {
8
14
  rpcProvider = getTestProvider() as RpcProvider;
15
+ const account = getTestAccount(rpcProvider);
16
+
17
+ expect(account).toBeInstanceOf(Account);
18
+
19
+ const accountKeyPair = ec.genKeyPair();
20
+ accountPublicKey = ec.getStarkKey(accountKeyPair);
9
21
  });
10
22
 
11
23
  describe('RPC methods', () => {
@@ -13,5 +25,20 @@ describeIfRpc('RPCProvider', () => {
13
25
  const chainId = await rpcProvider.getChainId();
14
26
  expect(chainId).toBe('0x534e5f474f45524c49');
15
27
  });
28
+
29
+ test('deployContract', async () => {
30
+ const { contract_address, transaction_hash } = await rpcProvider.deployContract({
31
+ contract: compiledOpenZeppelinAccount,
32
+ constructorCalldata: [accountPublicKey],
33
+ addressSalt: accountPublicKey,
34
+ });
35
+ await rpcProvider.waitForTransaction(transaction_hash);
36
+ expect(contract_address).toBeTruthy();
37
+ expect(transaction_hash).toBeTruthy();
38
+ });
39
+
40
+ test.todo('getEstimateFee');
41
+
42
+ test.todo('invokeFunction');
16
43
  });
17
44
  });
@@ -99,7 +99,7 @@ var Account = /** @class */ (function (_super) {
99
99
  Account.prototype.estimateFee = function (calls, _a) {
100
100
  var _b = _a === void 0 ? {} : _a, providedNonce = _b.nonce, blockIdentifier = _b.blockIdentifier;
101
101
  return __awaiter(this, void 0, void 0, function () {
102
- var transactions, nonce, _c, version, signerDetails, signature, calldata, response, suggestedMaxFee;
102
+ var transactions, nonce, _c, version, chainId, signerDetails, signature, calldata, response, suggestedMaxFee;
103
103
  return __generator(this, function (_d) {
104
104
  switch (_d.label) {
105
105
  case 0:
@@ -114,19 +114,22 @@ var Account = /** @class */ (function (_super) {
114
114
  case 3:
115
115
  nonce = _c;
116
116
  version = (0, number_1.toBN)(hash_1.feeTransactionVersion);
117
+ return [4 /*yield*/, this.getChainId()];
118
+ case 4:
119
+ chainId = _d.sent();
117
120
  signerDetails = {
118
121
  walletAddress: this.address,
119
122
  nonce: (0, number_1.toBN)(nonce),
120
123
  maxFee: constants_1.ZERO,
121
124
  version: version,
122
- chainId: this.chainId,
125
+ chainId: chainId,
123
126
  };
124
127
  return [4 /*yield*/, this.signer.signTransaction(transactions, signerDetails)];
125
- case 4:
128
+ case 5:
126
129
  signature = _d.sent();
127
130
  calldata = (0, transaction_1.fromCallsToExecuteCalldataWithNonce)(transactions, nonce);
128
131
  return [4 /*yield*/, _super.prototype.getEstimateFee.call(this, { contractAddress: this.address, entrypoint: '__execute__', calldata: calldata, signature: signature }, blockIdentifier, { version: version })];
129
- case 5:
132
+ case 6:
130
133
  response = _d.sent();
131
134
  suggestedMaxFee = (0, stark_1.estimatedFeeToMaxFee)(response.overall_fee);
132
135
  return [2 /*return*/, __assign(__assign({}, response), { suggestedMaxFee: suggestedMaxFee })];
@@ -149,7 +152,7 @@ var Account = /** @class */ (function (_super) {
149
152
  if (abis === void 0) { abis = undefined; }
150
153
  if (transactionsDetail === void 0) { transactionsDetail = {}; }
151
154
  return __awaiter(this, void 0, void 0, function () {
152
- var transactions, nonce, _b, _c, maxFee, suggestedMaxFee, version, signerDetails, signature, calldata;
155
+ var transactions, nonce, _b, _c, maxFee, suggestedMaxFee, version, chainId, signerDetails, signature, calldata;
153
156
  return __generator(this, function (_d) {
154
157
  switch (_d.label) {
155
158
  case 0:
@@ -175,15 +178,18 @@ var Account = /** @class */ (function (_super) {
175
178
  _d.label = 6;
176
179
  case 6:
177
180
  version = (0, number_1.toBN)(hash_1.transactionVersion);
181
+ return [4 /*yield*/, this.getChainId()];
182
+ case 7:
183
+ chainId = _d.sent();
178
184
  signerDetails = {
179
185
  walletAddress: this.address,
180
186
  nonce: nonce,
181
187
  maxFee: maxFee,
182
188
  version: version,
183
- chainId: this.chainId,
189
+ chainId: chainId,
184
190
  };
185
191
  return [4 /*yield*/, this.signer.signTransaction(transactions, signerDetails, abis)];
186
- case 7:
192
+ case 8:
187
193
  signature = _d.sent();
188
194
  calldata = (0, transaction_1.fromCallsToExecuteCalldataWithNonce)(transactions, nonce);
189
195
  return [2 /*return*/, this.invokeFunction({ contractAddress: this.address, entrypoint: '__execute__', calldata: calldata, signature: signature }, {
@@ -99,7 +99,7 @@ var Account = /** @class */ (function (_super) {
99
99
  Account.prototype.estimateFee = function (calls, _a) {
100
100
  var _b = _a === void 0 ? {} : _a, providedNonce = _b.nonce, blockIdentifier = _b.blockIdentifier;
101
101
  return __awaiter(this, void 0, void 0, function () {
102
- var transactions, nonce, _c, version, signerDetails, signature, calldata, response, suggestedMaxFee;
102
+ var transactions, nonce, _c, version, chainId, signerDetails, signature, calldata, response, suggestedMaxFee;
103
103
  return __generator(this, function (_d) {
104
104
  switch (_d.label) {
105
105
  case 0:
@@ -114,19 +114,22 @@ var Account = /** @class */ (function (_super) {
114
114
  case 3:
115
115
  nonce = _c;
116
116
  version = (0, number_1.toBN)(hash_1.feeTransactionVersion);
117
+ return [4 /*yield*/, this.getChainId()];
118
+ case 4:
119
+ chainId = _d.sent();
117
120
  signerDetails = {
118
121
  walletAddress: this.address,
119
122
  nonce: (0, number_1.toBN)(nonce),
120
123
  maxFee: constants_1.ZERO,
121
124
  version: version,
122
- chainId: this.chainId,
125
+ chainId: chainId,
123
126
  };
124
127
  return [4 /*yield*/, this.signer.signTransaction(transactions, signerDetails)];
125
- case 4:
128
+ case 5:
126
129
  signature = _d.sent();
127
130
  calldata = (0, transaction_1.fromCallsToExecuteCalldataWithNonce)(transactions, nonce);
128
131
  return [4 /*yield*/, _super.prototype.getEstimateFee.call(this, { contractAddress: this.address, entrypoint: '__execute__', calldata: calldata, signature: signature }, blockIdentifier, { version: version })];
129
- case 5:
132
+ case 6:
130
133
  response = _d.sent();
131
134
  suggestedMaxFee = (0, stark_1.estimatedFeeToMaxFee)(response.overall_fee);
132
135
  return [2 /*return*/, __assign(__assign({}, response), { suggestedMaxFee: suggestedMaxFee })];
@@ -149,7 +152,7 @@ var Account = /** @class */ (function (_super) {
149
152
  if (abis === void 0) { abis = undefined; }
150
153
  if (transactionsDetail === void 0) { transactionsDetail = {}; }
151
154
  return __awaiter(this, void 0, void 0, function () {
152
- var transactions, nonce, _b, _c, maxFee, suggestedMaxFee, version, signerDetails, signature, calldata;
155
+ var transactions, nonce, _b, _c, maxFee, suggestedMaxFee, version, chainId, signerDetails, signature, calldata;
153
156
  return __generator(this, function (_d) {
154
157
  switch (_d.label) {
155
158
  case 0:
@@ -175,15 +178,18 @@ var Account = /** @class */ (function (_super) {
175
178
  _d.label = 6;
176
179
  case 6:
177
180
  version = (0, number_1.toBN)(hash_1.transactionVersion);
181
+ return [4 /*yield*/, this.getChainId()];
182
+ case 7:
183
+ chainId = _d.sent();
178
184
  signerDetails = {
179
185
  walletAddress: this.address,
180
186
  nonce: nonce,
181
187
  maxFee: maxFee,
182
188
  version: version,
183
- chainId: this.chainId,
189
+ chainId: chainId,
184
190
  };
185
191
  return [4 /*yield*/, this.signer.signTransaction(transactions, signerDetails, abis)];
186
- case 7:
192
+ case 8:
187
193
  signature = _d.sent();
188
194
  calldata = (0, transaction_1.fromCallsToExecuteCalldataWithNonce)(transactions, nonce);
189
195
  return [2 /*return*/, this.invokeFunction({ contractAddress: this.address, entrypoint: '__execute__', calldata: calldata, signature: signature }, {
@@ -13,6 +13,7 @@ export declare class Provider implements ProviderInterface {
13
13
  private provider;
14
14
  constructor(providerOrOptions?: ProviderOptions | ProviderInterface);
15
15
  get chainId(): StarknetChainId;
16
+ getChainId(): Promise<StarknetChainId>;
16
17
  getBlock(blockIdentifier?: BlockIdentifier): Promise<GetBlockResponse>;
17
18
  getClassAt(contractAddress: string, blockIdentifier?: BlockIdentifier): Promise<ContractClass>;
18
19
  getEstimateFee(invocation: Invocation, blockIdentifier?: BlockIdentifier, invocationDetails?: InvocationsDetails): Promise<EstimateFeeResponse>;
@@ -61,6 +61,13 @@ var Provider = /** @class */ (function () {
61
61
  enumerable: false,
62
62
  configurable: true
63
63
  });
64
+ Provider.prototype.getChainId = function () {
65
+ return __awaiter(this, void 0, void 0, function () {
66
+ return __generator(this, function (_a) {
67
+ return [2 /*return*/, this.provider.getChainId()];
68
+ });
69
+ });
70
+ };
64
71
  Provider.prototype.getBlock = function (blockIdentifier) {
65
72
  if (blockIdentifier === void 0) { blockIdentifier = 'pending'; }
66
73
  return __awaiter(this, void 0, void 0, function () {
@@ -4,6 +4,12 @@ import type { BigNumberish } from '../utils/number';
4
4
  import { BlockIdentifier } from './utils';
5
5
  export declare abstract class ProviderInterface {
6
6
  abstract chainId: StarknetChainId;
7
+ /**
8
+ * Gets the Starknet chain Id
9
+ *
10
+ * @returns the chain Id
11
+ */
12
+ abstract getChainId(): Promise<StarknetChainId>;
7
13
  /**
8
14
  * Calls a function on the StarkNet contract.
9
15
  *
@@ -217,7 +217,7 @@ var RpcProvider = /** @class */ (function () {
217
217
  contract_address: invocation.contractAddress,
218
218
  entry_point_selector: (0, hash_1.getSelectorFromName)(invocation.entrypoint),
219
219
  calldata: (0, provider_1.parseCalldata)(invocation.calldata),
220
- signature: (0, number_1.bigNumberishArrayToDecimalStringArray)(invocation.signature || []),
220
+ signature: (0, number_1.bigNumberishArrayToHexadecimalStringArray)(invocation.signature || []),
221
221
  version: (0, number_1.toHex)((0, number_1.toBN)((invocationDetails === null || invocationDetails === void 0 ? void 0 : invocationDetails.version) || 0)),
222
222
  },
223
223
  blockIdentifier,
@@ -235,6 +235,7 @@ var RpcProvider = /** @class */ (function () {
235
235
  {
236
236
  program: contractDefinition.program,
237
237
  entry_points_by_type: contractDefinition.entry_points_by_type,
238
+ abi: contractDefinition.abi, // rpc 2.0
238
239
  },
239
240
  (0, number_1.toHex)((0, number_1.toBN)(version || 0)),
240
241
  ]).then(this.responseParser.parseDeclareContractResponse)];
@@ -249,10 +250,11 @@ var RpcProvider = /** @class */ (function () {
249
250
  contractDefinition = (0, provider_1.parseContract)(contract);
250
251
  return [2 /*return*/, this.fetchEndpoint('starknet_addDeployTransaction', [
251
252
  addressSalt !== null && addressSalt !== void 0 ? addressSalt : (0, stark_1.randomAddress)(),
252
- (0, number_1.bigNumberishArrayToDecimalStringArray)(constructorCalldata !== null && constructorCalldata !== void 0 ? constructorCalldata : []),
253
+ (0, number_1.bigNumberishArrayToHexadecimalStringArray)(constructorCalldata !== null && constructorCalldata !== void 0 ? constructorCalldata : []),
253
254
  {
254
255
  program: contractDefinition.program,
255
256
  entry_points_by_type: contractDefinition.entry_points_by_type,
257
+ abi: contractDefinition.abi, // rpc 2.0
256
258
  },
257
259
  ]).then(this.responseParser.parseDeployContractResponse)];
258
260
  });
@@ -267,7 +269,7 @@ var RpcProvider = /** @class */ (function () {
267
269
  entry_point_selector: (0, hash_1.getSelectorFromName)(functionInvocation.entrypoint),
268
270
  calldata: (0, provider_1.parseCalldata)(functionInvocation.calldata),
269
271
  },
270
- (0, number_1.bigNumberishArrayToDecimalStringArray)(functionInvocation.signature || []),
272
+ (0, number_1.bigNumberishArrayToHexadecimalStringArray)(functionInvocation.signature || []),
271
273
  (0, number_1.toHex)((0, number_1.toBN)(details.maxFee || 0)),
272
274
  (0, number_1.toHex)((0, number_1.toBN)(details.version || 0)),
273
275
  ]).then(this.responseParser.parseInvokeFunctionResponse)];
@@ -27,6 +27,7 @@ export declare class SequencerProvider implements ProviderInterface {
27
27
  private getQueryString;
28
28
  private getHeaders;
29
29
  protected fetchEndpoint<T extends keyof Sequencer.Endpoints>(endpoint: T, ...[query, request]: Sequencer.Endpoints[T]['QUERY'] extends never ? Sequencer.Endpoints[T]['REQUEST'] extends never ? [] : [undefined, Sequencer.Endpoints[T]['REQUEST']] : Sequencer.Endpoints[T]['REQUEST'] extends never ? [Sequencer.Endpoints[T]['QUERY']] : [Sequencer.Endpoints[T]['QUERY'], Sequencer.Endpoints[T]['REQUEST']]): Promise<Sequencer.Endpoints[T]['RESPONSE']>;
30
+ getChainId(): Promise<StarknetChainId>;
30
31
  callContract({ contractAddress, entrypoint: entryPointSelector, calldata }: Call, blockIdentifier?: BlockIdentifier): Promise<CallContractResponse>;
31
32
  getBlock(blockIdentifier?: BlockIdentifier): Promise<GetBlockResponse>;
32
33
  getStorageAt(contractAddress: string, key: BigNumberish, blockIdentifier?: BlockIdentifier): Promise<BigNumberish>;
@@ -227,6 +227,13 @@ var SequencerProvider = /** @class */ (function () {
227
227
  });
228
228
  });
229
229
  };
230
+ SequencerProvider.prototype.getChainId = function () {
231
+ return __awaiter(this, void 0, void 0, function () {
232
+ return __generator(this, function (_a) {
233
+ return [2 /*return*/, Promise.resolve(this.chainId)];
234
+ });
235
+ });
236
+ };
230
237
  SequencerProvider.prototype.callContract = function (_a, blockIdentifier) {
231
238
  var contractAddress = _a.contractAddress, entryPointSelector = _a.entrypoint, _b = _a.calldata, calldata = _b === void 0 ? [] : _b;
232
239
  if (blockIdentifier === void 0) { blockIdentifier = 'pending'; }
@@ -7,3 +7,4 @@ export declare function hexToDecimalString(hex: string): string;
7
7
  export declare function toFelt(num: BigNumberish): string;
8
8
  export declare function assertInRange(input: BigNumberish, lowerBound: BigNumberish, upperBound: BigNumberish, inputName?: string): void;
9
9
  export declare function bigNumberishArrayToDecimalStringArray(rawCalldata: BigNumberish[]): string[];
10
+ export declare function bigNumberishArrayToHexadecimalStringArray(rawCalldata: BigNumberish[]): string[];
@@ -26,7 +26,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
26
26
  return (mod && mod.__esModule) ? mod : { "default": mod };
27
27
  };
28
28
  Object.defineProperty(exports, "__esModule", { value: true });
29
- exports.bigNumberishArrayToDecimalStringArray = exports.assertInRange = exports.toFelt = exports.hexToDecimalString = exports.toHex = exports.toBN = exports.isHex = void 0;
29
+ exports.bigNumberishArrayToHexadecimalStringArray = exports.bigNumberishArrayToDecimalStringArray = exports.assertInRange = exports.toFelt = exports.hexToDecimalString = exports.toHex = exports.toBN = exports.isHex = void 0;
30
30
  var bn_js_1 = __importStar(require("bn.js"));
31
31
  var minimalistic_assert_1 = __importDefault(require("minimalistic-assert"));
32
32
  var encode_1 = require("./encode");
@@ -76,3 +76,7 @@ function bigNumberishArrayToDecimalStringArray(rawCalldata) {
76
76
  return rawCalldata.map(function (x) { return toBN(x).toString(10); });
77
77
  }
78
78
  exports.bigNumberishArrayToDecimalStringArray = bigNumberishArrayToDecimalStringArray;
79
+ function bigNumberishArrayToHexadecimalStringArray(rawCalldata) {
80
+ return rawCalldata.map(function (x) { return toHex(toBN(x)); });
81
+ }
82
+ exports.bigNumberishArrayToHexadecimalStringArray = bigNumberishArrayToHexadecimalStringArray;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "starknet",
3
- "version": "4.4.0",
3
+ "version": "4.5.0",
4
4
  "description": "JavaScript library for StarkNet",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -85,6 +85,9 @@
85
85
  ],
86
86
  "setupFilesAfterEnv": [
87
87
  "./__tests__/jest.setup.ts"
88
+ ],
89
+ "sandboxInjectedGlobals": [
90
+ "Math"
88
91
  ]
89
92
  },
90
93
  "importSort": {
@@ -13,6 +13,7 @@ export declare class Provider implements ProviderInterface {
13
13
  private provider;
14
14
  constructor(providerOrOptions?: ProviderOptions | ProviderInterface);
15
15
  get chainId(): StarknetChainId;
16
+ getChainId(): Promise<StarknetChainId>;
16
17
  getBlock(blockIdentifier?: BlockIdentifier): Promise<GetBlockResponse>;
17
18
  getClassAt(contractAddress: string, blockIdentifier?: BlockIdentifier): Promise<ContractClass>;
18
19
  getEstimateFee(invocation: Invocation, blockIdentifier?: BlockIdentifier, invocationDetails?: InvocationsDetails): Promise<EstimateFeeResponse>;
@@ -61,6 +61,13 @@ var Provider = /** @class */ (function () {
61
61
  enumerable: false,
62
62
  configurable: true
63
63
  });
64
+ Provider.prototype.getChainId = function () {
65
+ return __awaiter(this, void 0, void 0, function () {
66
+ return __generator(this, function (_a) {
67
+ return [2 /*return*/, this.provider.getChainId()];
68
+ });
69
+ });
70
+ };
64
71
  Provider.prototype.getBlock = function (blockIdentifier) {
65
72
  if (blockIdentifier === void 0) { blockIdentifier = 'pending'; }
66
73
  return __awaiter(this, void 0, void 0, function () {
@@ -4,6 +4,12 @@ import type { BigNumberish } from '../utils/number';
4
4
  import { BlockIdentifier } from './utils';
5
5
  export declare abstract class ProviderInterface {
6
6
  abstract chainId: StarknetChainId;
7
+ /**
8
+ * Gets the Starknet chain Id
9
+ *
10
+ * @returns the chain Id
11
+ */
12
+ abstract getChainId(): Promise<StarknetChainId>;
7
13
  /**
8
14
  * Calls a function on the StarkNet contract.
9
15
  *
package/provider/rpc.js CHANGED
@@ -217,7 +217,7 @@ var RpcProvider = /** @class */ (function () {
217
217
  contract_address: invocation.contractAddress,
218
218
  entry_point_selector: (0, hash_1.getSelectorFromName)(invocation.entrypoint),
219
219
  calldata: (0, provider_1.parseCalldata)(invocation.calldata),
220
- signature: (0, number_1.bigNumberishArrayToDecimalStringArray)(invocation.signature || []),
220
+ signature: (0, number_1.bigNumberishArrayToHexadecimalStringArray)(invocation.signature || []),
221
221
  version: (0, number_1.toHex)((0, number_1.toBN)((invocationDetails === null || invocationDetails === void 0 ? void 0 : invocationDetails.version) || 0)),
222
222
  },
223
223
  blockIdentifier,
@@ -235,6 +235,7 @@ var RpcProvider = /** @class */ (function () {
235
235
  {
236
236
  program: contractDefinition.program,
237
237
  entry_points_by_type: contractDefinition.entry_points_by_type,
238
+ abi: contractDefinition.abi, // rpc 2.0
238
239
  },
239
240
  (0, number_1.toHex)((0, number_1.toBN)(version || 0)),
240
241
  ]).then(this.responseParser.parseDeclareContractResponse)];
@@ -249,10 +250,11 @@ var RpcProvider = /** @class */ (function () {
249
250
  contractDefinition = (0, provider_1.parseContract)(contract);
250
251
  return [2 /*return*/, this.fetchEndpoint('starknet_addDeployTransaction', [
251
252
  addressSalt !== null && addressSalt !== void 0 ? addressSalt : (0, stark_1.randomAddress)(),
252
- (0, number_1.bigNumberishArrayToDecimalStringArray)(constructorCalldata !== null && constructorCalldata !== void 0 ? constructorCalldata : []),
253
+ (0, number_1.bigNumberishArrayToHexadecimalStringArray)(constructorCalldata !== null && constructorCalldata !== void 0 ? constructorCalldata : []),
253
254
  {
254
255
  program: contractDefinition.program,
255
256
  entry_points_by_type: contractDefinition.entry_points_by_type,
257
+ abi: contractDefinition.abi, // rpc 2.0
256
258
  },
257
259
  ]).then(this.responseParser.parseDeployContractResponse)];
258
260
  });
@@ -267,7 +269,7 @@ var RpcProvider = /** @class */ (function () {
267
269
  entry_point_selector: (0, hash_1.getSelectorFromName)(functionInvocation.entrypoint),
268
270
  calldata: (0, provider_1.parseCalldata)(functionInvocation.calldata),
269
271
  },
270
- (0, number_1.bigNumberishArrayToDecimalStringArray)(functionInvocation.signature || []),
272
+ (0, number_1.bigNumberishArrayToHexadecimalStringArray)(functionInvocation.signature || []),
271
273
  (0, number_1.toHex)((0, number_1.toBN)(details.maxFee || 0)),
272
274
  (0, number_1.toHex)((0, number_1.toBN)(details.version || 0)),
273
275
  ]).then(this.responseParser.parseInvokeFunctionResponse)];
@@ -27,6 +27,7 @@ export declare class SequencerProvider implements ProviderInterface {
27
27
  private getQueryString;
28
28
  private getHeaders;
29
29
  protected fetchEndpoint<T extends keyof Sequencer.Endpoints>(endpoint: T, ...[query, request]: Sequencer.Endpoints[T]['QUERY'] extends never ? Sequencer.Endpoints[T]['REQUEST'] extends never ? [] : [undefined, Sequencer.Endpoints[T]['REQUEST']] : Sequencer.Endpoints[T]['REQUEST'] extends never ? [Sequencer.Endpoints[T]['QUERY']] : [Sequencer.Endpoints[T]['QUERY'], Sequencer.Endpoints[T]['REQUEST']]): Promise<Sequencer.Endpoints[T]['RESPONSE']>;
30
+ getChainId(): Promise<StarknetChainId>;
30
31
  callContract({ contractAddress, entrypoint: entryPointSelector, calldata }: Call, blockIdentifier?: BlockIdentifier): Promise<CallContractResponse>;
31
32
  getBlock(blockIdentifier?: BlockIdentifier): Promise<GetBlockResponse>;
32
33
  getStorageAt(contractAddress: string, key: BigNumberish, blockIdentifier?: BlockIdentifier): Promise<BigNumberish>;
@@ -227,6 +227,13 @@ var SequencerProvider = /** @class */ (function () {
227
227
  });
228
228
  });
229
229
  };
230
+ SequencerProvider.prototype.getChainId = function () {
231
+ return __awaiter(this, void 0, void 0, function () {
232
+ return __generator(this, function (_a) {
233
+ return [2 /*return*/, Promise.resolve(this.chainId)];
234
+ });
235
+ });
236
+ };
230
237
  SequencerProvider.prototype.callContract = function (_a, blockIdentifier) {
231
238
  var contractAddress = _a.contractAddress, entryPointSelector = _a.entrypoint, _b = _a.calldata, calldata = _b === void 0 ? [] : _b;
232
239
  if (blockIdentifier === void 0) { blockIdentifier = 'pending'; }
@@ -47,13 +47,14 @@ export class Account extends Provider implements AccountInterface {
47
47
  const transactions = Array.isArray(calls) ? calls : [calls];
48
48
  const nonce = providedNonce ?? (await this.getNonce());
49
49
  const version = toBN(feeTransactionVersion);
50
+ const chainId = await this.getChainId();
50
51
 
51
52
  const signerDetails: InvocationsSignerDetails = {
52
53
  walletAddress: this.address,
53
54
  nonce: toBN(nonce),
54
55
  maxFee: ZERO,
55
56
  version,
56
- chainId: this.chainId,
57
+ chainId,
57
58
  };
58
59
 
59
60
  const signature = await this.signer.signTransaction(transactions, signerDetails);
@@ -99,13 +100,14 @@ export class Account extends Provider implements AccountInterface {
99
100
  }
100
101
 
101
102
  const version = toBN(transactionVersion);
103
+ const chainId = await this.getChainId();
102
104
 
103
105
  const signerDetails: InvocationsSignerDetails = {
104
106
  walletAddress: this.address,
105
107
  nonce,
106
108
  maxFee,
107
109
  version,
108
- chainId: this.chainId,
110
+ chainId,
109
111
  };
110
112
 
111
113
  const signature = await this.signer.signTransaction(transactions, signerDetails, abis);
@@ -46,6 +46,10 @@ export class Provider implements ProviderInterface {
46
46
  return this.provider.chainId;
47
47
  }
48
48
 
49
+ public async getChainId(): Promise<StarknetChainId> {
50
+ return this.provider.getChainId();
51
+ }
52
+
49
53
  public async getBlock(blockIdentifier: BlockIdentifier = 'pending'): Promise<GetBlockResponse> {
50
54
  return this.provider.getBlock(blockIdentifier);
51
55
  }
@@ -22,6 +22,13 @@ import { BlockIdentifier } from './utils';
22
22
  export abstract class ProviderInterface {
23
23
  public abstract chainId: StarknetChainId;
24
24
 
25
+ /**
26
+ * Gets the Starknet chain Id
27
+ *
28
+ * @returns the chain Id
29
+ */
30
+ public abstract getChainId(): Promise<StarknetChainId>;
31
+
25
32
  /**
26
33
  * Calls a function on the StarkNet contract.
27
34
  *
@@ -19,7 +19,12 @@ import { RPC } from '../types/api';
19
19
  import fetch from '../utils/fetchPonyfill';
20
20
  import { getSelectorFromName } from '../utils/hash';
21
21
  import { stringify } from '../utils/json';
22
- import { BigNumberish, bigNumberishArrayToDecimalStringArray, toBN, toHex } from '../utils/number';
22
+ import {
23
+ BigNumberish,
24
+ bigNumberishArrayToHexadecimalStringArray,
25
+ toBN,
26
+ toHex,
27
+ } from '../utils/number';
23
28
  import { parseCalldata, parseContract, wait } from '../utils/provider';
24
29
  import { RPCResponseParser } from '../utils/responseParser/rpc';
25
30
  import { randomAddress } from '../utils/stark';
@@ -166,7 +171,7 @@ export class RpcProvider implements ProviderInterface {
166
171
  contract_address: invocation.contractAddress,
167
172
  entry_point_selector: getSelectorFromName(invocation.entrypoint),
168
173
  calldata: parseCalldata(invocation.calldata),
169
- signature: bigNumberishArrayToDecimalStringArray(invocation.signature || []),
174
+ signature: bigNumberishArrayToHexadecimalStringArray(invocation.signature || []),
170
175
  version: toHex(toBN(invocationDetails?.version || 0)),
171
176
  },
172
177
  blockIdentifier,
@@ -183,6 +188,7 @@ export class RpcProvider implements ProviderInterface {
183
188
  {
184
189
  program: contractDefinition.program,
185
190
  entry_points_by_type: contractDefinition.entry_points_by_type,
191
+ abi: contractDefinition.abi, // rpc 2.0
186
192
  },
187
193
  toHex(toBN(version || 0)),
188
194
  ]).then(this.responseParser.parseDeclareContractResponse);
@@ -197,10 +203,11 @@ export class RpcProvider implements ProviderInterface {
197
203
 
198
204
  return this.fetchEndpoint('starknet_addDeployTransaction', [
199
205
  addressSalt ?? randomAddress(),
200
- bigNumberishArrayToDecimalStringArray(constructorCalldata ?? []),
206
+ bigNumberishArrayToHexadecimalStringArray(constructorCalldata ?? []),
201
207
  {
202
208
  program: contractDefinition.program,
203
209
  entry_points_by_type: contractDefinition.entry_points_by_type,
210
+ abi: contractDefinition.abi, // rpc 2.0
204
211
  },
205
212
  ]).then(this.responseParser.parseDeployContractResponse);
206
213
  }
@@ -215,7 +222,7 @@ export class RpcProvider implements ProviderInterface {
215
222
  entry_point_selector: getSelectorFromName(functionInvocation.entrypoint),
216
223
  calldata: parseCalldata(functionInvocation.calldata),
217
224
  },
218
- bigNumberishArrayToDecimalStringArray(functionInvocation.signature || []),
225
+ bigNumberishArrayToHexadecimalStringArray(functionInvocation.signature || []),
219
226
  toHex(toBN(details.maxFee || 0)),
220
227
  toHex(toBN(details.version || 0)),
221
228
  ]).then(this.responseParser.parseInvokeFunctionResponse);
@@ -207,6 +207,10 @@ export class SequencerProvider implements ProviderInterface {
207
207
  }
208
208
  }
209
209
 
210
+ public async getChainId(): Promise<StarknetChainId> {
211
+ return Promise.resolve(this.chainId);
212
+ }
213
+
210
214
  public async callContract(
211
215
  { contractAddress, entrypoint: entryPointSelector, calldata = [] }: Call,
212
216
  blockIdentifier: BlockIdentifier = 'pending'
@@ -57,3 +57,7 @@ export function assertInRange(
57
57
  export function bigNumberishArrayToDecimalStringArray(rawCalldata: BigNumberish[]): string[] {
58
58
  return rawCalldata.map((x) => toBN(x).toString(10));
59
59
  }
60
+
61
+ export function bigNumberishArrayToHexadecimalStringArray(rawCalldata: BigNumberish[]): string[] {
62
+ return rawCalldata.map((x) => toHex(toBN(x)));
63
+ }
package/utils/number.d.ts CHANGED
@@ -7,3 +7,4 @@ export declare function hexToDecimalString(hex: string): string;
7
7
  export declare function toFelt(num: BigNumberish): string;
8
8
  export declare function assertInRange(input: BigNumberish, lowerBound: BigNumberish, upperBound: BigNumberish, inputName?: string): void;
9
9
  export declare function bigNumberishArrayToDecimalStringArray(rawCalldata: BigNumberish[]): string[];
10
+ export declare function bigNumberishArrayToHexadecimalStringArray(rawCalldata: BigNumberish[]): string[];
package/utils/number.js CHANGED
@@ -26,7 +26,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
26
26
  return (mod && mod.__esModule) ? mod : { "default": mod };
27
27
  };
28
28
  Object.defineProperty(exports, "__esModule", { value: true });
29
- exports.bigNumberishArrayToDecimalStringArray = exports.assertInRange = exports.toFelt = exports.hexToDecimalString = exports.toHex = exports.toBN = exports.isHex = void 0;
29
+ exports.bigNumberishArrayToHexadecimalStringArray = exports.bigNumberishArrayToDecimalStringArray = exports.assertInRange = exports.toFelt = exports.hexToDecimalString = exports.toHex = exports.toBN = exports.isHex = void 0;
30
30
  var bn_js_1 = __importStar(require("bn.js"));
31
31
  var minimalistic_assert_1 = __importDefault(require("minimalistic-assert"));
32
32
  var encode_1 = require("./encode");
@@ -76,3 +76,7 @@ function bigNumberishArrayToDecimalStringArray(rawCalldata) {
76
76
  return rawCalldata.map(function (x) { return toBN(x).toString(10); });
77
77
  }
78
78
  exports.bigNumberishArrayToDecimalStringArray = bigNumberishArrayToDecimalStringArray;
79
+ function bigNumberishArrayToHexadecimalStringArray(rawCalldata) {
80
+ return rawCalldata.map(function (x) { return toHex(toBN(x)); });
81
+ }
82
+ exports.bigNumberishArrayToHexadecimalStringArray = bigNumberishArrayToHexadecimalStringArray;
@@ -176,6 +176,12 @@ const signature = await this.signer.signTransaction(transactions, signerDetails)
176
176
  }
177
177
  ```
178
178
 
179
+ ### bigNumberishArrayToHexadecimalStringArray
180
+
181
+ `bigNumberishArrayToHexadecimalStringArray(rawCalldata: BigNumberish[]): string[]`
182
+
183
+ Convert BigNumberish array to hexadecimal string array. Used for signature conversion.
184
+
179
185
  <hr />
180
186
 
181
187
  ## **uint256**