Skip to main content
Version: Endpoint V2

Transaction Pricing

Every transaction using LayerZero has four main cost elements, one for each component that enables cross-chain messaging:

  1. an initial source blockchain transaction.

  2. the fee paid to the OApp's configured Security Stack.

  3. the configured Executor fee for executing the message on the destination chain.

  4. the gas cost of the transaction on the destination blockchain itself.

Message Execution Options

Because the source chain has no concept of the destination chain's state, you must specify the amount of gas (wei) you anticipate will be necessary for executing your _lzReceive or lzCompose method on the destination smart contract.

LayerZero provides robust Message Execution Options, which allow users to provide detailed instructions regarding the gas limit and msg.value the Executor uses for message delivery on the destination chain:

// addExecutorLzReceiveOption(GAS_LIMIT, MSG_VALUE)
// addExecutorLzComposeOption(INDEX, GAS_LIMIT, MSG_VALUE)
bytes memory options = OptionsBuilder.newOptions()
.addExecutorLzReceiveOption(60000, 0)
.addExecutorLzComposeOption(0, 30000, 0)
caution

The amount of gas units (wei) that your contract's _lzReceive or lzCompose methods consume can be dynamic depending on the destination chain. Different blockchains have different opcode costs and gas mechanisms that can fluctuate (e.g., sequencer fees, proof fees, etc).

To mitigate the risk of transactions stalling due to OUT-OF-GAS issues on the destination, it is advisable to test gas costs for your _lzReceive or lzCompose contract logic, and incorporate a gas buffer by allocating additional gas upfront depending on the chain.

Quote Mechanism

The LayerZero Endpoint provides an on-chain quote mechanism, to determine the cost of sending a message to the destination chain:

// LayerZero Endpoint's quote mechanism
endpoint.quote(
MessagingParams(_dstEid, _getPeerOrRevert(_dstEid), _message, _options, _payInLzToken),
address(this)
);

Both the OApp and OFT have implemented a quote mechanism using this Endpoint method.

If a user wants to send a message from Chain A to Chain B, the gas quote returned on Chain A is:

  • the execution cost on Chain A + fees for the Security Stack and Executor + a quote for the gas to be executed on Chain B

For example, if a user wants 200000 gas units on Chain B, then a quote for that gas token is obtained by multiplying the gas by the gas price on the destination chain. It also takes into account dollar prices of the source and destination native tokens.

The source chain's native token quote is calculated using following formula:

GAS×DESTINATION_GAS_PRICE×DESTINATION_NATIVE_TOKEN_PRICESOURCE_NATIVE_TOKEN_PRICE\text{GAS} \times \text{DESTINATION\_GAS\_PRICE} \times \frac{\text{DESTINATION\_NATIVE\_TOKEN\_PRICE}}{\text{SOURCE\_NATIVE\_TOKEN\_PRICE}}

For example, assume Chain A is Astar and Chain B is Astar zkEVM:


200000 * (4000000000 / 10**18) * $3500 / $0.15 = 18.7 ASTR quote
info

In the above example, Astar uses token ASTR as a native token, and Astar zkEVM uses ETH as its native token. Other assumptions are:

  1. ASTR = ~$0.15
  2. ETH = ~$3500
  3. Destination gas price = 4 Gwei :::

Handling Errors

Transactions in LayerZero may occasionally encounter delays in transit from the source chain to the destination chain. Common causes for these delays include:

  • Failure to initiate a valid transaction from the source chain into the LayerZero protocol.

  • Insufficient gas payments made by the user.

  • Transaction reverts on the destination chain, either due to in-contract or configuration issues.

LayerZero Scan offers a comprehensive tool for users to track their transactions. It provides detailed insights into where transactions may encounter delays, serving as a starting point for debugging.

Users can find detailed guidelines and support for debugging and recovering stalled transactions in Debugging Messages.