Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@layerzerolabs/lz-definitions

Package Overview
Dependencies
Maintainers
1
Versions
245
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@layerzerolabs/lz-definitions

LayerZero Utility

  • 3.0.19
  • latest
  • npm
  • Socket score

Version published
Weekly downloads
2.9K
decreased by-16.38%
Maintainers
1
Weekly downloads
 
Created
Source

@layerzerolabs/lz-definitions

The LayerZero Definitions package provides a comprehensive set of type definitions and utilities for interacting with various blockchains. It includes enums, types, and interfaces that facilitate the development and integration of applications with the LayerZero protocol.

Features

  • Enums: Provides a set of enums representing various blockchain-related constants.
  • Types: Defines various types used across the LayerZero protocol.
  • Interfaces: Provides interfaces for different blockchain specifications and configurations.
  • Utilities: Includes utility functions for converting and handling blockchain-related data.

Installation

To install the LayerZero Definitions package, you can use npm or yarn:

npm install @layerzerolabs/lz-definitions

or

yarn add @layerzerolabs/lz-definitions

Utilities

networkToEndpointId

import {
  networkToEndpointId,
  EndpointVersion,
  EndpointId,
} from "@layerzerolabs/lz-definitions";

// Converts a network name and version to an endpoint ID.
const endpointId: EndpointId = networkToEndpointId(
  "ethereum-mainnet",
  EndpointVersion.V1,
);
console.log(endpointId);

networkToEnv

import {
  networkToEnv,
  EndpointVersion,
  Environment,
} from "@layerzerolabs/lz-definitions";

// Converts a network name and version to an environment.
const environment: Environment = networkToEnv(
  "ethereum-mainnet",
  EndpointVersion.V1,
);
console.log(environment);

networkToStage

import { networkToStage, Stage } from "@layerzerolabs/lz-definitions";

// Converts a network name to a stage.
const stage: Stage = networkToStage("ethereum-mainnet");
console.log(stage);

endpointIdToNetwork

import {
  endpointIdToNetwork,
  Environment,
  Network,
  SandboxV2EndpointId,
} from "@layerzerolabs/lz-definitions";

// Converts an endpoint ID to a network name.
const network: Network = endpointIdToNetwork(
  SandboxV2EndpointId.APTOS_V2_SANDBOX,
  Environment.MAINNET,
);
console.log(network);

endpointIdToVersion

import {
  endpointIdToVersion,
  EndpointVersion,
  SandboxV2EndpointId,
} from "@layerzerolabs/lz-definitions";

// Converts an endpoint ID to an endpoint version.
const version: EndpointVersion = endpointIdToVersion(
  SandboxV2EndpointId.APTOS_V2_SANDBOX,
);
console.log(version);

endpointIdToChainKey

import {
  endpointIdToChainKey,
  ChainKey,
  SandboxV2EndpointId,
} from "@layerzerolabs/lz-definitions";

// Converts an endpoint ID to a chain key.
const chainKey: ChainKey = endpointIdToChainKey(
  SandboxV2EndpointId.APTOS_V2_SANDBOX,
);
console.log(chainKey);

chainAndStageToEndpointId

import {
  chainAndStageToEndpointId,
  Chain,
  Stage,
  EndpointVersion,
  EndpointId,
} from "@layerzerolabs/lz-definitions";

// Converts a chain and stage to an endpoint ID.
const endpointId: EndpointId = chainAndStageToEndpointId(
  Chain.ETHEREUM,
  Stage.MAINNET,
  EndpointVersion.V1,
);
console.log(endpointId);

chainAndStageToNetwork

import {
  chainAndStageToNetwork,
  Chain,
  Stage,
  Network,
} from "@layerzerolabs/lz-definitions";

// Converts a chain and stage to a network name.
const network: Network = chainAndStageToNetwork(Chain.ETHEREUM, Stage.MAINNET);
console.log(network);

endpointSpecToNetwork

import {
  endpointSpecToNetwork,
  EndpointSpec,
  Network,
} from "@layerzerolabs/lz-definitions";

const spec: EndpointSpec = {
  chain: Chain.ETHEREUM,
  stage: Stage.MAINNET,
  version: EndpointVersion.V1,
  env: Environment.MAINNET,
};

// Converts an endpoint specification to a network name.
const network: Network = endpointSpecToNetwork(spec);
console.log(network);

endpointSpecToEnv

import {
  endpointSpecToEnv,
  EndpointSpec,
  Environment,
} from "@layerzerolabs/lz-definitions";

const spec: EndpointSpec = {
  chain: Chain.ETHEREUM,
  stage: Stage.MAINNET,
  version: EndpointVersion.V1,
  env: Environment.MAINNET,
};

// Converts an endpoint specification to an environment.
const environment: Environment = endpointSpecToEnv(spec);
console.log(environment);

endpointSpecToEndpointId

import {
  endpointSpecToEndpointId,
  EndpointSpec,
  EndpointId,
} from "@layerzerolabs/lz-definitions";

const spec: EndpointSpec = {
  chain: Chain.ETHEREUM,
  stage: Stage.MAINNET,
  version: EndpointVersion.V1,
  env: Environment.MAINNET,
};

// Converts an endpoint specification to an endpoint ID.
const endpointId: EndpointId = endpointSpecToEndpointId(spec);
console.log(endpointId);

endpointIdToEndpointSpec

import {
  endpointIdToEndpointSpec,
  EndpointId,
  EndpointSpec,
  Environment,
  SandboxV2EndpointId,
} from "@layerzerolabs/lz-definitions";

// Converts an endpoint ID and environment to an endpoint specification.
const spec: EndpointSpec = endpointIdToEndpointSpec(
  SandboxV2EndpointId.APTOS_V2_SANDBOX,
  Environment.MAINNET,
);
console.log(spec);

networkToChain

import { networkToChain, Chain } from "@layerzerolabs/lz-definitions";

// Converts a network name to a chain.
const chain: Chain = networkToChain("ethereum-mainnet");
console.log(chain);

networkToChainType

import { networkToChainType, ChainType } from "@layerzerolabs/lz-definitions";

// Converts a network name to a chain type.
const chainType: ChainType = networkToChainType("ethereum-mainnet");
console.log(chainType);

chainToChainType

import {
  chainToChainType,
  Chain,
  ChainType,
} from "@layerzerolabs/lz-definitions";

// Returns the chain type for a given chain.
const chainType: ChainType = chainToChainType(Chain.ETHEREUM);
console.log(chainType);

endpointIdToChain

import {
  endpointIdToChain,
  Chain,
  SandboxV2EndpointId,
} from "@layerzerolabs/lz-definitions";

// Converts an endpoint ID to a chain.
const chain: Chain = endpointIdToChain(SandboxV2EndpointId.APTOS_V2_SANDBOX);
console.log(chain);

endpointIdToStage

import {
  endpointIdToStage,
  Stage,
  SandboxV2EndpointId,
} from "@layerzerolabs/lz-definitions";

// Converts an endpoint ID to a stage.
const stage: Stage = endpointIdToStage(SandboxV2EndpointId.APTOS_V2_SANDBOX);
console.log(stage);

endpointIdToChainType

import {
  endpointIdToChainType,
  ChainType,
  SandboxV2EndpointId,
} from "@layerzerolabs/lz-definitions";

// Converts an endpoint ID to a chain type.
const chainType: ChainType = endpointIdToChainType(
  SandboxV2EndpointId.APTOS_V2_SANDBOX,
);
console.log(chainType);

getNetworksForStage

import { getNetworksForStage, Stage } from "@layerzerolabs/lz-definitions";

// Gets the networks for a given stage.
const networks: string[] = getNetworksForStage(Stage.MAINNET);
console.log(networks);

getChainIdForNetwork

import { getChainIdForNetwork } from "@layerzerolabs/lz-definitions";

// Gets the chain ID for a given network.
const chainId: string = getChainIdForNetwork("ethereum", "mainnet", "1.0.0");
console.log(chainId);

getNetworkForChainId

import {
  getNetworkForChainId,
  Chain,
  Stage,
  SandboxV2EndpointId,
} from "@layerzerolabs/lz-definitions";

// Gets the network for a given chain ID.
const networkInfo = getNetworkForChainId(SandboxV2EndpointId.APTOS_V2_SANDBOX);
console.log(networkInfo.chainName, networkInfo.env, networkInfo.ulnVersion);

isNetworkEndpointIdSupported

import {
  isNetworkEndpointIdSupported,
  EndpointVersion,
} from "@layerzerolabs/lz-definitions";

// Checks if a network endpoint ID is supported.
const isSupported: boolean = isNetworkEndpointIdSupported(
  "ethereum-mainnet",
  EndpointVersion.V1,
);
console.log(isSupported);

isEvmChain

import { isEvmChain, Chain } from "@layerzerolabs/lz-definitions";

// Determines if a chain is EVM based.
const isEvm: boolean = isEvmChain(Chain.ETHEREUM);
console.log(isEvm);

FAQs

Package last updated on 27 Nov 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc