Integration of LayerZero V2
Note: when a user transfers tokens through a classic bridge, they entrust their funds to a custodian. The Ronin bridge hack for $600M showed that this approach is dangerous. LayerZero V2 solves this problem fundamentally differently: the token is burned on the source and minted on the destination — no locked liquidity. This makes OFT 100 times safer than traditional bridges since there is no single point of failure. We integrate LayerZero V2 into DeFi projects — from simple OFT to complex cross-chain DAOs. Stack: Solidity 0.8.x, Foundry, Hardhat. We work with Ethereum, Arbitrum, Polygon, BNB Chain, and Base. We have 30+ projects and $10M+ in managed liquidity.
According to LayerZero V2 Documentation, the protocol provides omnichain messaging with verification via DVN. DVN configuration is set via setConfig, allowing security to be tailored to the specific project.
How does LayerZero V2 work?
V2 simplified the architecture compared to V1. Endpoint is a singleton contract in each network. Address: 0x1a44076050125825900e736c501f859c50fE728c in all supported networks. DVN are verifiers that confirm delivery. The developer chooses the configuration: number of required/optional DVN. Example providers: Google Cloud, Polyhedra, Axelar. Minimum secure configuration: 2 independent DVN in required. Executor is an agent that calls lzReceive on the destination after DVN confirmation. You can use the standard LayerZero executor or your own.
Why is OFT safer than a classic bridge?
In a classic bridge, you lock the token and rely on the custodian not to steal it. In OFT, the token exists natively in each network: on transfer, it is burned on the source and minted on the destination. No locked liquidity. A bridge hack like Ronin ($600M) is impossible — there is no single point of failure. The only risk is incorrect setPeer configuration. Compare:
| Parameter | Classic bridge | OFT |
|---|---|---|
| Mechanism | Lock-and-mint | Burn-and-mint |
| Hack risk | High (single point of failure) | Low (no locked liquidity) |
| Audit | Required for every contract | Only setPeer configuration |
OApp: Basic Integration Pattern
OApp is the base contract for any integration. Example implementation:
import { OApp, Origin, MessagingFee } from "@layerzerolabs/oapp-evm/contracts/oapp/OApp.sol";
contract CrossChainMessenger is OApp {
event MessageReceived(uint32 srcEid, bytes32 sender, string message);
constructor(address _endpoint, address _owner)
OApp(_endpoint, _owner) {}
function sendMessage(
uint32 dstEid,
string calldata message,
bytes calldata options
) external payable {
bytes memory payload = abi.encode(message);
MessagingFee memory fee = _quote(dstEid, payload, options, false);
require(msg.value >= fee.nativeFee, "Insufficient fee");
_lzSend(dstEid, payload, options, fee, payable(msg.sender));
}
function _lzReceive(
Origin calldata origin,
bytes32,
bytes calldata payload,
address,
bytes calldata
) internal override {
string memory message = abi.decode(payload, (string));
emit MessageReceived(origin.srcEid, origin.sender, message);
}
function quoteSend(
uint32 dstEid,
string calldata message,
bytes calldata options
) external view returns (MessagingFee memory) {
return _quote(dstEid, abi.encode(message), options, false);
}
}
options encode gas limit for lzReceive, airdrop ETH, ordered delivery. Use OptionsBuilder. Insufficient gas causes revert on destination. Excessive gas leads to overpayment. Profiling through tests is necessary.
OFT: Omnichain Fungible Token
OFT is the main use case. The token exists natively in each network. The contract is minimal:
import { OFT } from "@layerzerolabs/oft-evm/contracts/OFT.sol";
contract MyOFT is OFT {
constructor(string memory _name, string memory _symbol, address _lzEndpoint, address _owner)
OFT(_name, _symbol, _lzEndpoint, _owner) {}
}
Deploy in each network and link via setPeer. This operation is critical for security — if the wrong address is specified, messages will go nowhere.
OFTAdapter for Existing Tokens
If the token already lives on one network, use OFTAdapter:
import { OFTAdapter } from "@layerzerolabs/oft-evm/contracts/OFTAdapter.sol";
contract MyTokenAdapter is OFTAdapter {
constructor(address _token, address _lzEndpoint, address _owner)
OFTAdapter(_token, _lzEndpoint, _owner) {}
}
On the home chain, deploy an Adapter (custodian); on the others, a regular OFT.
How to Configure DVN?
DVN configuration is a key security step. Follow these steps:
- Select at least 2 independent DVN providers (e.g., LayerZero Labs and Google Cloud).
- Determine required/optional configuration. We recommend 2 required, 0 optional.
- Use
ILayerZeroEndpointV2.setConfigto apply settings.
Example configuration:
const configParams = [{
eid: dstEid,
configType: CONFIG_TYPE_ULN,
config: ethers.AbiCoder.defaultAbiCoder().encode(
['tuple(uint64,uint8,uint8,uint8,address[],address[])'],
[[0, 2, 1, 0, [dvn1, dvn2], [dvn3]]]
)
}];
await endpoint.setConfig(oappAddress, sendLibAddress, configParams);
This configuration ensures that for message delivery, confirmation from two of the three specified DVNs is required. 10 times more reliable than using a single verifier.
Step-by-Step Integration Guide for LayerZero V2
- Choose the integration type (OApp, OFT, or OFTAdapter).
- Develop a smart contract using @layerzerolabs/oapp-evm.
- Deploy the contract in target networks (minimum 2).
- Configure setPeer to link contracts between networks.
- Configure DVN via setConfig (minimum 2 required).
- Test on testnets (Sepolia, Mumbai).
- Launch on mainnet and set up monitoring via lzScan.
Testing and DevTools
For local testing, use TestHelper from @layerzerolabs/test-devtools-evm-foundry:
contract OFTTest is TestHelper {
function setUp() public virtual override {
super.setUp();
setUpEndpoints(2, LibraryType.UltraLightNode);
}
}
lzScan is the official explorer for debugging. For production errors, it's the first tool.
Common Errors
- Insufficient gas on destination – solutions: increase gas in OptionsBuilder, pre-measure via tests.
- Unordered delivery – if order matters, use ordered delivery (30% more expensive).
- Fee estimation – call
_quoteimmediately before the transaction: fee depends on destination gas price and changes quickly.
What's Included in the Integration
- Cross-chain interaction architecture
- Smart contract development (OApp/OFT/OFTAdapter)
- Deployment in 2–5 networks (Ethereum, Arbitrum, Polygon, BNB Chain, Base)
- DVN and Executor configuration
- Testing on testnets (Sepolia, Mumbai)
- Monitoring via lzScan
- Documentation and team training
| Task | Tool |
|---|---|
| Smart contracts | Solidity + OApp SDK |
| Deploy and wire | Hardhat + lz-devtools |
| DVN configuration | LayerZero SDK + Dashboard |
| Testing | Foundry + TestHelper |
| Monitoring | lzScan |
Basic OFT integration (existing token + cross-chain transfer) takes 2–3 weeks. Custom application with multiple networks and UI takes 6–8 weeks. For OFT with significant liquidity, we recommend auditing contracts and setPeer configuration.
We guarantee security and reliability of integration. We will assess your project — get a consultation. Contact us to discuss your project and receive an estimate of timelines and cost. Order LayerZero integration today.







