Skip to main content
Version: Endpoint V2 Docs

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 cost of purchasing the specified amount of destination gas token(s) for the Executor's destination transaction.

    The source chain's native gas token quote for the messaging fee 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}}

Gas Amount

Because the source chain has no concept of the destination chain's state, you must specify the amount of gas in 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 per function call:

// 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/V2/protocol/contracts/interfaces/ILayerZeroEndpointV2.sol

struct MessagingParams {
uint32 dstEid;
bytes32 receiver;
bytes message;
bytes options;
bool payInLzToken;
}

struct MessagingFee {
uint256 nativeFee;
uint256 lzTokenFee;
}

// LayerZero Endpoint's quote mechanism
function quote(MessagingParams calldata _params, address _sender) external view returns (MessagingFee memory);

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}}

info

For example, assume Chain A is Astar and Chain B is Astar zkEVM, 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

The quote returned will be:

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

Profiling

These sample gas profiles were based on 15 OFT transfers across 3 EVM networks (Sepolia, Fuji, Mumbai):

MetricValue
Deployment gas2,903,879
Send gas on source chain (average)226,541
Send gas on source chain (range)221,261 - 241,095
Receive gas on destination chain (average)62,000
Receive gas on destination chain (range)56,970 - 78,882

Please note that the values provided above were measured for standard OFT transactions with minimal custom logic applied. You can explore the source code at the following links:

Feel free to input these contract addresses into LayerZero Scan to discover all the transfers used for profiling, including both the source and destination transactions.

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.