lifi.quote

Documentation for eth_defi.lifi.quote Python module.

LI.FI cross-chain quote fetching.

See LI.FI API documentation for more details.

Functions

fetch_lifi_quote(from_chain_id, to_chain_id, ...)

Fetch a cross-chain quote from the LI.FI API.

Classes

LifiQuote

LI.FI cross-chain quote response.

class LifiQuote

Bases: object

LI.FI cross-chain quote response.

Contains all information needed to execute a cross-chain transfer, including the ready-to-sign transaction request.

source_chain_id: int

Source chain ID

target_chain_id: int

Target chain ID

from_token: str

Source token address

to_token: str

Destination token address

from_amount: int

Amount to send (raw, with decimals)

estimate_to_amount: int

Estimated amount to receive (raw, with decimals)

estimate_to_amount_min: int

Minimum guaranteed amount to receive including slippage (raw, with decimals)

gas_cost_usd: decimal.Decimal | None

Estimated gas cost in USD

execution_duration: int | None

Estimated execution duration in seconds

fetched_at: float

Unix timestamp (seconds) when this quote was fetched

data: dict

Full API response data for reference

get_transaction_request()

Get the transaction request from the quote.

This is the ready-to-sign transaction with from, to, data, value, gasLimit, gasPrice, and chainId.

Returns

Transaction request dict from LI.FI API

Return type

dict

get_age_seconds()

Seconds elapsed since this quote was fetched.

Returns

Age of the quote in seconds.

Return type

float

is_valid(max_age_seconds=120)

Check if this quote is still fresh enough to execute.

The LI.FI /v1/quote endpoint does not return an explicit expiry timestamp. This method uses a time-based heuristic: quotes older than max_age_seconds are considered stale because gas prices and bridge liquidity change rapidly.

Parameters

max_age_seconds (float) – Maximum acceptable age in seconds (default 120s)

Returns

True if the quote is younger than max_age_seconds.

Return type

bool

__init__(source_chain_id, target_chain_id, from_token, to_token, from_amount, estimate_to_amount, estimate_to_amount_min, gas_cost_usd, execution_duration, fetched_at, data)
Parameters
  • source_chain_id (int) –

  • target_chain_id (int) –

  • from_token (str) –

  • to_token (str) –

  • from_amount (int) –

  • estimate_to_amount (int) –

  • estimate_to_amount_min (int) –

  • gas_cost_usd (decimal.Decimal | None) –

  • execution_duration (int | None) –

  • fetched_at (float) –

  • data (dict) –

Return type

None

fetch_lifi_quote(from_chain_id, to_chain_id, from_token, to_token, from_amount, from_address, to_address=None, slippage=0.03, order='CHEAPEST', api_timeout=30)

Fetch a cross-chain quote from the LI.FI API.

Calls GET /v1/quote to get a bridge/swap quote with ready-to-sign transaction data.

Example:

from eth_defi.lifi.quote import fetch_lifi_quote
from eth_defi.lifi.constants import LIFI_NATIVE_TOKEN_ADDRESS

quote = fetch_lifi_quote(
    from_chain_id=1,  # Ethereum
    to_chain_id=42161,  # Arbitrum
    from_token=LIFI_NATIVE_TOKEN_ADDRESS,
    to_token=LIFI_NATIVE_TOKEN_ADDRESS,
    from_amount=10000000000000000,  # 0.01 ETH in wei
    from_address="0xYourWalletAddress",
)

tx_request = quote.get_transaction_request()
# Sign and send tx_request
Parameters
  • from_chain_id (int) – Source chain ID

  • to_chain_id (int) – Destination chain ID

  • from_token (str) – Source token address (use LIFI_NATIVE_TOKEN_ADDRESS for native token)

  • to_token (str) – Destination token address (use LIFI_NATIVE_TOKEN_ADDRESS for native token)

  • from_amount (int) – Amount to send in raw units (wei for ETH)

  • from_address (str) – Sender wallet address

  • to_address (str | None) – Recipient wallet address. If None, defaults to from_address.

  • slippage (float) – Maximum allowed slippage as a decimal (0.03 = 3%)

  • order (str) – Route preference: CHEAPEST or FASTEST

  • api_timeout (float) – API request timeout in seconds

Returns

Quote with transaction data ready for signing

Raises

LifiAPIError – If the API returns an error or no route is found

Return type

eth_defi.lifi.quote.LifiQuote