Skip to main content
Both OApp and OFT come packaged with methods you can implement or call directly in order to receive a quote for how much native gas your message will cost to send to the destination chain.
For a comprehensive overview of how LayerZero’s transaction pricing works, see Transaction Pricing Model. This page focuses on the technical implementation of fee estimation.
Both the OApp and OFT implementations for estimating fees require some knowledge of how _options work. We recommend reviewing the OApp or OFT Quickstart and Message Options guides first to better understand _options usage.

OApp Fee Estimation

To estimate how much gas a message will cost to be sent and received, you will need to implement a quote function to return an estimate from the Endpoint contract to use as a recommended msg.value.
The _quote can be returned in either the native gas token or in LzToken, supporting both payment methods. In general, this quote will be accurate as the same function is used by the Endpoint when pricing an _lzSend call:
Make sure that the arguments passed into the _quote function identically match the parameters used in the lzSend function. If parameters mismatch, you may run into errors as your msg.value will not match the actual gas quote.

Remember that to send a message, a msg.sender will be paying the source chain, the selected DVNs to deliver the message, and the destination chain to execute the transaction.

OFT Fee Estimation

To estimate how much gas an OFT transfer will cost, call the quoteSend function to return an estimate from the Endpoint contract.

Best Practices for Fee Estimation

Testing and Validation

  • Test quotes thoroughly on each target chain before deployment
  • Compare estimated vs actual costs in your testing environment
  • Account for gas price volatility by including appropriate buffers

Implementation Considerations

  • Cache quotes when possible to reduce onchain calls
  • Handle quote failures gracefully with proper error handling
  • Provide clear fee breakdowns to users in your interface
  • Update quotes regularly for accurate pricing in volatile markets

User Experience

  • Display total costs upfront before transaction confirmation
  • Show fee components separately (source gas, DVN fees, destination gas)
  • Offer gas limit recommendations based on operation complexity
  • Provide fee optimization suggestions for frequent operations