starknet 3.12.3 → 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.
Files changed (76) hide show
  1. package/.github/workflows/pr.yml +3 -0
  2. package/.github/workflows/release.yml +4 -0
  3. package/CHANGELOG.md +42 -0
  4. package/__mocks__/Account.json +25468 -0
  5. package/__tests__/account.test.ts +102 -65
  6. package/__tests__/contract.test.ts +23 -65
  7. package/__tests__/fixtures.ts +21 -1
  8. package/__tests__/provider.test.ts +31 -2
  9. package/account/default.d.ts +2 -9
  10. package/account/default.js +1 -0
  11. package/account/index.js +10 -6
  12. package/account/interface.d.ts +5 -3
  13. package/constants.d.ts +1 -0
  14. package/constants.js +1 -0
  15. package/contract/default.d.ts +1 -1
  16. package/contract/default.js +20 -21
  17. package/contract/index.js +10 -6
  18. package/dist/account/default.d.ts +2 -6
  19. package/dist/account/default.js +2 -0
  20. package/dist/account/index.js +5 -1
  21. package/dist/account/interface.d.ts +3 -3
  22. package/dist/constants.d.ts +1 -0
  23. package/dist/constants.js +1 -0
  24. package/dist/contract/default.d.ts +1 -1
  25. package/dist/contract/default.js +18 -18
  26. package/dist/contract/index.js +5 -1
  27. package/dist/index.js +5 -1
  28. package/dist/provider/default.d.ts +11 -4
  29. package/dist/provider/default.js +29 -8
  30. package/dist/provider/index.js +5 -1
  31. package/dist/provider/interface.d.ts +9 -1
  32. package/dist/provider/utils.js +5 -5
  33. package/dist/signer/index.js +5 -1
  34. package/dist/types/account.d.ts +6 -0
  35. package/dist/types/api.d.ts +10 -2
  36. package/dist/types/index.d.ts +1 -0
  37. package/dist/types/index.js +6 -1
  38. package/dist/types/lib.d.ts +4 -1
  39. package/dist/utils/ellipticCurve.js +1 -1
  40. package/dist/utils/encode.js +1 -1
  41. package/dist/utils/hash.js +1 -1
  42. package/dist/utils/number.js +8 -4
  43. package/dist/utils/shortString.js +2 -2
  44. package/dist/utils/typedData/index.js +8 -4
  45. package/index.js +10 -6
  46. package/package.json +30 -28
  47. package/provider/default.d.ts +11 -3
  48. package/provider/default.js +31 -12
  49. package/provider/index.js +10 -6
  50. package/provider/interface.d.ts +9 -1
  51. package/provider/utils.js +5 -5
  52. package/signer/index.js +10 -6
  53. package/src/account/default.ts +3 -6
  54. package/src/account/interface.ts +5 -3
  55. package/src/constants.ts +1 -0
  56. package/src/provider/default.ts +33 -6
  57. package/src/provider/interface.ts +9 -1
  58. package/src/types/account.ts +7 -0
  59. package/src/types/api.ts +11 -2
  60. package/src/types/index.ts +1 -0
  61. package/src/types/lib.ts +5 -1
  62. package/types/account.d.ts +6 -0
  63. package/types/api.d.ts +13 -2
  64. package/types/index.d.ts +1 -0
  65. package/types/index.js +11 -6
  66. package/types/lib.d.ts +4 -1
  67. package/utils/ellipticCurve.js +1 -1
  68. package/utils/encode.js +1 -1
  69. package/utils/hash.js +1 -1
  70. package/utils/number.js +13 -9
  71. package/utils/shortString.js +2 -2
  72. package/utils/typedData/index.js +15 -13
  73. package/www/docs/API/provider.md +20 -3
  74. package/www/guides/account.md +21 -7
  75. package/www/guides/erc20.md +15 -27
  76. package/__tests__/accountContract.test.ts +0 -110
@@ -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,
@@ -31,7 +32,9 @@ type NetworkName = 'mainnet-alpha' | 'goerli-alpha';
31
32
  type ProviderOptions = { network: NetworkName } | { baseUrl: string };
32
33
 
33
34
  function wait(delay: number) {
34
- return new Promise((res) => setTimeout(res, delay));
35
+ return new Promise((res) => {
36
+ setTimeout(res, delay);
37
+ });
35
38
  }
36
39
 
37
40
  function isEmptyQueryObject(obj?: Record<any, any>): obj is undefined {
@@ -250,7 +253,7 @@ export class Provider implements ProviderInterface {
250
253
  */
251
254
  public async getStorageAt(
252
255
  contractAddress: string,
253
- key: number,
256
+ key: BigNumberish,
254
257
  blockIdentifier: BlockIdentifier = 'pending'
255
258
  ): Promise<object> {
256
259
  return this.fetchEndpoint('get_storage_at', { blockIdentifier, contractAddress, key });
@@ -270,14 +273,13 @@ export class Provider implements ProviderInterface {
270
273
  }
271
274
 
272
275
  /**
273
- * Gets the transaction receipt from a tx hash or tx id.
276
+ * Gets the transaction receipt from a tx hash.
274
277
  *
275
- * [Reference] (https://github.com/starkware-libs/cairo-lang/blob/master/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L104-L111)
278
+ * [Reference] (https://github.com/starkware-libs/cairo-lang/blob/167b28bcd940fd25ea3816204fa882a0b0a49603/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L183)
276
279
  *
277
280
  * @param txHash
278
281
  * @returns the transaction receipt object
279
282
  */
280
-
281
283
  public async getTransactionReceipt(txHash: BigNumberish): Promise<TransactionReceiptResponse> {
282
284
  const txHashHex = toHex(toBN(txHash));
283
285
  return this.fetchEndpoint('get_transaction_receipt', { transactionHash: txHashHex });
@@ -308,6 +310,31 @@ export class Provider implements ProviderInterface {
308
310
  return this.fetchEndpoint('get_transaction_trace', { transactionHash: txHashHex });
309
311
  }
310
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
+
311
338
  /**
312
339
  * Deploys a given compiled contract (json) to starknet
313
340
  *
@@ -85,7 +85,7 @@ export abstract class ProviderInterface {
85
85
  */
86
86
  public abstract getStorageAt(
87
87
  contractAddress: string,
88
- key: number,
88
+ key: BigNumberish,
89
89
  blockIdentifier?: BlockIdentifier
90
90
  ): Promise<object>;
91
91
 
@@ -109,6 +109,14 @@ export abstract class ProviderInterface {
109
109
  */
110
110
  public abstract getTransaction(txHash: BigNumberish): Promise<GetTransactionResponse>;
111
111
 
112
+ /**
113
+ * Gets the transaction receipt from a tx hash.
114
+ *
115
+ * [Reference] (https://github.com/starkware-libs/cairo-lang/blob/167b28bcd940fd25ea3816204fa882a0b0a49603/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L183)
116
+ *
117
+ * @param txHash
118
+ * @returns the transaction receipt object
119
+ */
112
120
  public abstract getTransactionReceipt(txHash: BigNumberish): Promise<TransactionReceiptResponse>;
113
121
 
114
122
  /**
@@ -1,7 +1,14 @@
1
1
  import BN from 'bn.js';
2
2
 
3
+ import { BlockIdentifier } from '../provider/utils';
4
+ import { BigNumberish } from '../utils/number';
3
5
  import { EstimateFeeResponse } from './api';
4
6
 
5
7
  export interface EstimateFee extends EstimateFeeResponse {
6
8
  suggestedMaxFee: BN;
7
9
  }
10
+
11
+ export interface EstimateFeeDetails {
12
+ nonce?: BigNumberish;
13
+ blockIdentifier?: BlockIdentifier;
14
+ }
package/src/types/api.ts CHANGED
@@ -55,7 +55,7 @@ export type Endpoints = {
55
55
  get_storage_at: {
56
56
  QUERY: {
57
57
  contractAddress: string;
58
- key: number;
58
+ key: BigNumberish;
59
59
  blockIdentifier: BlockIdentifier;
60
60
  };
61
61
  REQUEST: never;
@@ -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 = {
@@ -2,3 +2,4 @@ export * from './lib';
2
2
  export * from './api';
3
3
  export * from './signer';
4
4
  export * from './contract';
5
+ export * from './account';
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
 
@@ -1,6 +1,12 @@
1
1
  import BN from 'bn.js';
2
2
 
3
+ import { BlockIdentifier } from '../provider/utils';
4
+ import { BigNumberish } from '../utils/number';
3
5
  import { EstimateFeeResponse } from './api';
4
6
  export interface EstimateFee extends EstimateFeeResponse {
5
7
  suggestedMaxFee: BN;
6
8
  }
9
+ export interface EstimateFeeDetails {
10
+ nonce?: BigNumberish;
11
+ blockIdentifier?: BlockIdentifier;
12
+ }
package/types/api.d.ts CHANGED
@@ -54,7 +54,7 @@ export declare type Endpoints = {
54
54
  get_storage_at: {
55
55
  QUERY: {
56
56
  contractAddress: string;
57
- key: number;
57
+ key: BigNumberish;
58
58
  blockIdentifier: BlockIdentifier;
59
59
  };
60
60
  REQUEST: never;
@@ -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/index.d.ts CHANGED
@@ -2,3 +2,4 @@ export * from './lib';
2
2
  export * from './api';
3
3
  export * from './signer';
4
4
  export * from './contract';
5
+ export * from './account';
package/types/index.js CHANGED
@@ -4,12 +4,16 @@ var __createBinding =
4
4
  (Object.create
5
5
  ? function (o, m, k, k2) {
6
6
  if (k2 === undefined) k2 = k;
7
- Object.defineProperty(o, k2, {
8
- enumerable: true,
9
- get: function () {
10
- return m[k];
11
- },
12
- });
7
+ var desc = Object.getOwnPropertyDescriptor(m, k);
8
+ if (!desc || ('get' in desc ? !m.__esModule : desc.writable || desc.configurable)) {
9
+ desc = {
10
+ enumerable: true,
11
+ get: function () {
12
+ return m[k];
13
+ },
14
+ };
15
+ }
16
+ Object.defineProperty(o, k2, desc);
13
17
  }
14
18
  : function (o, m, k, k2) {
15
19
  if (k2 === undefined) k2 = k;
@@ -27,3 +31,4 @@ __exportStar(require('./lib'), exports);
27
31
  __exportStar(require('./api'), exports);
28
32
  __exportStar(require('./signer'), exports);
29
33
  __exportStar(require('./contract'), exports);
34
+ __exportStar(require('./account'), exports);
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 = {
@@ -68,7 +68,7 @@ function fixMessage(msg) {
68
68
  }
69
69
  (0, minimalistic_assert_1.default)(pureHex.length === 63);
70
70
  // In this case delta will be 4 so we perform a shift-left of 4 bits by adding a ZERO_BN.
71
- return pureHex + '0';
71
+ return ''.concat(pureHex, '0');
72
72
  }
73
73
  exports.genKeyPair = exports.ec.genKeyPair.bind(exports.ec);
74
74
  function getKeyPair(pk) {
package/utils/encode.js CHANGED
@@ -76,7 +76,7 @@ function removeHexPrefix(hex) {
76
76
  }
77
77
  exports.removeHexPrefix = removeHexPrefix;
78
78
  function addHexPrefix(hex) {
79
- return '0x' + removeHexPrefix(hex);
79
+ return '0x'.concat(removeHexPrefix(hex));
80
80
  }
81
81
  exports.addHexPrefix = addHexPrefix;
82
82
  function padString(str, length, left, padding) {
package/utils/hash.js CHANGED
@@ -97,7 +97,7 @@ function pedersen(input) {
97
97
  (0, minimalistic_assert_1.default)(
98
98
  x.gte(constants_1.ZERO) &&
99
99
  x.lt((0, number_1.toBN)((0, encode_1.addHexPrefix)(constants_1.FIELD_PRIME))),
100
- 'Invalid input: ' + input[i]
100
+ 'Invalid input: '.concat(input[i])
101
101
  );
102
102
  for (var j = 0; j < 252; j += 1) {
103
103
  var pt = constantPoints[2 + i * 252 + j];
package/utils/number.js CHANGED
@@ -4,12 +4,16 @@ var __createBinding =
4
4
  (Object.create
5
5
  ? function (o, m, k, k2) {
6
6
  if (k2 === undefined) k2 = k;
7
- Object.defineProperty(o, k2, {
8
- enumerable: true,
9
- get: function () {
10
- return m[k];
11
- },
12
- });
7
+ var desc = Object.getOwnPropertyDescriptor(m, k);
8
+ if (!desc || ('get' in desc ? !m.__esModule : desc.writable || desc.configurable)) {
9
+ desc = {
10
+ enumerable: true,
11
+ get: function () {
12
+ return m[k];
13
+ },
14
+ };
15
+ }
16
+ Object.defineProperty(o, k2, desc);
13
17
  }
14
18
  : function (o, m, k, k2) {
15
19
  if (k2 === undefined) k2 = k;
@@ -68,7 +72,7 @@ function toHex(number) {
68
72
  }
69
73
  exports.toHex = toHex;
70
74
  function hexToDecimalString(hex) {
71
- return toBN('0x' + hex.replace(/^0x/, '')).toString();
75
+ return toBN('0x'.concat(hex.replace(/^0x/, ''))).toString();
72
76
  }
73
77
  exports.hexToDecimalString = hexToDecimalString;
74
78
  function toFelt(num) {
@@ -88,11 +92,11 @@ function assertInRange(input, lowerBound, upperBound, inputName) {
88
92
  if (inputName === void 0) {
89
93
  inputName = '';
90
94
  }
91
- var messageSuffix = inputName === '' ? 'invalid length' : 'invalid ' + inputName + ' length';
95
+ var messageSuffix = inputName === '' ? 'invalid length' : 'invalid '.concat(inputName, ' length');
92
96
  var inputBn = toBN(input);
93
97
  (0, minimalistic_assert_1.default)(
94
98
  inputBn.gte(toBN(lowerBound)) && inputBn.lt(toBN(upperBound)),
95
- 'Message not signable, ' + messageSuffix + '.'
99
+ 'Message not signable, '.concat(messageSuffix, '.')
96
100
  );
97
101
  }
98
102
  exports.assertInRange = assertInRange;
@@ -17,8 +17,8 @@ function isShortString(str) {
17
17
  }
18
18
  exports.isShortString = isShortString;
19
19
  function encodeShortString(str) {
20
- if (!isASCII(str)) throw new Error(str + ' is not an ASCII string');
21
- if (!isShortString(str)) throw new Error(str + ' is too long');
20
+ if (!isASCII(str)) throw new Error(''.concat(str, ' is not an ASCII string'));
21
+ if (!isShortString(str)) throw new Error(''.concat(str, ' is too long'));
22
22
  return (0, encode_1.addHexPrefix)(
23
23
  str.replace(/./g, function (char) {
24
24
  return char.charCodeAt(0).toString(16);
@@ -4,12 +4,16 @@ var __createBinding =
4
4
  (Object.create
5
5
  ? function (o, m, k, k2) {
6
6
  if (k2 === undefined) k2 = k;
7
- Object.defineProperty(o, k2, {
8
- enumerable: true,
9
- get: function () {
10
- return m[k];
11
- },
12
- });
7
+ var desc = Object.getOwnPropertyDescriptor(m, k);
8
+ if (!desc || ('get' in desc ? !m.__esModule : desc.writable || desc.configurable)) {
9
+ desc = {
10
+ enumerable: true,
11
+ get: function () {
12
+ return m[k];
13
+ },
14
+ };
15
+ }
16
+ Object.defineProperty(o, k2, desc);
13
17
  }
14
18
  : function (o, m, k, k2) {
15
19
  if (k2 === undefined) k2 = k;
@@ -76,7 +80,7 @@ function getHex(value) {
76
80
  if (typeof value === 'string') {
77
81
  return (0, number_1.toHex)((0, number_1.toBN)((0, shortString_1.encodeShortString)(value)));
78
82
  }
79
- throw new Error('Invalid BigNumberish: ' + value);
83
+ throw new Error('Invalid BigNumberish: '.concat(value));
80
84
  }
81
85
  }
82
86
  /**
@@ -135,12 +139,10 @@ var encodeType = function (typedData, type) {
135
139
  var types = __spreadArray([primary], __read(dependencies.sort()), false);
136
140
  return types
137
141
  .map(function (dependency) {
138
- return (
139
- dependency +
140
- '(' +
142
+ return ''.concat(dependency, '(').concat(
141
143
  typedData.types[dependency].map(function (t) {
142
- return t.name + ':' + t.type;
143
- }) +
144
+ return ''.concat(t.name, ':').concat(t.type);
145
+ }),
144
146
  ')'
145
147
  );
146
148
  })
@@ -193,7 +195,7 @@ var encodeData = function (typedData, type, data) {
193
195
  ts = _b[0],
194
196
  vs = _b[1];
195
197
  if (data[field.name] === undefined || data[field.name] === null) {
196
- throw new Error("Cannot encode data: missing data for '" + field.name + "'");
198
+ throw new Error("Cannot encode data: missing data for '".concat(field.name, "'"));
197
199
  }
198
200
  var value = data[field.name];
199
201
  var _c = __read(encodeValue(typedData, field.type, value), 2),
@@ -131,11 +131,11 @@ Gets the status of a transaction.
131
131
 
132
132
  <hr/>
133
133
 
134
- provider.**getTransactionReceipt**(txHash, txId) => _Promise < TransactionReceipt >_
134
+ provider.**getTransactionReceipt**(txHash) => _Promise < TransactionReceiptResponse >_
135
135
 
136
136
  Gets the status of a transaction.
137
137
 
138
- ###### _TransactionReceipt_
138
+ ###### _TransactionReceiptResponse_
139
139
 
140
140
  ```
141
141
  {
@@ -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
 
@@ -14,7 +14,15 @@ Install the latest version of starknet with `npm install starknet@next`
14
14
 
15
15
  ```javascript
16
16
  import fs from "fs";
17
- import * as starknet from "starknet";
17
+ import fs from "fs";
18
+ import {
19
+ Account,
20
+ Contract,
21
+ defaultProvider,
22
+ ec,
23
+ json,
24
+ number,
25
+ } from "starknet";
18
26
  ```
19
27
 
20
28
  ## Generate random key pair.
@@ -44,17 +52,23 @@ const accountResponse = await defaultProvider.deployContract({
44
52
 
45
53
  Wait for the deployment transaction to be accepted and assign the address of the deployed account to the Account object.
46
54
 
47
- Use your new account object to sign transactions, messages or verify signatures!
48
-
49
55
  ```javascript
50
56
  await defaultProvider.waitForTransaction(accountResponse.transaction_hash);
51
57
  const accountContract = new Contract(
52
58
  compiledArgentAccount.abi,
53
59
  accountResponse.address
54
60
  );
55
- const { transaction_hash: initializeTxHash } = await accountContract.initialize(
56
- starkKeyPub,
57
- "0"
61
+ const initializeResponse = await accountContract.initialize(starkKeyPub, "0");
62
+
63
+ await defaultProvider.waitForTransaction(initializeResponse.transaction_hash);
64
+ ```
65
+
66
+ Once account contract is initialized [Account](../docs/API/account.md) instance can be created. Use your new account instance to sign transactions, messages or verify signatures!
67
+
68
+ ```js
69
+ const account = new Account(
70
+ defaultProvider,
71
+ accountResponse.address,
72
+ starkKeyPair
58
73
  );
59
- await defaultProvider.waitForTransaction(initializeTxHash);
60
74
  ```
@@ -4,7 +4,7 @@ sidebar_position: 3
4
4
 
5
5
  # Deploy an ERC20 Contract
6
6
 
7
- Dpeploy the contract and wait for deployment transaction to be accepted on StarkNet
7
+ Deploy the contract and wait for deployment transaction to be accepted on StarkNet
8
8
 
9
9
  ```javascript
10
10
  const compiledErc20 = json.parse(
@@ -26,9 +26,11 @@ const erc20 = new Contract(compiledErc20.abi, erc20Address);
26
26
 
27
27
  ## Mint tokens to an account address
28
28
 
29
+ Make sure you created the `Account` instance following the [Creating an Account](./account.md) guide.
30
+
29
31
  ```javascript
30
32
  const { transaction_hash: mintTxHash } = await erc20.mint(
31
- accountContract.address,
33
+ account.address,
32
34
  "1000"
33
35
  );
34
36
  console.log(`Waiting for Tx to be Accepted on Starknet - Minting...`);
@@ -38,11 +40,11 @@ await defaultProvider.waitForTransaction(mintTxHash);
38
40
  ## Check balance after mint
39
41
 
40
42
  ```javascript
41
- console.log(`Calling StarkNet for accountContract balance...`);
42
- const balanceBeforeTransfer = await erc20.balance_of(accountContract.address);
43
+ console.log(`Calling StarkNet for account balance...`);
44
+ const balanceBeforeTransfer = await erc20.balance_of(account.address);
43
45
 
44
46
  console.log(
45
- `accountContract Address ${accountContract.address} has a balance of:`,
47
+ `account Address ${account.address} has a balance of:`,
46
48
  number.toBN(balanceBeforeTransfer.res, 16).toString()
47
49
  );
48
50
  ```
@@ -50,30 +52,16 @@ console.log(
50
52
  ## Transfer tokens
51
53
 
52
54
  ```javascript
53
- // Get the nonce of the account and prepare transfer tx
54
- console.log(`Calling StarkNet for accountContract nonce...`);
55
- const nonce = (await accountContract.call("get_nonce")).nonce.toString();
56
- const calls = [
55
+ // Execute tx transfer of 10 tokens
56
+ console.log(`Invoke Tx - Transfer 10 tokens back to erc20 contract...`);
57
+ const { transaction_hash: transferTxHash } = await account.execute(
57
58
  {
58
59
  contractAddress: erc20Address,
59
60
  entrypoint: "transfer",
60
61
  calldata: [erc20Address, "10"],
61
62
  },
62
- ];
63
- const msgHash = hash.hashMulticall(accountContract.address, calls, nonce, "0");
64
-
65
- const { callArray, calldata } = transformCallsToMulticallArrays(calls);
66
-
67
- // sign tx to transfer 10 tokens
68
- const signature = ec.sign(starkKeyPair, msgHash);
69
-
70
- // Execute tx transfer of 10 tokens
71
- console.log(`Invoke Tx - Transfer 10 tokens back to erc20 contract...`);
72
- const { transaction_hash: transferTxHash } = await accountContract.__execute__(
73
- callArray,
74
- calldata,
75
- nonce,
76
- signature
63
+ undefined,
64
+ { maxFee: "0" }
77
65
  );
78
66
 
79
67
  // Wait for the invoke transaction to be accepted on StarkNet
@@ -85,11 +73,11 @@ await defaultProvider.waitForTransaction(transferTxHash);
85
73
 
86
74
  ```javascript
87
75
  // Check balance after transfer - should be 990
88
- console.log(`Calling StarkNet for accountContract balance...`);
89
- const balanceAfterTransfer = await erc20.balance_of(accountContract.address);
76
+ console.log(`Calling StarkNet for account balance...`);
77
+ const balanceAfterTransfer = await erc20.balance_of(account.address);
90
78
 
91
79
  console.log(
92
- `accountContract Address ${accountContract.address} has a balance of:`,
80
+ `account Address ${account.address} has a balance of:`,
93
81
  number.toBN(balanceAfterTransfer.res, 16).toString()
94
82
  );
95
83
  ```