LayerZero
What is LayerZero?
LayerZero is an omnichannel interoperability protocol designed to facilitate cross-chain communication. By enabling secure and efficient message passing across chains, LayerZero allows developers to build decentralized applications (dApps) that operate cohesively over multiple blockchains. This capability enhances the functionality and user experience of dApps by leveraging the unique features of various ecosystems.
Overview of LayerZero and HTS Compatibility
LayerZero integrates seamlessly with the Hedera Token Service (HTS) and EVM-compatible tokens (ERC-20 and ERC-721). This integration enables efficient cross-chain communication for various token types, making it easier to bridge assets such as $USDC or $Sauce between Hedera and other networks.
Getting Started with LayerZero on Hedera
To get started quickly, you can begin with the Gitpod demo, which requires no environment setup. Alternatively, you can go directly into the LayerZero Quickstart series. These guides provide an overview of deploying an Omnichain Application (OApp) on Hedera and other EVM-compatible networks, covering essentials like setting up your LayerZero environment and deploying contracts for cross-chain messaging.
LayerZero Examples and Key Components
All examples in the demo repo are exploratory code and have NOT been audited. Please use it at your own risk!
Omnichain Fungible Token (OFT) / Omnichain Non-Fungible Token (ONFT)
The OFT and ONFT token standards allow the transfer of fungible (ERC-20s) and non-fungible tokens (ERC-721s) across chains using LayerZero's messaging infrastructure. If you're bridging an existing fungible ERC token on Hedera to another EVM chain, you can deploy the OFT standard contract and the ONFT standard contract for NFTs.
Use Case
Allows fungible and non-fungible tokens to be transferred across chains.
Example Contracts
// SPDX-License-Identifier: Apache-2.0
pragma solidity ^0.8.22;
import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";
import {OFT} from "@layerzerolabs/lz-evm-oapp-v2/contracts/oft/OFT.sol";
contract ExampleOFT is OFT {
uint8 decimalsArg = 8;
constructor(
string memory _name,
string memory _symbol,
address _lzEndpoint,
address _delegate,
uint256 _initialMint,
uint8 _decimals
) OFT(_name, _symbol, _lzEndpoint, _delegate) Ownable(_delegate) {
_mint(msg.sender, _initialMint);
decimalsArg = _decimals;
}
function decimals() public view override returns (uint8) {
return decimalsArg;
}
}
OFT Adapter / ONFT Adapter
The OFT Adapter acts as an intermediary contract that handles sending and receiving existing fungible tokens across chains. If your token already exists on the chain you want to connect to, you can deploy the OFT Adapter contract to act as an intermediary lockbox for the token. Similarly, the ONFT Adapter handles sending and receiving existing fungible tokens across chains. If your NFT already exists on the chain you want to connect to, you can deploy the ONFT Adapter contract to act as an intermediary lockbox for the NFT.
Use Case
Intermediary contract that handles sending and receiving existing fungible tokens across chains. If your token already exists on the chain you want to connect to, you can deploy the OFT Adapter contract to act as an intermediary lockbox for the token.
Example Contracts
// SPDX-License-Identifier: Apache-2.0
pragma solidity ^0.8.22;
import {OFTAdapter} from "@layerzerolabs/lz-evm-oapp-v2/contracts/oft/OFTAdapter.sol";
import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";
contract ExampleOFTAdapter is OFTAdapter {
constructor(
address _token,
address _lzEndpoint,
address _owner
) OFTAdapter(_token, _lzEndpoint, _owner) Ownable(_owner) {}
}
HTS Connector
The HTS Connector extends LayerZero’s functionality to accommodate HTS tokens, addressing the differences between HTS and ERC token standards. It facilitates the integration of existing ERC tokens with Hedera by bridging them as native HTS tokens. This is a variant of OFT when bringing tokens to Hedera as HTS. If you bring a token to Hedera as an ERC token, you can use OFT or ONFT.
Use Case
Bridging a token from other networks to Hedera as an HTS token.
Developer Considerations to Note EVM Differences
Please note the smallest unit of HBAR is the tinybar (8 decimal places), while the JSON-RPC relay operates 18 decimal places for compatibility with Ethereum tools. This means when dealing with msg.value
, conversions between tinybars and weibars are necessary. Additionally, Hedera’s gas model charges for at least 80% of gas, regardless of usage, and event handling often requires querying mirror nodes. Please take these differences into account, especially when calling quote
. Reference the Understanding Hedera's EVM Differences and Compatibility: For EVM Developers section for a more comprehensive list of differences.
Additional Resources
Last updated
Was this helpful?