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

@layerzerolabs/lz-core

Package Overview
Dependencies
Maintainers
0
Versions
131
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@layerzerolabs/lz-core

LayerZero Core Library

  • 3.0.36
  • latest
  • npm
  • Socket score

Version published
Weekly downloads
468
decreased by-85.89%
Maintainers
0
Weekly downloads
 
Created
Source

@layerzerolabs/lz-core

This package defines the core interface for the tooling stack, containing only neutral interfaces that are unrelated to the LayerZero protocol.

Features

  • Transaction Interface: Used for expressing transactions in different stages.
  • Provider Interface: Defines the connectors to a chain node.
  • Signer Interface: Handles message and transaction signing.
  • The signHash function is implemented in this package instead of lz-utilities or lz-foundation to minimize dependencies.

Installation

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

npm install @layerzerolabs/lz-core

or

yarn add @layerzerolabs/lz-core

Usage

Transaction Interfaces

TransactionRequest

Represents the request of a transaction.

import { TransactionRequest } from "@layerzerolabs/lz-core";

const request = TransactionRequest.from({
    to: "0xRecipientAddress",
    value: "1000000000000000000", // 1 ETH
});
console.log(`Transaction Request: ${JSON.stringify(request)}`);
TransactionResponse

Represents the response of a transaction.

import { TransactionResponse } from "@layerzerolabs/lz-core";

const response = TransactionResponse.from({
    hash: "0xTransactionHash",
    status: 1,
});
console.log(`Transaction Response: ${JSON.stringify(response)}`);

Provider Interface

Defines the connectors to a chain node.

import { Provider } from "@layerzerolabs/lz-core";

class MyProvider implements Provider {
    url = "https://mainnet.infura.io/v3/YOUR_INFURA_PROJECT_ID";

    async getBlock(blockTag) {
        // Implementation to get block
    }

    async getBlockWithTransactions(blockTag) {
        // Implementation to get block with transactions
    }

    async getTransaction(txHash) {
        // Implementation to get transaction
    }

    async getTransactionReceipt(txHash) {
        // Implementation to get transaction receipt
    }

    async getBlockNumber() {
        // Implementation to get block number
    }

    async getSlot(commitment) {
        // Implementation to get slot
    }

    async getTransactionCount(addressOrName, blockTag) {
        // Implementation to get transaction count
    }

    async getBalance(address) {
        // Implementation to get balance
    }

    async getBlockTimestamp(blockTag) {
        // Implementation to get block timestamp
    }

    async sendTransaction(transaction, sendOptions) {
        // Implementation to send transaction
    }

    async confirmTransaction(pending, opts) {
        // Implementation to confirm transaction
    }

    async sendAndConfirm(transaction, opts) {
        // Implementation to send and confirm transaction
    }

    readonly native = {}; // Native provider instance
}

const provider = new MyProvider();
console.log(`Provider URL: ${provider.url}`);

Signer Interface

Handles message and transaction signing.

import { Signer, TransactionRequest, SignedTransaction, TransactionPending, TransactionReceipt } from "@layerzerolabs/lz-core";

class MySigner implements Signer {
    async connect(provider) {
        // Implementation to connect to provider
    }

    async buildTransaction(buildTxRequest) {
        // Implementation to build transaction
    }

    async signTransaction(transaction) {
        // Implementation to sign transaction
    }

    async sendTransaction(transaction, sendOptions) {
        // Implementation to send transaction
    }

    async sendAndConfirm(transaction, opts) {
        // Implementation to send and confirm transaction
    }

    async signBuffer(buffer) {
        // Implementation to sign buffer
    }

    async getAddress() {
        // Implementation to get address
    }

    native = {}; // Native signer instance
}

const signer = new MySigner();
console.log(`Signer Address: ${await signer.getAddress()}`);

FAQs

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