starknet 4.16.0 → 4.17.1

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,22 @@
1
+ ## [4.17.1](https://github.com/0xs34n/starknet.js/compare/v4.17.0...v4.17.1) (2022-12-14)
2
+
3
+ ### Bug Fixes
4
+
5
+ - estimateAccountDeployFee set nonce to constant 0 ([2110ef0](https://github.com/0xs34n/starknet.js/commit/2110ef09da63765609d60e01259c360a0e8a9ddf))
6
+ - nonce should be fixed for deploy account to 0 ([c8a38e5](https://github.com/0xs34n/starknet.js/commit/c8a38e5349e5c5ebe3bb0665a4fb18cd02811626))
7
+ - rpc deployAccountContract request, rpc nonce hotfix ([9576335](https://github.com/0xs34n/starknet.js/commit/9576335893561603cfd6a8ff4454b69cb49f7484))
8
+
9
+ # [4.17.0](https://github.com/0xs34n/starknet.js/compare/v4.16.0...v4.17.0) (2022-12-13)
10
+
11
+ ### Bug Fixes
12
+
13
+ - merge conflicts ([92a3be8](https://github.com/0xs34n/starknet.js/commit/92a3be8500153d4b87b888f454bb4140edb88411))
14
+
15
+ ### Features
16
+
17
+ - contract factory deploy arguments ([9eff7f4](https://github.com/0xs34n/starknet.js/commit/9eff7f4ccc74cb5f0c0594e88c0292600f20ec09))
18
+ - update contractFactory docs ([76f8440](https://github.com/0xs34n/starknet.js/commit/76f8440233c4a1e24e3dfff25fe02525e86a8258))
19
+
1
20
  # [4.16.0](https://github.com/0xs34n/starknet.js/compare/v4.15.1...v4.16.0) (2022-12-12)
2
21
 
3
22
  ### Bug Fixes
@@ -338,6 +338,8 @@ describe('deploy and test Wallet', () => {
338
338
  expect(deployments).toHaveProperty('transaction_hash');
339
339
  expect(deployments.contract_address[0]).toBeDefined();
340
340
  expect(deployments.contract_address[1]).toBeDefined();
341
+
342
+ await provider.waitForTransaction(deployments.transaction_hash);
341
343
  });
342
344
  });
343
345
  });
@@ -220,12 +220,24 @@ describe('contract module', () => {
220
220
  });
221
221
  test('deployment of new contract', async () => {
222
222
  const factory = new ContractFactory(compiledErc20, classHash, account);
223
- const erc20 = await factory.deploy(constructorCalldata);
223
+ const erc20 = await factory.deploy(
224
+ compileCalldata({
225
+ name: encodeShortString('Token'),
226
+ symbol: encodeShortString('ERC20'),
227
+ recipient: wallet,
228
+ })
229
+ );
224
230
  expect(erc20 instanceof Contract);
225
231
  });
226
232
  test('wait for deployment transaction', async () => {
227
233
  const factory = new ContractFactory(compiledErc20, classHash, account);
228
- const contract = await factory.deploy(constructorCalldata);
234
+ const contract = await factory.deploy(
235
+ compileCalldata({
236
+ name: encodeShortString('Token'),
237
+ symbol: encodeShortString('ERC20'),
238
+ recipient: wallet,
239
+ })
240
+ );
229
241
  expect(contract.deployed()).resolves.not.toThrow();
230
242
  });
231
243
  test('attach new contract', async () => {
@@ -1,11 +1,11 @@
1
- import { BlockNumber, GetBlockResponse, stark } from '../src';
1
+ import { BlockNumber, GetBlockResponse, Provider, stark } from '../src';
2
2
  import { toBN } from '../src/utils/number';
3
3
  import { encodeShortString } from '../src/utils/shortString';
4
4
  import { compiledErc20, erc20ClassHash, getTestAccount, getTestProvider } from './fixtures';
5
5
 
6
6
  const { compileCalldata } = stark;
7
7
 
8
- const testProvider = getTestProvider();
8
+ const testProvider = new Provider(getTestProvider());
9
9
 
10
10
  describe('defaultProvider', () => {
11
11
  let exampleTransactionHash: string;
@@ -17,6 +17,8 @@ describe('defaultProvider', () => {
17
17
  const account = getTestAccount(testProvider);
18
18
 
19
19
  beforeAll(async () => {
20
+ expect(testProvider).toBeInstanceOf(Provider);
21
+
20
22
  const { deploy } = await account.declareDeploy({
21
23
  contract: compiledErc20,
22
24
  classHash: '0x54328a1075b8820eb43caf0caa233923148c983742402dcfc38541dd843d01a',
@@ -47,7 +47,7 @@ export const getTestProvider = (): ProviderInterface => {
47
47
  if (IS_LOCALHOST_DEVNET) {
48
48
  // accelerate the tests when running locally
49
49
  const originalWaitForTransaction = provider.waitForTransaction.bind(provider);
50
- provider.waitForTransaction = (txHash, retryInterval) => {
50
+ provider.waitForTransaction = (txHash: string, retryInterval?: number) => {
51
51
  return originalWaitForTransaction(txHash, retryInterval || 1000);
52
52
  };
53
53
  }
@@ -86,8 +86,8 @@ describeIfRpc('RPCProvider', () => {
86
86
  });
87
87
 
88
88
  describe('deploy contract related tests', () => {
89
- let contract_address;
90
- let transaction_hash;
89
+ let contract_address: string;
90
+ let transaction_hash: string;
91
91
 
92
92
  beforeAll(async () => {
93
93
  const { deploy } = await account.declareDeploy({
@@ -128,9 +128,5 @@ describeIfRpc('RPCProvider', () => {
128
128
  expect(contractClass).toHaveProperty('program');
129
129
  expect(contractClass).toHaveProperty('entry_points_by_type');
130
130
  });
131
-
132
- test.todo('getEstimateFee');
133
-
134
- test.todo('invokeFunction');
135
131
  });
136
132
  });
package/dist/index.d.ts CHANGED
@@ -544,7 +544,9 @@ declare namespace OPENRPC {
544
544
  errors: Errors.INVALID_CONTRACT_CLASS;
545
545
  };
546
546
  starknet_addDeployAccountTransaction: {
547
- params: BROADCASTED_DEPLOY_ACCOUNT_TXN;
547
+ params: {
548
+ deploy_account_transaction: BROADCASTED_DEPLOY_ACCOUNT_TXN;
549
+ };
548
550
  result: {
549
551
  transaction_hash: TXN_HASH;
550
552
  contract_address: FELT;
@@ -1477,7 +1479,7 @@ declare abstract class ProviderInterface {
1477
1479
  abstract deployAccountContract(payload: DeployAccountContractPayload, details: InvocationsDetailsWithNonce): Promise<DeployContractResponse>;
1478
1480
  /**
1479
1481
  * Invokes a function on starknet
1480
- * @deprecated This method wont be supported as soon as fees are mandatory
1482
+ * @deprecated This method wont be supported as soon as fees are mandatory. Should not be used outside of Account class
1481
1483
  *
1482
1484
  * @param invocation the invocation object containing:
1483
1485
  * - contractAddress - the address of the contract
@@ -1506,7 +1508,7 @@ declare abstract class ProviderInterface {
1506
1508
  abstract declareContract(transaction: DeclareContractTransaction, details: InvocationsDetailsWithNonce): Promise<DeclareContractResponse>;
1507
1509
  /**
1508
1510
  * Estimates the fee for a given INVOKE transaction
1509
- * @deprecated Please use getInvokeEstimateFee or getDeclareEstimateFee instead
1511
+ * @deprecated Please use getInvokeEstimateFee or getDeclareEstimateFee instead. Should not be used outside of Account class
1510
1512
  *
1511
1513
  * @param invocation the invocation object containing:
1512
1514
  * - contractAddress - the address of the contract
@@ -1737,13 +1739,13 @@ declare class Provider implements ProviderInterface {
1737
1739
  get chainId(): StarknetChainId;
1738
1740
  getChainId(): Promise<StarknetChainId>;
1739
1741
  getBlock(blockIdentifier: BlockIdentifier): Promise<GetBlockResponse>;
1740
- getClassAt(contractAddress: string, blockIdentifier: BlockIdentifier): Promise<ContractClass>;
1742
+ getClassAt(contractAddress: string, blockIdentifier?: BlockIdentifier): Promise<ContractClass>;
1741
1743
  getClassHashAt(contractAddress: string, blockIdentifier: BlockIdentifier): Promise<string>;
1742
1744
  getClassByHash(classHash: string): Promise<ContractClass>;
1743
1745
  getEstimateFee(invocationWithTxType: Invocation, invocationDetails: InvocationsDetailsWithNonce, blockIdentifier: BlockIdentifier): Promise<EstimateFeeResponse>;
1744
1746
  getInvokeEstimateFee(invocationWithTxType: Invocation, invocationDetails: InvocationsDetailsWithNonce, blockIdentifier?: BlockIdentifier): Promise<EstimateFeeResponse>;
1745
1747
  getNonceForAddress(contractAddress: string, blockIdentifier?: BlockIdentifier): Promise<BigNumberish>;
1746
- getStorageAt(contractAddress: string, key: BigNumberish, blockIdentifier: BlockIdentifier): Promise<BigNumberish>;
1748
+ getStorageAt(contractAddress: string, key: BigNumberish, blockIdentifier?: BlockIdentifier): Promise<BigNumberish>;
1747
1749
  getTransaction(txHash: BigNumberish): Promise<GetTransactionResponse>;
1748
1750
  getTransactionReceipt(txHash: BigNumberish): Promise<GetTransactionReceiptResponse>;
1749
1751
  callContract(request: Call, blockIdentifier?: BlockIdentifier): Promise<CallContractResponse>;
@@ -2008,10 +2010,12 @@ declare abstract class AccountInterface extends ProviderInterface {
2008
2010
  /**
2009
2011
  * Estimate Fee for executing a DEPLOY_ACCOUNT transaction on starknet
2010
2012
  *
2011
- * @param contractPayload the payload object containing:
2013
+ * @param contractPayload -
2012
2014
  * - contract - the compiled contract to be deployed
2013
2015
  * - classHash - the class hash of the compiled contract. This can be obtained by using starknet-cli.
2014
- *
2016
+ * @param estimateFeeDetails -
2017
+ * - optional blockIdentifier
2018
+ * - constant nonce = 0
2015
2019
  * @returns response from estimate_fee
2016
2020
  */
2017
2021
  abstract estimateAccountDeployFee(contractPayload: DeployAccountContractPayload, estimateFeeDetails?: EstimateFeeDetails): Promise<EstimateFeeResponse>;
@@ -2138,7 +2142,7 @@ declare abstract class AccountInterface extends ProviderInterface {
2138
2142
  - optional address salt
2139
2143
  - optional contractAddress
2140
2144
  * @param transactionsDetail Invocation Details containing:
2141
- - optional nonce
2145
+ - constant nonce = 0
2142
2146
  - optional version
2143
2147
  - optional maxFee
2144
2148
  * @returns a confirmation of sending a transaction on the starknet contract
@@ -2208,7 +2212,7 @@ declare class Account extends Provider implements AccountInterface {
2208
2212
  estimateFee(calls: AllowArray<Call>, estimateFeeDetails?: EstimateFeeDetails | undefined): Promise<EstimateFee>;
2209
2213
  estimateInvokeFee(calls: AllowArray<Call>, { nonce: providedNonce, blockIdentifier }?: EstimateFeeDetails): Promise<EstimateFee>;
2210
2214
  estimateDeclareFee({ classHash, contract }: DeclareContractPayload, { blockIdentifier, nonce: providedNonce }?: EstimateFeeDetails): Promise<EstimateFee>;
2211
- estimateAccountDeployFee({ classHash, addressSalt, constructorCalldata, contractAddress: providedContractAddress, }: DeployAccountContractPayload, { blockIdentifier, nonce: providedNonce }?: EstimateFeeDetails): Promise<EstimateFee>;
2215
+ estimateAccountDeployFee({ classHash, addressSalt, constructorCalldata, contractAddress: providedContractAddress, }: DeployAccountContractPayload, { blockIdentifier }?: EstimateFeeDetails): Promise<EstimateFee>;
2212
2216
  estimateDeployFee(payload: UniversalDeployerContractPayload | UniversalDeployerContractPayload[], transactionsDetail?: InvocationsDetails | undefined): Promise<EstimateFee>;
2213
2217
  execute(calls: AllowArray<Call>, abis?: Abi[] | undefined, transactionsDetail?: InvocationsDetails): Promise<InvokeFunctionResponse>;
2214
2218
  declare({ classHash, contract }: DeclareContractPayload, transactionsDetail?: InvocationsDetails): Promise<DeclareContractResponse>;
@@ -2322,6 +2326,7 @@ declare class Contract implements ContractInterface {
2322
2326
  [name: string]: ContractFunction;
2323
2327
  };
2324
2328
  readonly [key: string]: AsyncContractFunction | any;
2329
+ private checkCalldata;
2325
2330
  /**
2326
2331
  * Contract class to handle contract methods
2327
2332
  *
@@ -2337,29 +2342,6 @@ declare class Contract implements ContractInterface {
2337
2342
  invoke(method: string, args?: Array<any>, options?: Overrides): Promise<InvokeFunctionResponse>;
2338
2343
  estimate(method: string, args?: Array<any>): Promise<EstimateFeeResponse>;
2339
2344
  populate(method: string, args?: Array<any>): Call;
2340
- /**
2341
- * Deep parse of the object that has been passed to the method
2342
- *
2343
- * @param struct - struct that needs to be calculated
2344
- * @return {number} - number of members for the given struct
2345
- */
2346
- private calculateStructMembers;
2347
- /**
2348
- * Validates if all arguments that are passed to the method are corresponding to the ones in the abi
2349
- *
2350
- * @param type - type of the method
2351
- * @param method - name of the method
2352
- * @param args - arguments that are passed to the method
2353
- */
2354
- protected validateMethodAndArgs(type: 'INVOKE' | 'CALL', method: string, args?: Array<any>): void;
2355
- /**
2356
- * Deep parse of the object that has been passed to the method
2357
- *
2358
- * @param element - element that needs to be parsed
2359
- * @param type - name of the method
2360
- * @return {string | string[]} - parsed arguments in format that contract is expecting
2361
- */
2362
- protected parseCalldataValue(element: ParsedStruct | BigNumberish | BigNumberish[], type: string): string | string[];
2363
2345
  /**
2364
2346
  * Parse of the response elements that are converted to Object (Struct) by using the abi
2365
2347
  *
@@ -2368,22 +2350,6 @@ declare class Contract implements ContractInterface {
2368
2350
  * @return {BigNumberish | ParsedStruct} - parsed arguments in format that contract is expecting
2369
2351
  */
2370
2352
  protected parseResponseStruct(responseIterator: Iterator<string>, type: string): BigNumberish | ParsedStruct;
2371
- /**
2372
- * Parse one field of the calldata by using input field from the abi for that method
2373
- *
2374
- * @param args - value of the field
2375
- * @param input - input(field) information from the abi that will be used to parse the data
2376
- * @return {string | string[]} - parsed arguments in format that contract is expecting
2377
- */
2378
- protected parseCalldataField(argsIterator: Iterator<any>, input: AbiEntry): string | string[];
2379
- /**
2380
- * Parse the calldata by using input fields from the abi for that method
2381
- *
2382
- * @param args - arguments passed the the method
2383
- * @param inputs - list of inputs(fields) that are in the abi
2384
- * @return {Calldata} - parsed arguments in format that contract is expecting
2385
- */
2386
- protected compileCalldata(args: Array<any>, inputs: AbiEntry[]): Calldata;
2387
2353
  /**
2388
2354
  * Parse elements of the response and structuring them into one field by using output property from the abi for that method
2389
2355
  *
@@ -2407,15 +2373,16 @@ declare class ContractFactory {
2407
2373
  compiledContract: CompiledContract;
2408
2374
  classHash: string;
2409
2375
  account: AccountInterface;
2376
+ private checkCalldata;
2410
2377
  constructor(compiledContract: CompiledContract, classHash: string, account: AccountInterface, abi?: Abi);
2411
2378
  /**
2412
2379
  * Deploys contract and returns new instance of the Contract
2413
2380
  *
2414
- * @param constructorCalldata - Constructor Calldata
2381
+ * @param args - Array of the constructor arguments for deployment
2415
2382
  * @param addressSalt (optional) - Address Salt for deployment
2416
2383
  * @returns deployed Contract
2417
2384
  */
2418
- deploy(constructorCalldata?: RawArgs, addressSalt?: string | undefined): Promise<Contract>;
2385
+ deploy(args?: Array<any>, addressSalt?: string | undefined): Promise<Contract>;
2419
2386
  /**
2420
2387
  * Attaches to new Provider or Account
2421
2388
  *