Cross-chain gas feeding with LI.FI

Here is a Python example showing how to keep hot wallets funded with gas across multiple EVM chains using LI.FI.

Overview

  • Checks native token gas balances on target chains

  • Fetches USD prices from the LI.FI token API

  • Identifies chains running low on gas (below a configurable USD threshold)

  • Fetches bridge quotes from LI.FI to bridge native tokens from a source chain

  • Optionally executes bridge transactions with human approval

Chain names are resolved using our internal names from eth_defi.chain.CHAIN_NAMES (e.g. “ethereum”, “arbitrum”, “base”), converted to numeric chain IDs, and passed to the LI.FI API which also uses numeric chain IDs.

Prerequisites

  • Native tokens on your source chain (e.g. ETH on Arbitrum)

  • JSON-RPC endpoints for all chains involved (JSON_RPC_* environment variables)

  • Optional: a LI.FI API key for higher rate limits

Environment variables

# Hot wallet private key
export PRIVATE_KEY=0x...
# Source chain (where funds are bridged from)
export SOURCE_CHAIN=arbitrum
# Target chains (comma-separated, where gas is needed)
export TARGET_CHAINS=base,polygon,ethereum
# Minimum gas balance in USD before triggering a top-up
export MIN_GAS_USD=5
# Amount to bridge in USD when topping up
export TOP_UP_GAS_USD=20
# Optional: LI.FI API key
export LIFI_API_KEY=...
# Optional: set to true to only show quotes without executing
export DRY_RUN=true

Running the example

source .local-test.env && \
poetry run python scripts/lifi/feed-cross-chain.py

The script will display a balance table and proposed swaps, then ask for confirmation before executing. Set DRY_RUN=true to skip execution entirely.

API documentation

See LI.FI API reference for the module documentation.

Source code

"""Feed gas to hot wallets across multiple chains using LI.FI.

Checks native token gas balances on target chains and bridges
gas from a source chain when any target is running low.

See :py:mod:`eth_defi.lifi.top_up` for the full implementation and
environment variable reference.

Usage:

.. code-block:: shell

    export PRIVATE_KEY=<...>
    export DRY_RUN=true
    export SOURCE_CHAIN=arbitrum
    export TARGET_CHAINS="base, ethereum, monad, hyperliquid, avalanche"
    export MIN_GAS_USD=5
    export TOP_UP_GAS_USD=10
    python scripts/lifi/feed-cross-chain.py

"""

from eth_defi.lifi.top_up import perform_top_up


def main():
    perform_top_up()


if __name__ == "__main__":
    main()