Repository: 0xs34n/starknet.js
Pull request #463 (2022-12-16 17:31:38)

V5/refactor 1
## Motivation and Resolution
Fix https://github.com/0xs34n/starknet.js/issues/433

### RPC version (if applicable)

...

## Usage related changes

<!-- How the changes from this PR affect users. -->

- Change 1.
- ...

## Development related changes

<!-- How these changes affect the developers of this project - e.g. changes in testing or CI/CD. -->

- Change 1.
- ...

## Checklist:

- [ ] Performed a self-review of the code
- [ ] Rebased to the last commit of the target branch (or merged it into my branch)
- [ ] Linked the issues which this PR resolves
- [ ] Documented the changes
- [ ] Updated the docs (www)
- [ ] Updated the tests
- [ ] All tests are passing



Patch:
diff --git a/package-lock.json b/package-lock.json
index 918d2e6d..830e6e78 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -1743,6 +1743,7 @@
       "integrity": "sha512-ooWCrlZP11i8GImSjTHYHLkvFDP48nS4+204nGb1RiX/WXYHmJA2III9/e2DWVabCESdW7hBAEzHRqUn9OUVvQ==",
       "dev": true,
       "optional": true,
+      "peer": true,
       "engines": {
         "node": ">=0.1.90"
       }
@@ -5104,6 +5105,7 @@
       "resolved": "https://registry.npmjs.org/cli-table3/-/cli-table3-0.6.3.tgz",
       "integrity": "sha512-w5Jac5SykAeZJKntOxJCrm63Eg5/4dhMWIcuTbo9rpE+brgaSZo0RuNJZeOyMgsUdhDeojvgyQLmjI+K50ZGyg==",
       "dev": true,
+      "peer": true,
       "dependencies": {
         "string-width": "^4.2.0"
       },
@@ -5118,13 +5120,15 @@
       "version": "8.0.0",
       "resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-8.0.0.tgz",
       "integrity": "sha512-MSjYzcWNOA0ewAHpz0MxpYFvwg6yjy1NG3xteoqz644VCo/RPgnr1/GGt+ic3iJTzQ8Eu3TdM14SawnVUmGE6A==",
-      "dev": true
+      "dev": true,
+      "peer": true
     },
     "node_modules/cli-table3/node_modules/is-fullwidth-code-point": {
       "version": "3.0.0",
       "resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-3.0.0.tgz",
       "integrity": "sha512-zymm5+u+sCsSWyD9qNaejV3DFvhCKclKdizYaJUuHA83RLjb7nSuGnddCHGv0hk+KY7BMAlsWeK4Ueg6EV6XQg==",
       "dev": true,
+      "peer": true,
       "engines": {
         "node": ">=8"
       }
@@ -5134,6 +5138,7 @@
       "resolved": "https://registry.npmjs.org/string-width/-/string-width-4.2.3.tgz",
       "integrity": "sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==",
       "dev": true,
+      "peer": true,
       "dependencies": {
         "emoji-regex": "^8.0.0",
         "is-fullwidth-code-point": "^3.0.0",
@@ -18685,7 +18690,8 @@
       "resolved": "https://registry.npmjs.org/@colors/colors/-/colors-1.5.0.tgz",
       "integrity": "sha512-ooWCrlZP11i8GImSjTHYHLkvFDP48nS4+204nGb1RiX/WXYHmJA2III9/e2DWVabCESdW7hBAEzHRqUn9OUVvQ==",
       "dev": true,
-      "optional": true
+      "optional": true,
+      "peer": true
     },
     "@commitlint/cli": {
       "version": "17.4.2",
@@ -21201,6 +21207,7 @@
       "resolved": "https://registry.npmjs.org/cli-table3/-/cli-table3-0.6.3.tgz",
       "integrity": "sha512-w5Jac5SykAeZJKntOxJCrm63Eg5/4dhMWIcuTbo9rpE+brgaSZo0RuNJZeOyMgsUdhDeojvgyQLmjI+K50ZGyg==",
       "dev": true,
+      "peer": true,
       "requires": {
         "@colors/colors": "1.5.0",
         "string-width": "^4.2.0"
@@ -21210,19 +21217,22 @@
           "version": "8.0.0",
           "resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-8.0.0.tgz",
           "integrity": "sha512-MSjYzcWNOA0ewAHpz0MxpYFvwg6yjy1NG3xteoqz644VCo/RPgnr1/GGt+ic3iJTzQ8Eu3TdM14SawnVUmGE6A==",
-          "dev": true
+          "dev": true,
+          "peer": true
         },
         "is-fullwidth-code-point": {
           "version": "3.0.0",
           "resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-3.0.0.tgz",
           "integrity": "sha512-zymm5+u+sCsSWyD9qNaejV3DFvhCKclKdizYaJUuHA83RLjb7nSuGnddCHGv0hk+KY7BMAlsWeK4Ueg6EV6XQg==",
-          "dev": true
+          "dev": true,
+          "peer": true
         },
         "string-width": {
           "version": "4.2.3",
           "resolved": "https://registry.npmjs.org/string-width/-/string-width-4.2.3.tgz",
           "integrity": "sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==",
           "dev": true,
+          "peer": true,
           "requires": {
             "emoji-regex": "^8.0.0",
             "is-fullwidth-code-point": "^3.0.0",
diff --git a/src/account/default.ts b/src/account/default.ts
index fb96c760..21f42b7f 100644
--- a/src/account/default.ts
+++ b/src/account/default.ts
@@ -26,6 +26,8 @@ import {
   MultiDeployContractResponse,
   Signature,
   TransactionBulk,
+  TransactionStatus,
+  TransactionType,
   UniversalDeployerContractPayload,
 } from '../types';
 import { EstimateFeeBulk, TransactionSimulation } from '../types/account';
@@ -111,13 +113,6 @@ export class Account extends Provider implements AccountInterface {
     }
   }
 
-  public async estimateFee(
-    calls: AllowArray<Call>,
-    estimateFeeDetails?: EstimateFeeDetails | undefined
-  ): Promise<EstimateFee> {
-    return this.estimateInvokeFee(calls, estimateFeeDetails);
-  }
-
   public async estimateInvokeFee(
     calls: AllowArray<Call>,
     { nonce: providedNonce, blockIdentifier }: EstimateFeeDetails = {}
@@ -315,7 +310,10 @@ export class Account extends Provider implements AccountInterface {
     const nonce = toBigInt(transactionsDetail.nonce ?? (await this.getNonce()));
     const maxFee =
       transactionsDetail.maxFee ??
-      (await this.getSuggestedMaxFee({ type: 'INVOKE', payload: calls }, transactionsDetail));
+      (await this.getSuggestedMaxFee(
+        { type: TransactionType.INVOKE, payload: calls },
+        transactionsDetail
+      ));
     const version = toBigInt(transactionVersion);
     const chainId = await this.getChainId();
 
@@ -352,7 +350,7 @@ export class Account extends Provider implements AccountInterface {
     const maxFee =
       transactionsDetail.maxFee ??
       (await this.getSuggestedMaxFee(
-        { type: 'DECLARE', payload: { classHash, contract } }, // Provide the classHash to avoid re-computing it
+        { type: TransactionType.DECLARE, payload: { classHash, contract } }, // Provide the classHash to avoid re-computing it
         transactionsDetail
       ));
 
@@ -431,9 +429,9 @@ export class Account extends Provider implements AccountInterface {
     details?: InvocationsDetails | undefined
   ): Promise<DeployContractUDCResponse> {
     const deployTx = await this.deploy(payload, details);
-    const txReceipt = await this.waitForTransaction(deployTx.transaction_hash, undefined, [
-      'ACCEPTED_ON_L2',
-    ]);
+    const txReceipt = await this.waitForTransaction(deployTx.transaction_hash, {
+      successStates: [TransactionStatus.ACCEPTED_ON_L2],
+    });
     return parseUDCEvent(txReceipt);
   }
 
@@ -443,7 +441,9 @@ export class Account extends Provider implements AccountInterface {
   ): Promise<DeclareDeployUDCResponse> {
     const { contract, constructorCalldata, salt, unique } = payload;
     const { transaction_hash, class_hash } = await this.declare({ contract }, details);
-    const declare = await this.waitForTransaction(transaction_hash, undefined, ['ACCEPTED_ON_L2']);
+    const declare = await this.waitForTransaction(transaction_hash, {
+      successStates: [TransactionStatus.ACCEPTED_ON_L2],
+    });
     const deploy = await this.deployContract(
       { classHash: class_hash, salt, unique, constructorCalldata },
       details
@@ -472,7 +472,7 @@ export class Account extends Provider implements AccountInterface {
       transactionsDetail.maxFee ??
       (await this.getSuggestedMaxFee(
         {
-          type: 'DEPLOY_ACCOUNT',
+          type: TransactionType.DEPLOY_ACCOUNT,
           payload: { classHash, constructorCalldata, addressSalt, contractAddress },
         },
         transactionsDetail
@@ -535,19 +535,19 @@ export class Account extends Provider implements AccountInterface {
     let feeEstimate: EstimateFee;
 
     switch (type) {
-      case 'INVOKE':
+      case TransactionType.INVOKE:
         feeEstimate = await this.estimateInvokeFee(payload, details);
         break;
 
-      case 'DECLARE':
+      case TransactionType.DECLARE:
         feeEstimate = await this.estimateDeclareFee(payload, details);
         break;
 
-      case 'DEPLOY_ACCOUNT':
+      case TransactionType.DEPLOY_ACCOUNT:
         feeEstimate = await this.estimateAccountDeployFee(payload, details);
         break;
 
-      case 'DEPLOY':
+      case TransactionType.DEPLOY:
         feeEstimate = await this.estimateDeployFee(payload, details);
         break;
 
diff --git a/src/account/interface.ts b/src/account/interface.ts
index 8e4f40e5..2fd8ea0f 100644
--- a/src/account/interface.ts
+++ b/src/account/interface.ts
@@ -32,22 +32,6 @@ export abstract class AccountInterface extends ProviderInterface {
 
   public abstract signer: SignerInterface;
 
-  /**
-   * @deprecated Use estimateInvokeFee or estimateDeclareFee instead
-   * Estimate Fee for executing an INVOKE transaction on starknet
-   *
-   * @param calls the invocation object containing:
-   * - contractAddress - the address of the contract
-   * - entrypoint - the entrypoint of the contract
-   * - calldata - (defaults to []) the calldata
-   *
-   * @returns response from estimate_fee
-   */
-  public abstract estimateFee(
-    calls: AllowArray<Call>,
-    estimateFeeDetails?: EstimateFeeDetails
-  ): Promise<EstimateFeeResponse>;
-
   /**
    * Estimate Fee for executing an INVOKE transaction on starknet
    *
diff --git a/src/constants.ts b/src/constants.ts
index f4f1012c..df2ac851 100644
--- a/src/constants.ts
+++ b/src/constants.ts
@@ -5,11 +5,24 @@ export const MASK_250 = 2n ** 250n - 1n; // 2 ** 250 - 1
 export const MASK_251 = 2n ** 251n;
 export const API_VERSION = ZERO;
 
+export enum BaseUrl {
+  SN_MAIN = 'https://alpha-mainnet.starknet.io',
+  SN_GOERLI = 'https://alpha4.starknet.io',
+  SN_GOERLI2 = 'https://alpha4-2.starknet.io',
+}
+
+export enum NetworkName {
+  SN_MAIN = 'SN_MAIN',
+  SN_GOERLI = 'SN_GOERLI',
+  SN_GOERLI2 = 'SN_GOERLI2',
+}
+
 export enum StarknetChainId {
-  MAINNET = '0x534e5f4d41494e', // encodeShortString('SN_MAIN'),
-  TESTNET = '0x534e5f474f45524c49', // encodeShortString('SN_GOERLI'),
-  TESTNET2 = '0x534e5f474f45524c4932',
+  SN_MAIN = '0x534e5f4d41494e', // encodeShortString('SN_MAIN'),
+  SN_GOERLI = '0x534e5f474f45524c49', // encodeShortString('SN_GOERLI'),
+  SN_GOERLI2 = '0x534e5f474f45524c4932', // encodeShortString('SN_GOERLI2'),
 }
+
 export enum TransactionHashPrefix {
   DECLARE = '0x6465636c617265', // encodeShortString('declare'),
   DEPLOY = '0x6465706c6f79', // encodeShortString('deploy'),
diff --git a/src/provider/default.ts b/src/provider/default.ts
index 2e2a6fa7..bb6f879b 100644
--- a/src/provider/default.ts
+++ b/src/provider/default.ts
@@ -17,8 +17,8 @@ import {
   InvocationBulk,
   InvocationsDetailsWithNonce,
   InvokeFunctionResponse,
-  Status,
   TransactionSimulationResponse,
+  waitForTransactionOptions,
 } from '../types';
 import { BigNumberish } from '../utils/number';
 import { ProviderInterface } from './interface';
@@ -185,10 +185,9 @@ export class Provider implements ProviderInterface {
 
   public async waitForTransaction(
     txHash: BigNumberish,
-    retryInterval?: number,
-    successStates?: Array<Status>
+    options: waitForTransactionOptions
   ): Promise<GetTransactionReceiptResponse> {
-    return this.provider.waitForTransaction(txHash, retryInterval, successStates);
+    return this.provider.waitForTransaction(txHash, options);
   }
 
   public async getSimulateTransaction(
diff --git a/src/provider/interface.ts b/src/provider/interface.ts
index 94120cc7..7e169d47 100644
--- a/src/provider/interface.ts
+++ b/src/provider/interface.ts
@@ -18,8 +18,8 @@ import type {
   InvocationBulk,
   InvocationsDetailsWithNonce,
   InvokeFunctionResponse,
-  Status,
   TransactionSimulationResponse,
+  waitForTransactionOptions,
 } from '../types';
 import type { BigNumberish } from '../utils/number';
 import { BlockIdentifier } from './utils';
@@ -293,8 +293,7 @@ export abstract class ProviderInterface {
    */
   public abstract waitForTransaction(
     txHash: BigNumberish,
-    retryInterval?: number,
-    successStates?: Array<Status>
+    options?: waitForTransactionOptions
   ): Promise<GetTransactionReceiptResponse>;
 
   /**
diff --git a/src/provider/rpc.ts b/src/provider/rpc.ts
index cdb7f691..efd4c889 100644
--- a/src/provider/rpc.ts
+++ b/src/provider/rpc.ts
@@ -17,6 +17,8 @@ import {
   InvokeFunctionResponse,
   RPC,
   TransactionSimulationResponse,
+  TransactionStatus,
+  waitForTransactionOptions,
 } from '../types';
 import fetch from '../utils/fetchPonyfill';
 import { getSelectorFromName } from '../utils/hash';
@@ -247,7 +249,7 @@ export class RpcProvider implements ProviderInterface {
     const block_id = new Block(blockIdentifier).identifier;
     return this.fetchEndpoint('starknet_estimateFee', {
       request: {
-        type: 'INVOKE',
+        type: RPC.TransactionType.INVOKE,
         sender_address: invocation.contractAddress,
         calldata: parseCalldata(invocation.calldata),
         signature: signatureToHexArray(invocation.signature),
@@ -259,8 +261,6 @@ export class RpcProvider implements ProviderInterface {
     }).then(this.responseParser.parseFeeEstimateResponse);
   }
 
-  // TODO: Revisit after Pathfinder release with JSON-RPC v0.2.1 RPC Spec
-
   public async getDeclareEstimateFee(
     { senderAddress, contractDefinition, signature }: DeclareContractTransaction,
     details: InvocationsDetailsWithNonce,
@@ -269,7 +269,7 @@ export class RpcProvider implements ProviderInterface {
     const block_id = new Block(blockIdentifier).identifier;
     return this.fetchEndpoint('starknet_estimateFee', {
       request: {
-        type: 'DECLARE',
+        type: RPC.TransactionType.DECLARE,
         contract_class: {
           program: contractDefinition.program,
           entry_points_by_type: contractDefinition.entry_points_by_type,
@@ -293,7 +293,7 @@ export class RpcProvider implements ProviderInterface {
     const block_id = new Block(blockIdentifier).identifier;
     return this.fetchEndpoint('starknet_estimateFee', {
       request: {
-        type: 'DEPLOY_ACCOUNT',
+        type: RPC.TransactionType.DEPLOY_ACCOUNT,
         constructor_calldata: bigNumberishArrayToHexadecimalStringArray(constructorCalldata || []),
         class_hash: toHex(classHash),
         contract_address_salt: toHex(addressSalt || 0),
@@ -325,7 +325,7 @@ export class RpcProvider implements ProviderInterface {
           entry_points_by_type: contractDefinition.entry_points_by_type,
           abi: contractDefinition.abi, // rpc 2.0
         },
-        type: 'DECLARE',
+        type: RPC.TransactionType.DECLARE,
         version: toHex(details.version || 0),
         max_fee: toHex(details.maxFee || 0),
         signature: signatureToHexArray(signature),
@@ -344,7 +344,7 @@ export class RpcProvider implements ProviderInterface {
         constructor_calldata: bigNumberishArrayToHexadecimalStringArray(constructorCalldata || []),
         class_hash: toHex(classHash),
         contract_address_salt: toHex(addressSalt || 0),
-        type: 'DEPLOY_ACCOUNT',
+        type: RPC.TransactionType.DEPLOY_ACCOUNT,
         max_fee: toHex(details.maxFee || 0),
         version: toHex(details.version || 0),
         signature: signatureToHexArray(signature),
@@ -361,7 +361,7 @@ export class RpcProvider implements ProviderInterface {
       invoke_transaction: {
         sender_address: functionInvocation.contractAddress,
         calldata: parseCalldata(functionInvocation.calldata),
-        type: 'INVOKE',
+        type: RPC.TransactionType.INVOKE,
         max_fee: toHex(details.maxFee || 0),
         version: toHex(details.version || 1),
         signature: signatureToHexArray(functionInvocation.signature),
@@ -396,16 +396,19 @@ export class RpcProvider implements ProviderInterface {
     return this.fetchEndpoint('starknet_traceBlockTransactions', { block_hash: blockHash });
   }
 
-  public async waitForTransaction(
-    txHash: string,
-    retryInterval: number = 8000,
-    successStates = ['ACCEPTED_ON_L1', 'ACCEPTED_ON_L2', 'PENDING']
-  ) {
-    const errorStates = ['REJECTED', 'NOT_RECEIVED'];
+  public async waitForTransaction(txHash: string, options?: waitForTransactionOptions) {
+    const errorStates = [TransactionStatus.RECEIVED, TransactionStatus.NOT_RECEIVED];
     let { retries } = this;
     let onchain = false;
     let txReceipt: any = {};
 
+    const retryInterval = options?.retryInterval ?? 8000;
+    const successStates = options?.successStates ?? [
+      TransactionStatus.ACCEPTED_ON_L1,
+      TransactionStatus.ACCEPTED_ON_L2,
+      TransactionStatus.PENDING,
+    ];
+
     while (!onchain) {
       // eslint-disable-next-line no-await-in-loop
       await wait(retryInterval);
@@ -427,7 +430,7 @@ export class RpcProvider implements ProviderInterface {
           throw error;
         }
       } catch (error: unknown) {
-        if (error instanceof Error && errorStates.includes(error.message)) {
+        if (error instanceof Error && errorStates.includes(error.message as TransactionStatus)) {
           throw error;
         }
 
diff --git a/src/provider/sequencer.ts b/src/provider/sequencer.ts
index 1733db5d..d49a1a00 100644
--- a/src/provider/sequencer.ts
+++ b/src/provider/sequencer.ts
@@ -1,6 +1,6 @@
 import urljoin from 'url-join';
 
-import { StarknetChainId } from '../constants';
+import { BaseUrl, NetworkName, StarknetChainId } from '../constants';
 import {
   Call,
   CallContractResponse,
@@ -23,7 +23,10 @@ import {
   InvokeFunctionResponse,
   Sequencer,
   TransactionSimulationResponse,
+  TransactionStatus,
   TransactionTraceResponse,
+  TransactionType,
+  waitForTransactionOptions,
 } from '../types';
 import fetch from '../utils/fetchPonyfill';
 import { getSelector, getSelectorFromName } from '../utils/hash';
@@ -45,7 +48,6 @@ import { GatewayError, HttpError, LibraryError } from './errors';
 import { ProviderInterface } from './interface';
 import { Block, BlockIdentifier } from './utils';
 
-export type NetworkName = 'mainnet-alpha' | 'goerli-alpha' | 'goerli-alpha-2';
 export type SequencerHttpMethod = 'POST' | 'GET';
 
 export type SequencerProviderOptions = {
@@ -74,7 +76,7 @@ function isEmptyQueryObject(obj?: Record<any, any>): obj is undefined {
 }
 
 const defaultOptions = {
-  network: 'goerli-alpha-2' as NetworkName,
+  network: NetworkName.SN_GOERLI2,
   blockIdentifier: 'pending',
 };
 
@@ -115,14 +117,14 @@ export class SequencerProvider implements ProviderInterface {
 
   protected static getNetworkFromName(name: NetworkName | StarknetChainId) {
     switch (name) {
-      case 'mainnet-alpha' || StarknetChainId.MAINNET:
-        return 'https://alpha-mainnet.starknet.io';
-      case 'goerli-alpha' || StarknetChainId.TESTNET:
-        return 'https://alpha4.starknet.io';
-      case 'goerli-alpha-2' || StarknetChainId.TESTNET2:
-        return 'https://alpha4-2.starknet.io';
+      case NetworkName.SN_MAIN || StarknetChainId.SN_MAIN:
+        return BaseUrl.SN_MAIN;
+      case NetworkName.SN_GOERLI || StarknetChainId.SN_GOERLI:
+        return BaseUrl.SN_GOERLI;
+      case NetworkName.SN_GOERLI2 || StarknetChainId.SN_GOERLI2:
+        return BaseUrl.SN_GOERLI2;
       default:
-        return 'https://alpha4.starknet.io';
+        throw new Error('Could not detect base url from NetworkName');
     }
   }
 
@@ -130,21 +132,21 @@ export class SequencerProvider implements ProviderInterface {
     try {
       const url = new URL(baseUrl);
       if (url.host.includes('mainnet.starknet.io')) {
-        return StarknetChainId.MAINNET;
+        return StarknetChainId.SN_MAIN;
       }
       if (url.host.includes('alpha4-2.starknet.io')) {
-        return StarknetChainId.TESTNET2;
+        return StarknetChainId.SN_GOERLI2;
       }
+      return StarknetChainId.SN_GOERLI;
     } catch {
       // eslint-disable-next-line no-console
       console.error(`Could not parse baseUrl: ${baseUrl}`);
+      return StarknetChainId.SN_GOERLI;
     }
-    return StarknetChainId.TESTNET;
   }
 
   private getFetchUrl(endpoint: keyof Sequencer.Endpoints) {
     const gatewayUrlEndpoints = ['add_transaction'];
-
     return gatewayUrlEndpoints.includes(endpoint) ? this.gatewayUrl : this.feederGatewayUrl;
   }
 
@@ -341,7 +343,7 @@ export class SequencerProvider implements ProviderInterface {
     details: InvocationsDetailsWithNonce
   ): Promise<InvokeFunctionResponse> {
     return this.fetchEndpoint('add_transaction', undefined, {
-      type: 'INVOKE_FUNCTION',
+      type: TransactionType.INVOKE,
       contract_address: functionInvocation.contractAddress,
       calldata: bigNumberishArrayToDecimalStringArray(functionInvocation.calldata ?? []),
       signature: signatureToDecimalArray(functionInvocation.signature),
@@ -356,7 +358,7 @@ export class SequencerProvider implements ProviderInterface {
     details: InvocationsDetailsWithNonce
   ): Promise<DeployContractResponse> {
     return this.fetchEndpoint('add_transaction', undefined, {
-      type: 'DEPLOY_ACCOUNT',
+      type: TransactionType.DEPLOY_ACCOUNT,
       contract_address_salt: addressSalt ?? randomAddress(),
       constructor_calldata: bigNumberishArrayToDecimalStringArray(constructorCalldata ?? []),
       class_hash: toHex(classHash),
@@ -372,7 +374,7 @@ export class SequencerProvider implements ProviderInterface {
     details: InvocationsDetailsWithNonce
   ): Promise<DeclareContractResponse> {
     return this.fetchEndpoint('add_transaction', undefined, {
-      type: 'DECLARE',
+      type: TransactionType.DECLARE,
       contract_class: contractDefinition,
       nonce: toHex(details.nonce),
       signature: signatureToDecimalArray(signature),
@@ -399,7 +401,7 @@ export class SequencerProvider implements ProviderInterface {
       'estimate_fee',
       { blockIdentifier },
       {
-        type: 'INVOKE_FUNCTION',
+        type: TransactionType.INVOKE,
         contract_address: invocation.contractAddress,
         calldata: invocation.calldata ?? [],
         signature: signatureToDecimalArray(invocation.signature),
@@ -418,7 +420,7 @@ export class SequencerProvider implements ProviderInterface {
       'estimate_fee',
       { blockIdentifier },
       {
-        type: 'DECLARE',
+        type: TransactionType.DECLARE,
         sender_address: senderAddress,
         contract_class: contractDefinition,
         signature: signatureToDecimalArray(signature),
@@ -437,7 +439,7 @@ export class SequencerProvider implements ProviderInterface {
       'estimate_fee',
       { blockIdentifier },
       {
-        type: 'DEPLOY_ACCOUNT',
+        type: TransactionType.DEPLOY_ACCOUNT,
         class_hash: toHex(classHash),
         constructor_calldata: bigNumberishArrayToDecimalStringArray(constructorCalldata || []),
         contract_address_salt: toHex(addressSalt || 0),
@@ -496,14 +498,16 @@ export class SequencerProvider implements ProviderInterface {
     return this.fetchEndpoint('get_code', { contractAddress, blockIdentifier });
   }
 
-  public async waitForTransaction(
-    txHash: BigNumberish,
-    retryInterval: number = 8000,
-    successStates = ['ACCEPTED_ON_L1', 'ACCEPTED_ON_L2', 'PENDING']
-  ) {
-    const errorStates = ['REJECTED', 'NOT_RECEIVED'];
+  public async waitForTransaction(txHash: BigNumberish, options?: waitForTransactionOptions) {
+    const errorStates = [TransactionStatus.RECEIVED, TransactionStatus.NOT_RECEIVED];
     let onchain = false;
     let res;
+    const retryInterval = options?.retryInterval ?? 8000;
+    const successStates = options?.successStates ?? [
+      TransactionStatus.ACCEPTED_ON_L1,
+      TransactionStatus.ACCEPTED_ON_L2,
+      TransactionStatus.PENDING,
+    ];
 
     while (!onchain) {
       // eslint-disable-next-line no-await-in-loop
diff --git a/src/types/api/openrpc.ts b/src/types/api/openrpc.ts
index a88f4849..f1a0d7ff 100644
--- a/src/types/api/openrpc.ts
+++ b/src/types/api/openrpc.ts
@@ -17,7 +17,7 @@ type BLOCK_NUMBER = number;
 type BLOCK_HASH = FELT;
 type TXN_HASH = FELT;
 type TXN_STATUS = 'PENDING' | 'ACCEPTED_ON_L2' | 'ACCEPTED_ON_L1' | 'REJECTED';
-type TXN_TYPE = 'DECLARE' | 'DEPLOY' | 'DEPLOY_ACCOUNT' | 'INVOKE' | 'L1_HANDLER';
+export type TXN_TYPE = 'DECLARE' | 'DEPLOY' | 'DEPLOY_ACCOUNT' | 'INVOKE' | 'L1_HANDLER';
 type BLOCK_STATUS = 'PENDING' | 'ACCEPTED_ON_L2' | 'ACCEPTED_ON_L1' | 'REJECTED';
 enum BLOCK_TAG {
   'latest',
diff --git a/src/types/api/rpc.ts b/src/types/api/rpc.ts
index 9f7a2869..553c3fa0 100644
--- a/src/types/api/rpc.ts
+++ b/src/types/api/rpc.ts
@@ -42,4 +42,13 @@ export namespace RPC {
   export type DeclaredTransaction = OPENRPC.DeclaredTransaction;
   export type DeployedTransaction = OPENRPC.DeployedTransaction;
   export type Methods = OPENRPC.Methods;
+
+  // 'DECLARE' | 'DEPLOY' | 'DEPLOY_ACCOUNT' | 'INVOKE' | 'L1_HANDLER'
+  export enum TransactionType {
+    DECLARE = 'DECLARE',
+    DEPLOY = 'DEPLOY',
+    DEPLOY_ACCOUNT = 'DEPLOY_ACCOUNT',
+    INVOKE = 'INVOKE',
+    L1_HANDLER = 'L1_HANDLER',
+  }
 }
diff --git a/src/types/api/sequencer.ts b/src/types/api/sequencer.ts
index 01be59c7..c47452c5 100644
--- a/src/types/api/sequencer.ts
+++ b/src/types/api/sequencer.ts
@@ -12,7 +12,7 @@ import {
 } from '../lib';
 
 export type GetTransactionStatusResponse = {
-  tx_status: Status;
+  tx_status: TransactionStatus;
   block_hash?: string;
   tx_failure_reason?: {
     code: string;
@@ -116,7 +116,7 @@ export namespace Sequencer {
 
   export type AddTransactionResponse = {
     transaction_hash: string;
-    code?: TransactionStatus;
+    code?: 'TRANSACTION_RECEIVED';
     address?: string;
     class_hash?: string;
   };
diff --git a/src/types/lib.ts b/src/types/lib.ts
index abe90356..d892dd81 100644
--- a/src/types/lib.ts
+++ b/src/types/lib.ts
@@ -82,6 +82,14 @@ export type InvocationsDetails = {
 
 export type InvocationsDetailsWithNonce = InvocationsDetails & { nonce: BigNumberish };
 
+export enum TransactionStatus {
+  NOT_RECEIVED = 'NOT_RECEIVED',
+  RECEIVED = 'RECEIVED',
+  PENDING = 'PENDING',
+  ACCEPTED_ON_L2 = 'ACCEPTED_ON_L2',
+  ACCEPTED_ON_L1 = 'ACCEPTED_ON_L1',
+  REJECTED = 'REJECTED',
+}
 export type TransactionBulk = Array<
   | ({ type: 'DECLARE' } & { payload: DeclareContractPayload })
   | ({ type: 'DEPLOY' } & {
@@ -107,8 +115,14 @@ export type Status =
   | 'ACCEPTED_ON_L2'
   | 'ACCEPTED_ON_L1'
   | 'REJECTED';
-export type TransactionStatus = 'TRANSACTION_RECEIVED';
-export type TransactionType = 'DECLARE' | 'DEPLOY' | 'INVOKE_FUNCTION' | 'DEPLOY_ACCOUNT';
+
+export enum TransactionType {
+  INVOKE = 'INVOKE_FUNCTION',
+  DECLARE = 'DECLARE',
+  DEPLOY = 'DEPLOY',
+  DEPLOY_ACCOUNT = 'DEPLOY_ACCOUNT',
+}
+
 export type EntryPointType = 'EXTERNAL';
 export type CompressedProgram = string;
 
@@ -177,3 +191,8 @@ export type Args = {
 export type ParsedStruct = {
   [key: string]: BigNumberish | ParsedStruct;
 };
+
+export type waitForTransactionOptions = {
+  retryInterval?: number;
+  successStates?: Array<TransactionStatus>;
+};
diff --git a/src/types/provider.ts b/src/types/provider.ts
index 5390bcf0..85e9ae3f 100644
--- a/src/types/provider.ts
+++ b/src/types/provider.ts
@@ -12,6 +12,7 @@ import {
   RawCalldata,
   Signature,
   Status,
+  TransactionType,
   UniversalDeployerContractPayload,
 } from './lib';
 
@@ -117,19 +118,19 @@ export type CallContractResponse = {
 
 export type EstimateFeeAction =
   | {
-      type: 'INVOKE';
+      type: TransactionType.INVOKE;
       payload: AllowArray<Call>;
     }
   | {
-      type: 'DECLARE';
+      type: TransactionType.DECLARE;
       payload: DeclareContractPayload;
     }
   | {
-      type: 'DEPLOY_ACCOUNT';
+      type: TransactionType.DEPLOY_ACCOUNT;
       payload: DeployAccountContractPayload;
     }
   | {
-      type: 'DEPLOY';
+      type: TransactionType.DEPLOY;
       payload: UniversalDeployerContractPayload;
     };
 
diff --git a/src/utils/starknetId.ts b/src/utils/starknetId.ts
index 750eb1f3..ddd1f324 100644
--- a/src/utils/starknetId.ts
+++ b/src/utils/starknetId.ts
@@ -102,10 +102,10 @@ export function getStarknetIdContract(chainId: StarknetChainId): string {
     '0x05cf267a0af6101667013fc6bd3f6c11116a14cda9b8c4b1198520d59f900b17';
 
   switch (chainId) {
-    case StarknetChainId.MAINNET:
+    case StarknetChainId.SN_MAIN:
       return starknetIdMainnetContract;
 
-    case StarknetChainId.TESTNET:
+    case StarknetChainId.SN_GOERLI:
       return starknetIdTestnetContract;
 
     default:
diff --git a/tsconfig.json b/tsconfig.json
index b2c54d96..787a6e40 100644
--- a/tsconfig.json
+++ b/tsconfig.json
@@ -14,7 +14,6 @@
     "target": "ES2020" /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */,
     "lib": [
       "ES2020",
-      "es2017",
       "es7",
       "es6",
       "dom"
diff --git a/www/docs/API/utils.md b/www/docs/API/utils.md
index 837ac064..872a4f9f 100644
--- a/www/docs/API/utils.md
+++ b/www/docs/API/utils.md
@@ -286,7 +286,7 @@ const hashMsg = calculcateTransactionHash(
   getSelectorFromName('__execute__'),
   calldata,
   maxFee,
-  StarknetChainId.TESTNET
+  StarknetChainId.SN_GOERLI
 );
 ```
 


Test patch:
diff --git a/__tests__/account.test.ts b/__tests__/account.test.ts
index adbe4334..89193eb3 100644
--- a/__tests__/account.test.ts
+++ b/__tests__/account.test.ts
@@ -1,5 +1,5 @@
 import typedDataExample from '../__mocks__/typedDataExample.json';
-import { Account, Contract, Provider, ec, number, stark } from '../src';
+import { Account, Contract, Provider, TransactionStatus, ec, number, stark } from '../src';
 import { parseUDCEvent } from '../src/utils/events';
 import { calculateContractAddressFromHash, feeTransactionVersion } from '../src/utils/hash';
 import { cleanHex, hexToDecimalString, toBigInt, toHex } from '../src/utils/number';
@@ -123,7 +123,9 @@ describe('deploy and test Wallet', () => {
       calldata: [erc20.address, '10', '0'],
     });
 
-    await provider.waitForTransaction(transaction_hash, undefined, ['ACCEPTED_ON_L2']);
+    await provider.waitForTransaction(transaction_hash, {
+      successStates: [TransactionStatus.ACCEPTED_ON_L2],
+    });
   });
 
   test('read balance of wallet after transfer', async () => {
@@ -162,7 +164,9 @@ describe('deploy and test Wallet', () => {
       },
     ]);
 
-    await provider.waitForTransaction(transaction_hash, undefined, ['ACCEPTED_ON_L2']);
+    await provider.waitForTransaction(transaction_hash, {
+      successStates: [TransactionStatus.ACCEPTED_ON_L2],
+    });
 
     const response = await dapp.get_number(account.address);
     expect(toBigInt(response.number as string).toString()).toStrictEqual('57');
diff --git a/__tests__/fixtures.ts b/__tests__/fixtures.ts
index 6601885d..7ed0cd89 100644
--- a/__tests__/fixtures.ts
+++ b/__tests__/fixtures.ts
@@ -2,7 +2,7 @@ import fs from 'fs';
 import path from 'path';
 
 import { Account, ProviderInterface, RpcProvider, SequencerProvider, json } from '../src';
-import { CompiledContract } from '../src/types';
+import { CompiledContract, waitForTransactionOptions } from '../src/types';
 import { toHex } from '../src/utils/number';
 
 const readContract = (name: string): CompiledContract =>
@@ -51,8 +51,11 @@ export const getTestProvider = (): ProviderInterface => {
   if (IS_LOCALHOST_DEVNET) {
     // accelerate the tests when running locally
     const originalWaitForTransaction = provider.waitForTransaction.bind(provider);
-    provider.waitForTransaction = (txHash: string, retryInterval?: number) => {
-      return originalWaitForTransaction(txHash, retryInterval || 1000);
+    provider.waitForTransaction = (
+      txHash: string,
+      { retryInterval }: waitForTransactionOptions = {}
+    ) => {
+      return originalWaitForTransaction(txHash, { retryInterval: retryInterval || 1000 });
     };
   }
 
diff --git a/__tests__/utils/ellipticalCurve.test.ts b/__tests__/utils/ellipticalCurve.test.ts
index 6aa11efb..f7c496c1 100644
--- a/__tests__/utils/ellipticalCurve.test.ts
+++ b/__tests__/utils/ellipticalCurve.test.ts
@@ -56,7 +56,7 @@ test('hashMessage()', () => {
     transactionVersion,
     calldata,
     maxFee,
-    StarknetChainId.TESTNET,
+    StarknetChainId.SN_GOERLI,
     nonce
   );
 
diff --git a/__tests__/utils/starknetId.test.ts b/__tests__/utils/starknetId.test.ts
index b4a50a7c..14762174 100644
--- a/__tests__/utils/starknetId.test.ts
+++ b/__tests__/utils/starknetId.test.ts
@@ -36,15 +36,15 @@ describe('Should tets StarknetId utils', () => {
   });
 
   test('Should test getStarknetIdContract', () => {
-    expect(getStarknetIdContract(StarknetChainId.TESTNET)).toBe(
+    expect(getStarknetIdContract(StarknetChainId.SN_GOERLI)).toBe(
       '0x05cf267a0af6101667013fc6bd3f6c11116a14cda9b8c4b1198520d59f900b17'
     );
 
     expect(() => {
-      getStarknetIdContract(StarknetChainId.TESTNET2);
+      getStarknetIdContract(StarknetChainId.SN_GOERLI2);
     }).toThrow();
 
-    expect(getStarknetIdContract(StarknetChainId.MAINNET)).toBe(
+    expect(getStarknetIdContract(StarknetChainId.SN_MAIN)).toBe(
       '0x6ac597f8116f886fa1c97a23fa4e08299975ecaf6b598873ca6792b9bbfb678'
     );
   });
diff --git a/__tests__/utils/transactionHash.test.ts b/__tests__/utils/transactionHash.test.ts
index 9363bed5..571205b9 100644
--- a/__tests__/utils/transactionHash.test.ts
+++ b/__tests__/utils/transactionHash.test.ts
@@ -10,7 +10,7 @@ describe('calculateTransactionHashCommon()', () => {
       '0x64',
       [],
       '0x0',
-      StarknetChainId.TESTNET
+      StarknetChainId.SN_GOERLI
     );
     expect(result).toBe('0x7d260744de9d8c55e7675a34512d1951a7b262c79e685d26599edd2948de959');
   });