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

@layerzerolabs/lz-v2-utilities

Package Overview
Dependencies
Maintainers
1
Versions
147
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@layerzerolabs/lz-v2-utilities

LayerZero Utility V2

  • 3.0.21
  • latest
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

@layerzerolabs/lz-v2-utilities

The LayerZero V2 Utilities package provides a set of essential utilities and modules to facilitate the development and integration of applications with various blockchain networks. It includes functions for packet encoding/decoding, precrime configuration parsing, error parsing, and more.

Features

  • Packet Encoding/Decoding: Functions for encoding and decoding packets.
  • Precrime Configuration Parsing: Functions for parsing precrime configurations.
  • Error Parsing: Functions for parsing error data.
  • Hex Utilities: Functions for handling hexadecimal data.
  • Options Management: Functions for managing options.

Installation

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

npm install @layerzerolabs/lz-v2-utilities

or

yarn add @layerzerolabs/lz-v2-utilities

Usage

Packet Encoding/Decoding

PacketV1Codec

Encodes and decodes packets using the V1 codec.

import { PacketV1Codec } from "@layerzerolabs/lz-v2-utilities";

const packet = {
    version: 1,
    nonce: '1',
    srcEid: 10121,
    sender: '0x7Cff4181f857B06114643D495648A95b3E0B0B81',
    dstEid: 10108,
    receiver: '0x6552e1c444f6a2ce35b22de6a554da8c32c5650db0e0158df2eb0daa51289968',
    guid: '0x6552e1c444f6a2ce35b22de6a554da8c32c5650db0e0158df2eb0daa51289968',
    message: '0xff',
    payload: '',
};

// Encode the packet
const encodedHex = PacketV1Codec.encode(packet);
console.log(`Encoded Packet: ${encodedHex}`);

// Decode the packet
const decodedPacket = PacketV1Codec.from(encodedHex).toPacket();
console.log(`Decoded Packet: ${JSON.stringify(decodedPacket)}`);

Precrime Configuration Parsing

parsePrecrimeConfig

Parses the precrime configuration string.

import { parsePrecrimeConfig } from "@layerzerolabs/lz-v2-utilities";

const configHex = '0x0002000000000000000500010000000100000000000000000000000000000000000000000000000000000000000111110000000000000000000000000000000000000000000000000000000000011111';

const config = parsePrecrimeConfig(configHex);
console.log(`Parsed Precrime Config: ${JSON.stringify(config)}`);

Error Parsing

parseError

Parses the error data.

import { parseError } from "@layerzerolabs/lz-v2-utilities";
import { Interface } from "@ethersproject/abi";

const errorData = "0x08c379a0...";
const intf = new Interface(["function myFunction()"]);

const parsedError = parseError(errorData, intf);
console.log(`Parsed Error: ${parsedError}`);

Hex Utilities

hexZeroPadTo32

Pads a hexadecimal address to 32 bytes.

import { hexZeroPadTo32 } from "@layerzerolabs/lz-v2-utilities";

const address = "0x1234567890abcdef1234567890abcdef12345678";
const paddedAddress = hexZeroPadTo32(address);
console.log(`Padded Address: ${paddedAddress}`);

Options Management

optionsType1

Builds OptionsType.TYPE_1.

import { optionsType1 } from "@layerzerolabs/lz-v2-utilities";

const extraGas = 200000;
const options = optionsType1(extraGas);
console.log(`Options Type 1: ${options}`);

FAQs

Package last updated on 02 Dec 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