Skip to main content

Contracts

LayerZero offers two Contract Standards that provide out of the box message handling, interfaces for custom protocol configurations, and other quality of life improvements for developers:

  • OApp: the base contract standard for omnichain messaging and configuration.

  • OFT: an extension of OApp built for handling and supporting omnichain fungible token transfers.

Because everything on the blockchain is at its root a smart contract, LayerZero can extend existing contract standards to interoperate with the protocol and provide developers a starting point for building specific omnichain applications.

info

To find all of LayerZero's contracts visit the LayerZero V2 Protocol Repo.

Installation

To start using LayerZero contracts, you can install the OApp npm package to an existing project:

npm install @layerzerolabs/lz-evm-oapp-v2
info

LayerZero contracts work with both OpenZeppelin V5 and V4 contracts. Specify your desired version in your project's package.json:

"resolutions": {
"@openzeppelin/contracts": "^5.0.1",
}

LayerZero also provides create-lz-oapp, an npx package that allows developers to create any omnichain application in <4 minutes!

tip

Get started by running the following from your command line:

npx create-lz-oapp@latest

Usage

Once installed, you can use the contracts in the library by importing them:

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.22;

import "@layerzerolabs/lz-evm-oapp-v2/contracts/oapp/OApp.sol";

contract MyOApp is OApp {
constructor(address _endpoint, address _owner) OApp(_endpoint, _owner) {}
}

To keep your system secure, you should always use the installed code as-is, and neither copy-paste it from online sources, nor modify it directly.

Most of the LayerZero contracts are expected to be used via inheritance: you will inherit from them when writing your own contracts.

Tooling

LayerZero also provides developer tooling to simplify the contract creation, testing, and deployment process:

  • LayerZero Scan: a comprehensive block explorer, search, API, and analytics platform for tracking and debugging your omnichain transactions.

You can also ask for help or follow development in the Discord.