LayerZero Simple Config Generator
The LayerZero Simple Config Generator makes use of the @layerzerolabs/metadata-tools
package to provide a streamlined approach to configuring your OApp connections. It allows for a more simplified LayerZero config file.
Current Support: The Simple Config Generator currently supports EVM chains and Solana. Aptos support is not yet available.
Here's how to use it:
-
Install metadata-tools:
pnpm add -D @layerzerolabs/metadata-tools
-
Create a new LZ config file named
layerzero.config.ts
(or edit your existing one) in the project root and use the examples below as a starting point:- EVM Chains Only
- EVM + Solana
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,
},
];
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,
};
}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';
export const avalancheContract: OmniPointHardhat = {
eid: EndpointId.AVALANCHE_V2_TESTNET,
contractName: 'MyOFT',
};
export const solanaContract: OmniPointHardhat = {
eid: EndpointId.SOLANA_V2_TESTNET,
address: 'HBTWw2VKNLuDBjg9e5dArxo5axJRX8csCEBcCo3CFdAy', // your OFT Store address
};
const EVM_ENFORCED_OPTIONS: OAppEnforcedOption[] = [
{
msgType: 1,
optionType: ExecutorOptionType.LZ_RECEIVE,
gas: 80000,
value: 0,
},
];
const SOLANA_ENFORCED_OPTIONS: OAppEnforcedOption[] = [
{
msgType: 1,
optionType: ExecutorOptionType.LZ_RECEIVE,
gas: 200000,
value: 2039280, // SPL token account rent value in lamports
},
];
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
solanaContract, // Chain B contract
[['LayerZero Labs'], []], // [ requiredDVN[], [ optionalDVN[], threshold ] ]
[1, 1], // [A to B confirmations, B to A confirmations]
[SOLANA_ENFORCED_OPTIONS, EVM_ENFORCED_OPTIONS], // Chain B enforcedOptions, Chain A enforcedOptions
],
]);
return {
contracts: [{contract: avalancheContract}, {contract: solanaContract}],
connections,
};
}- Note that only the Solana contract object requires
address
to be specified. Do not specifyaddress
for non-Solana contract objects. - The above examples contain a minimal mesh with only one pathway (two chains) for demonstration purposes. You are able to add as many pathways as you need into the
connections
param, viagenerateConnectionsConfig
.
-
If your pathways include Solana, run the Solana init config command:
npx hardhat lz:oft:solana:init-config --oapp-config layerzero.config.ts
- Run the wire command:
- EVM Only
- EVM + Solana
npx hardhat lz:oapp:wire --oapp-config layerzero.config.ts
The wire command processes all the transactions required to connect all pathways specified in the LZ Config file. You need to only run this once regardless of how many pathways there are. If you change anything in the LZ Config file, then it should be run again.
npx hardhat lz:oapp:wire --oapp-config layerzero.config.ts
Key Features
- Automatic Bidirectional Connections: Define one pathway, get both directions automatically
- Built-in Best Practices: Uses recommended DVN and executor configurations
- Cross-VM Compatibility: Works seamlessly with EVM chains and Solana
- Reduced Complexity: Fewer configuration parameters to manage
- Less Error-Prone: Automated configuration generation reduces manual errors
Configuration Parameters
Pathway Definition
[
contractA, // Source chain contract
contractB, // Destination chain contract
[['LayerZero Labs'], []], // DVN configuration
[1, 1], // Confirmations for each direction
[optionsA, optionsB], // Enforced options for each direction
];
DVN Configuration
[['LayerZero Labs'], []]; // [ requiredDVN[], [ optionalDVN[], threshold ] ]
- Required DVNs: Must verify the message for it to be considered valid
- Optional DVNs: Additional verifiers (with threshold) for enhanced security
Enforced Options
const EVM_ENFORCED_OPTIONS: OAppEnforcedOption[] = [
{
msgType: 1, // Message type (1 = OFT, 2 = OApp)
optionType: ExecutorOptionType.LZ_RECEIVE, // Option type
gas: 80000, // Gas limit for destination execution
value: 0, // Value to send (usually 0)
},
];
VM-Specific Considerations
EVM Chains
- Use
contractName
for contract identification - Gas values represent actual gas units
- Value is typically 0
Solana
- Use
address
for contract identification (required) - Gas values represent compute units
- Value represents lamports (typically 2039280 for SPL token account rent)
Custom Metadata: For advanced use cases, you can provide custom metadata by passing a fetchMetadata
function to generateConnectionsConfig
. This allows you to extend the default metadata with custom DVNs and executors.
Next Steps
- Migrate from Manual Config: See the Migrate to Simple Config guide
- Production Deployment: Review and adjust settings for production environments
- Gas Optimization: Profile your contracts to set optimal gas limits
- Custom DVNs: Consider adding custom DVNs for enhanced security