Skip to main content
Version: Endpoint V1

OFT V1.1 (legacy)

Omnichain Fungible Token standard written to support EVM chains only.

OFT.sol

https://github.com/LayerZero-Labs/solidity-examples/blob/main/contracts/token/oft/v1/OFT.sol

Installation

npm i @layerzerolabs/solidity-examples
caution

Breaking changes were introduced with OpenZeppelin V5. You should only use OpenZeppelin contract versions lower than 5.x.x to maintain compatibility with broader contract libraries.

Usage

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

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

import "@layerzerolabs/solidity-examples/contracts/token/oft/v1/NativeOFT.sol";

contract MyNativeOFTV1 is NativeOFT {
constructor(
string memory _name,
string memory _symbol,
uint8 _sharedDecimals,
address _lzEndpoint) NativeOFTV2(_name, _symbol, _sharedDecimals, _lzEndpoint) {}
// ... your contract logic here
}

Extensions

ProxyOFT.sol

Use this extension when you want to turn an already deployed ERC20 into an OFT. You can then deploy OFT contracts on the LayerZero supported chains of your choosing. When you want to transfer your OFT from the source chain the OFT will lock in the ProxyOFT and mint on the destination chain. When you come back to the ProxyOFT chain the OFT burns on the source chain and unlocks on the destination chain.

How to deploy ProxyOFT and OFT Contracts

  1. Deploy your ProxyOFT contract using your ERC-20 address, and specify the shared decimals (ie. where your ERC-20 decimals > shared-decimals).
  2. Deploy your OFT contract on the other connected chain(s) and specify the shared decimals in relation to your ERC-20 & ProxyOFT.
  3. Set your contracts to trust one another using setTrustedRemoteAddress. Pair them to one another's chain and address.
  4. Next, we're going to set our minimum Gas Limit for each chain. (Recommended 200k for all EVM chains except Arbitrum, 2M for Arbitrum). Call setMinDstGas with the chainId of the other chain, the packet type ("0" meaning send, "1" meaning send and call), and the gas limit amount.
  5. Required only for ProxyOFT: Finally, approve your ProxyOFT as a spender of your ERC20 token by calling your deployed ERC20's approve function. This comes standard in the ERC20 interface, and is required when using an intermediary contract to spend token amounts on behalf of the caller.

(Make sure that your AdapterParams gas limit > setMinDstGas)

info

If providedGasLimit >= minGasLimit, it'd fail: "LZApp: gas limit is too low", where providedGasLimit is _getGasLimit( provided in _adapterParams) and minGasLimit is minDstGasLimit

https://github.com/LayerZero-Labs/solidity-examples/blob/main/contracts/token/oft/v1/ProxyOFT.sol