@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",
});
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) {
}
async getBlockWithTransactions(blockTag) {
}
async getTransaction(txHash) {
}
async getTransactionReceipt(txHash) {
}
async getBlockNumber() {
}
async getSlot(commitment) {
}
async getTransactionCount(addressOrName, blockTag) {
}
async getBalance(address) {
}
async getBlockTimestamp(blockTag) {
}
async sendTransaction(transaction, sendOptions) {
}
async confirmTransaction(pending, opts) {
}
async sendAndConfirm(transaction, opts) {
}
readonly native = {};
}
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) {
}
async buildTransaction(buildTxRequest) {
}
async signTransaction(transaction) {
}
async sendTransaction(transaction, sendOptions) {
}
async sendAndConfirm(transaction, opts) {
}
async signBuffer(buffer) {
}
async getAddress() {
}
native = {};
}
const signer = new MySigner();
console.log(`Signer Address: ${await signer.getAddress()}`);