Arbitrum Mainnet OFT Quickstart
Welcome! In this guide you'll mint and transfer a lightweight Omnichain Fungible Token (OFT) between Arbitrum Mainnet and any other supported chain.
Project scaffold
LayerZero's CLI lets you spin up an OFT workspace in seconds:
npx create-lz-oapp@latest # choose → "OFT example"
The wizard creates a repo with Hardhat + Foundry, sample contracts, tests and LayerZero helper scripts.
Add private keys
Rename .env.example
file to .env
and update it with needed configurations:
PRIVATE_KEY = your_private_key; // Required
At a minimum, you need to have the PRIVATE_KEY
. RPC URLs are optional, but strongly recommended. If you don't provide them, public RPCs will be used, but public RPCs can be unreliable or slow, leading to long waiting times for transactions to be confirmed or, at worst, cause your transactions to fail.
Hardhat network config
Update your hardhat.config.ts
file to include the networks you want to deploy your contracts to:
networks: {
// the network you are deploying to or are already on
// Arbitrum Mainnet (EID=30110)
'arbitrum-mainnet': {
eid: EndpointId.ARBITRUM_V2_MAINNET,
url: process.env.RPC_URL_ARBITRUM || 'https://arb1.arbitrum.io/rpc',
accounts,
},
// another network you want to connect to
'optimism-mainnet': {
eid: EndpointId.OPTIMISM_V2_MAINNET,
url: process.env.RPC_URL_OPTIMISM || 'https://mainnet.optimism.io',
accounts,
},
}
LayerZero wiring config
Modify your layerzero.config.ts
file to include the chains and channel security settings you want for each connection:
import {EndpointId} from '@layerzerolabs/lz-definitions';
import type {OmniPointHardhat} from '@layerzerolabs/toolbox-hardhat';
import {OAppEnforcedOption} from '@layerzerolabs/toolbox-hardhat';
import {ExecutorOptionType} from '@layerzerolabs/lz-v2-utilities';
import {TwoWayConfig, generateConnectionsConfig} from '@layerzerolabs/metadata-tools';
const arbitrumContract: OmniPointHardhat = {
eid: EndpointId.ARBITRUM_V2_MAINNET,
contractName: 'MyOFT',
};
const optimismContract: OmniPointHardhat = {
eid: EndpointId.OPTIMISM_V2_MAINNET,
contractName: 'MyOFT',
};
// To connect all the above chains to each other, we need the following pathways:
// Optimism <-> arbitrum
// arbitrum <-> Optimism
// For this example's simplicity, we will use the same enforced options values for sending to all chains
// To learn more, read https://docs.layerzero.network/v2/concepts/applications/oapp-standard#execution-options-and-enforced-settings
const EVM_ENFORCED_OPTIONS: OAppEnforcedOption[] = [
{
msgType: 1,
optionType: ExecutorOptionType.LZ_RECEIVE,
gas: 80000,
value: 0,
},
];
const pathways: TwoWayConfig[] = [
[
// 1) Chain B's contract (e.g. Optimism)
optimismContract,
// 2) Chain A's contract (e.g. arbitrum)
arbitrumContract,
// 3) Channel security settings:
// • first array = "required" DVN names
// • second array = "optional" DVN names array + threshold
// • third value = threshold (i.e., number of optionalDVNs that must sign)
// [ requiredDVN[], [ optionalDVN[], threshold ] ]
[['LayerZero Labs' /* ← add more DVN names here */], []],
// 4) Block confirmations:
// [confirmations for Optimism → arbitrum, confirmations for arbitrum → Optimism]
[20, 20],
// 5) Enforced execution options:
// [options for Optimism → arbitrum, options for arbitrum → Optimism]
[EVM_ENFORCED_OPTIONS, EVM_ENFORCED_OPTIONS],
],
];
export default async function () {
// Generate the connections config based on the pathways
const connections = await generateConnectionsConfig(pathways);
return {
contracts: [{contract: optimismContract}, {contract: arbitrumContract}],
connections,
};
}
It is strongly recommended to review LayerZero's Channel Security Model and understand the impact of each of these configuration settings.
See Next Steps to review the available providers and security settings.
The token contract
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.22;
import { Ownable } from "@openzeppelin/contracts/access/Ownable.sol";
import { OFT } from "@layerzerolabs/oft-evm/contracts/OFT.sol";
contract MyOFT is OFT, Ownable {
constructor(string memory name, string memory symbol, address endpoint, address owner)
OFT(name, symbol, endpoint, owner) Ownable(owner) {}
}
The OFT contract uses the ERC20 token standard. You may want to add a mint(...)
function in the constructor(...)
or contract body if this is your first time deploying an OFT. If you have an existing ERC20 token, you will want to use an OFT Adapter contract.
You can read the general OFT Quickstart for a better understanding of how OFTs work and what contracts to use.
Deploy
npx hardhat lz:deploy # choose arbitrum
You will be presented with a list of networks to deploy to.
Fund your deployer with native gas tokens beforehand.