Skip to main content
Version: Endpoint V2 Docs

LayerZero Experimental Simple Config Generator

We have developed a new simple config generator which makes use of the metadata-tools package. It is currently in the experimental stage. It allows for a more simplified Layerzero config file.

Here's how to use it:

  1. Install metadata-tools: pnpm add -D @layerzerolabs/metadata-tools

  2. Create a new file named layerzero.simple.config.ts in the project root and use the examples below as a starting point:

    import {ExecutorOptionType} from '@layerzerolabs/lz-v2-utilities';
    import {OAppEnforcedOption, OmniPointHardhat} from '@layerzerolabs/toolbox-hardhat';
    import {EndpointId} from '@layerzerolabs/lz-definitions';
    import {generateConnectionsConfig} from '@layerzerolabs/metadata-tools';

    const avalancheContract: OmniPointHardhat = {
    eid: EndpointId.AVALANCHE_V2_TESTNET,
    contractName: 'MyOFT',
    };

    const polygonContract: OmniPointHardhat = {
    eid: EndpointId.AMOY_V2_TESTNET,
    contractName: 'MyOFT',
    };

    const EVM_ENFORCED_OPTIONS: OAppEnforcedOption[] = [
    {
    msgType: 1,
    optionType: ExecutorOptionType.LZ_RECEIVE,
    gas: 80000,
    value: 0,
    },
    {
    msgType: 2,
    optionType: ExecutorOptionType.LZ_RECEIVE,
    gas: 80000,
    value: 0,
    },
    {
    msgType: 2,
    optionType: ExecutorOptionType.COMPOSE,
    index: 0,
    gas: 80000,
    value: 0,
    },
    ];

    export default async function () {
    // note: pathways declared here are automatically bidirectional
    // if you declare A,B there's no need to declare B,A
    const connections = await generateConnectionsConfig([
    [
    avalancheContract, // Chain A contract
    polygonContract, // Chain B contract
    [['LayerZero Labs'], []], // [ requiredDVN[], [ optionalDVN[], threshold ] ]
    [1, 1], // [A to B confirmations, B to A confirmations]
    [EVM_ENFORCED_OPTIONS, EVM_ENFORCED_OPTIONS], // Chain B enforcedOptions, Chain A enforcedOptions
    ],
    ]);

    return {
    contracts: [{contract: avalancheContract}, {contract: polygonContract}],
    connections,
    };
    }

    Note that only Solana contract object require address to be specified.

  3. If your pathways include Solana, run the Solana init config command:

npx hardhat lz:oft:solana:init-config --oapp-config layerzero.simple.config.ts --solana-secret-key <SECRET_KEY> --solana-program-id <PROGRAM_ID>
  1. Run the wire command:
npx hardhat lz:oapp:wire --oapp-config layerzero.simple.config.ts