layerzero
Installation
SKILL.md
LayerZero
LayerZero V2 is an immutable, censorship-resistant messaging protocol for cross-chain communication. It enables smart contracts on different blockchains to send arbitrary messages to each other through a modular security stack of Decentralized Verifier Networks (DVNs). The core primitive is the OApp (Omnichain Application) — a contract that inherits OApp.sol and implements _lzSend / _lzReceive to send and receive cross-chain messages through EndpointV2.
What You Probably Got Wrong
AI agents trained before mid-2024 confuse V1 and V2 architecture. These are the critical corrections.
- V2 is NOT V1 — completely different architecture. V1 used
LZApp,ILayerZeroEndpoint, and a monolithic oracle+relayer model. V2 usesOApp,EndpointV2, and modular DVNs+Executors. Do NOT import@layerzerolabs/solidity-examples— that is V1. Use@layerzerolabs/oapp-evmfor V2. - OFT burns on source, mints on destination — NOT a lock/mint bridge. The Omnichain Fungible Token standard burns tokens on the source chain and mints equivalent tokens on the destination. For existing ERC-20s that cannot add burn/mint, use
OFTAdapterwhich locks on source and mints an OFT representation on destination. - DVNs replace the V1 oracle+relayer model. V1 had a single Oracle and Relayer operated by LayerZero Labs. V2 decouples verification into configurable DVN sets — you choose which DVNs must verify your messages and set quorum thresholds.
_lzSendrequires proper fee estimation viaquoteSend()or_quote(). You must call the quote function first to determine the exactMessagingFee(native + lzToken), then pass that fee asmsg.value. Underpaying reverts.- Peer addresses must be set on BOTH chains. Calling
setPeer(dstEid, bytes32(peerAddress))on chain A is not enough. You must also callsetPeer(srcEid, bytes32(chainAAddress))on chain B. Unset peers causeNoPeerreverts. - Message ordering is NOT guaranteed unless you configure ordered delivery. V2 delivers messages in a nonce-based system, but by default the executor can deliver messages out of order. Use the
OrderedNonceenforcement option if strict ordering matters. eid(Endpoint ID) is NOT the chain ID. LayerZero uses its own Endpoint ID system. Ethereum mainnet is eid30101, Arbitrum is30110, Base is30184, Optimism is30111, Polygon is30109. Using chain IDs instead of eids is the most common integration mistake.- Peer addresses are
bytes32, notaddress. All peer addresses are stored asbytes32to support non-EVM chains. For EVM addresses, left-pad with zeros:bytes32(uint256(uint160(addr))). Passing a rawaddresstosetPeerwill fail. - The Executor is separate from DVNs. DVNs verify messages, but the Executor actually calls
lzReceiveon the destination. You can configure a custom Executor or use the LayerZero default. If you set gas limits too low in message options, the Executor will run out of gas on the destination.