Skip to content

Commit

Permalink
Update web3-utils to 1.4.6 and fix chainId constants (#513)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ben-Rey authored Dec 29, 2023
1 parent 1a4575a commit 2b2d4ee
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 8 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/web3-utils/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@massalabs/web3-utils",
"version": "1.4.5",
"version": "1.4.6",
"description": "Set of utilities shared between multiple @massalabs packages",
"main": "dist/cmd/index.js",
"module": "dist/esm/index.js",
Expand Down
34 changes: 28 additions & 6 deletions packages/web3-utils/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,32 @@ export const SECURENET = 'SecureNet';
export const LABNET = 'LabNet';
export const SANDBOX = 'Sandbox';

export const MAINNET_CHAIN_ID = 77658377n;
export const BUILDNET_CHAIN_ID = 77658366n;
export const SECURENET_CHAIN_ID = 77658383n;
export const LABNET_CHAIN_ID = 77658376n;
export const SANDBOX_CHAIN_ID = 77n;

// Adjusted: Use the values of the constants as keys
export const CHAIN_ID_TO_NETWORK_NAME = {
77658377: MAINNET,
77658366: BUILDNET,
77658383: SECURENET,
77658376: LABNET,
77: SANDBOX,
} as const; // type is inferred as the specific, unchangeable structure
[MAINNET_CHAIN_ID.toString()]: MAINNET,
[BUILDNET_CHAIN_ID.toString()]: BUILDNET,
[SECURENET_CHAIN_ID.toString()]: SECURENET,
[LABNET_CHAIN_ID.toString()]: LABNET,
[SANDBOX_CHAIN_ID.toString()]: SANDBOX,
} as const;

// Define ChainId type as the keys of CHAIN_ID_TO_NETWORK_NAME
export type ChainId = keyof typeof CHAIN_ID_TO_NETWORK_NAME;

// NETWORK_NAME_TO_CHAIN_ID mapping remains the same
export const NETWORK_NAME_TO_CHAIN_ID = {
[MAINNET]: MAINNET_CHAIN_ID,
[BUILDNET]: BUILDNET_CHAIN_ID,
[SECURENET]: SECURENET_CHAIN_ID,
[LABNET]: LABNET_CHAIN_ID,
[SANDBOX]: SANDBOX_CHAIN_ID,
} as const;

// Define NetworkName type as the keys of NETWORK_NAME_TO_CHAIN_ID
export type NetworkName = keyof typeof NETWORK_NAME_TO_CHAIN_ID;

0 comments on commit 2b2d4ee

Please sign in to comment.