lifi.api
Documentation for eth_defi.lifi.api Python module.
LI.FI API utilities.
Helpers for interacting with the LI.FI REST API.
Functions
|
Fetch native token USD prices for multiple chains. |
|
Fetch the status of a cross-chain transfer from the LI.FI API. |
|
Fetch the USD price of a token using the LI.FI token endpoint. |
Get LI.FI API base URL. |
|
Get HTTP headers for LI.FI API requests. |
Exceptions
Error returned by LI.FI API. |
- exception LifiAPIError
Bases:
ExceptionError returned by LI.FI API.
- __init__(*args, **kwargs)
- __new__(**kwargs)
- add_note()
Exception.add_note(note) – add a note to the exception
- with_traceback()
Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.
- get_lifi_headers()
Get HTTP headers for LI.FI API requests.
Reads the optional
LIFI_API_KEYenvironment variable. If not set, logs a warning and returns headers without authentication. Without an API key, the rate limit is 10 requests per second.- Returns
Headers dict, possibly containing
x-lifi-api-key- Return type
- fetch_lifi_token_price_usd(chain_id, token_address='0x0000000000000000000000000000000000000000', api_timeout=30)
Fetch the USD price of a token using the LI.FI token endpoint.
Uses
GET /v1/tokenwhich returnspriceUSDfor any supported token.- Parameters
- Returns
Token price in USD
- Raises
LifiAPIError – If the API returns an error or price is unavailable
- Return type
- fetch_lifi_status(tx_hash, from_chain_id=None, to_chain_id=None, api_timeout=30)
Fetch the status of a cross-chain transfer from the LI.FI API.
Uses
GET /v1/statusto check whether a bridge transaction has been delivered on the destination chain.The response contains a
statusfield with one of:PENDING— transfer in progressDONE— transfer completed successfullyFAILED— transfer unsuccessfulNOT_FOUND— transaction hash not recognised yetINVALID— hash not tied to a known bridge
- Parameters
- Returns
Full status response dict from LI.FI API
- Raises
LifiAPIError – If the HTTP request fails
- Return type
- fetch_lifi_native_token_prices(chain_ids, api_timeout=30)
Fetch native token USD prices for multiple chains.
Makes one API call per chain to the LI.FI token endpoint.
- Parameters
- Returns
Dict mapping chain_id to native token price in USD
- Raises
LifiAPIError – If any API call fails
- Return type