Skip to main content
Version: Endpoint V2

Deploying Contracts

Deploying LayerZero contracts is a straightforward process using the CLI tool.

After configuring your layerzero.config.ts with the appropriate contracts and adding your MNEMONIC or PRIVATE_KEY to your dotenv file:

import {ChainKey, EndpointVersion, networkToEndpointId} from '@layerzerolabs/lz-definitions';

// Define the Ethereum contract
// eid specifies the network (LZ V2 Ethereum Sepolia Testnet) and contractName is the name of the contract.
const ethContract = {
eid: networkToEndpointId(ChainKey.ETHEREUM, EndpointVersion.V2),
contractName: 'MyOFT',
};

// Define the Avalanche contract
// eid specifies the network (LZ V2 Avalanche Fuji Testnet) and contractName is the name of the contract.
const avaxContract = {
eid: networkToEndpointId(ChainKey.FUJI, EndpointVersion.V2),
contractName: 'MyOFT',
};

// Define the Amoy (Polygon) contract
// eid specifies the network (LZ V2 Polygon Amoy Testnet) and contractName is the name of the contract.
const amoyContract = {
eid: networkToEndpointId(ChainKey.AMOY_TESTNET, EndpointVersion.V2),
contractName: 'MyOFT',
};

Run the following command to deploy your LayerZero contracts:

npx hardhat lz:deploy

You will be prompted to select which chains to deploy to:

info:    Compiling you hardhat project
Nothing to compile
? Which networks would you like to deploy? ›
Instructions:
↑/↓: Highlight option
←/→/[space]: Toggle selection
[a,b,c]/delete: Filter choices
enter/return: Complete answer

Filtered results for: Enter something to filter

◉ fuji
◉ amoy
◉ sepolia

If you wish to deploy to all blockchain networks selected, simply hit enter to continue deployment.

To deselect a chain for deployment, highlight the chain and toggle the selection using the space bar or arrow keys:

Filtered results for: Enter something to filter

◉ fuji
◯ amoy
◉ sepolia

Afterwards you'll be prompted to choose which deploy script tags to use:

info:    Compiling you hardhat project
Nothing to compile
✔ Which networks would you like to deploy? › bsc_testnet, amoy, sepolia
? Which deploy script tags would you like to use? ›

By default, each LayerZero project has an example deploy script which will be used if no changes have been made:

warn:    Will use all deployment scripts
✔ Do you want to continue? … yes
Network: amoy
Deployer: 0x0000000000000000000000000000000000000000
Network: fuji
Deployer: 0x0000000000000000000000000000000000000000
Network: sepolia
Deployer: 0x0000000000000000000000000000000000000000
Deployed contract: MyOFT, network: amoy, address: 0x0000000000000000000000000000000000000000
Deployed contract: MyOFT, network: fuji, address: 0x0000000000000000000000000000000000000000
Deployed contract: MyOFT, network: sepolia, address: 0x0000000000000000000000000000000000000000
info: ✓ Your contracts are now deployed