Building a Cross-Chain Token Bridge with LayerZero V2

We built a cross-chain ERC20 token bridge using LayerZero V2. It moves BRG tokens across Ethereum, Arbitrum, Base, and Optimism — 12 directional pathways, all trustless, with multi-DVN verification. This post walks through the actual code. The full source is at github.com/gnuser/brg-bridge.

Architecture

/images/brg-bridge-architecture.svg

Lock-and-Mint Model

The bridge uses LayerZero’s OFT (Omnichain Fungible Token) standard:

  • Ethereum (home chain): BridgeOFTAdapter locks ERC20 tokens when bridging out, unlocks when bridging back.
  • L2 chains: BridgeOFT mints synthetic tokens on receive, burns on send. No pre-minted supply.

Total supply is always conserved: locked on Ethereum = minted across L2s.

LayerZero V2 Part 6: Developer Gotchas

This is Part 6 of a series on LayerZero V2. Part 1 covers the basics.

/images/part6-developer-gotchas.svg

These are the mistakes that cost us time building the BRG Bridge. Learn from our pain.

1. Wrong Option Type on Testnets

What happens: You use Type 3 options (the recommended format), but the testnet pathway doesn’t have Type 3 ULN config set. Transaction reverts with LZ_ULN_InvalidWorkerOptions.

LayerZero V2 Part 5: Composed Messages

This is Part 5 of a series on LayerZero V2. Part 1 covers the basics.

/images/part5-composed-messages.svg

Sometimes you want to bridge tokens AND do something with them in one operation. Bridge USDC to Arbitrum and immediately swap it for ETH. Bridge tokens and stake them. LayerZero V2 calls this composed messages.

The Problem with V1

In V1, composed operations were all-or-nothing. If you bridged + swapped + staked, and the staking failed, the ENTIRE transaction reverted — including the bridge. Your tokens got stuck in limbo.