Skip to content
LayerHop

LayerHop for developers · Python SDK

The Python SDK for cross-chain swaps

layerhop is the Python client for the LayerHop API, with a sync LayerHop class and an async AsyncLayerHop class. It needs Python 3.9 or newer and depends only on httpx. Call quote(), build_tx() and report_submitted(), then iterate watch(); the SDK returns unsigned transactions and your own wallet library signs them.

Install
pip install layerhop

How to use the SDK

  1. 1

    Install and create a client

    pip install layerhop, then LayerHop() or LayerHop(api_key=..., integrator=...). No key is needed to try it.

  2. 2

    Get a quote

    lh.quote(src_chain, src_token, amount, dst_chain, dst_token, sender=..., recipient=...) returns a dict with best, quotes and errors. Amounts are base-unit strings.

  3. 3

    Build the unsigned transaction

    lh.build_tx(best["quoteId"]) returns the transaction as a dict (vm is evm or svm).

  4. 4

    Have the user's wallet sign and send it

    For an EVM chain, send tx.approval first when it is present, then the main transaction (to, data, value) on tx.chainId. For Solana, sign the base64 VersionedTransaction; when submitViaApi is true, send the signed bytes through LayerHop instead of an RPC node.

  5. 5

    Report and track

    lh.report_submitted(quote_id, tx_hash), then iterate lh.watch(provider, tx_hash) until the order is final.

Code

Copy, then replace the addresses and the key.

Quote, build, report and track
from layerhop import LayerHop

lh = LayerHop()  # LayerHop(api_key="lh_live_...", integrator="myapp")

# 1. Quote: 100 USDC on Base -> SOL on Solana (amounts are base-unit strings)
q = lh.quote("base", "USDC", "100000000", "solana", "SOL",
             sender="0xYourEvmAddress", recipient="YourSolanaAddress")
best = q["best"]
print(best["provider"], best["dstAmount"], best["fees"]["ourFeeBps"])

# 2. Build the unsigned transaction
tx = lh.build_tx(best["quoteId"])

# 3. Sign and send it with YOUR wallet library (web3.py shown; w3 is your instance)
if tx["vm"] == "evm":
    # send tx["approval"] first when present
    tx_hash = w3.eth.send_transaction({"to": tx["to"], "data": tx["data"],
                                       "value": int(tx["value"]), "chainId": tx["chainId"]}).hex()

# 4. Report the broadcast, then track it
lh.report_submitted(best["quoteId"], tx_hash)
for s in lh.watch(best["provider"], tx_hash):
    print(s["state"])  # pending, then filled / refunded / failed
The async client
from layerhop import AsyncLayerHop

async with AsyncLayerHop() as lh:
    q = await lh.quote("base", "USDC", "100000000", "solana", "SOL", sender=s, recipient=r)
    async for st in lh.watch(q["best"]["provider"], tx_hash):
        print(st["state"])

What works today, and what doesn't

So you know before you build.

Works today

  • Sync and async clients that mirror the TypeScript SDK
  • Quotes, exact-output quotes, live quote streams, orders, order tracking, checkout sessions and webhook signature verification
  • Depends only on httpx

Good to know

  • It never signs: use web3.py, eth-account, solders or a KMS for that
  • Quotes expire within about 30 to 60 seconds
  • Providers are mainnet only; use an lh_test_ key to develop without real funds

Questions

Do I need an API key?

Not to try it: requests without a key work under a per-IP rate limit. For production, sign in to the dashboard with a wallet and create a key (lh_live_…, sent in the x-api-key header). A key gets its own rate limit, shows your usage and logs, and lets your orders trigger webhooks. lh_test_ keys give sandbox quotes and simulated orders.

What does it cost?

LayerHop's fee on a trade made through the API channel is 0.10% of the input amount, reported on every quote as fees.ourFeeBps next to the provider's fees and gas. Partners can add their own fee on top.

Does it hold keys or sign transactions?

No. It returns unsigned transactions and your own wallet library (viem, ethers, web3.py, go-ethereum, alloy, a Solana wallet, a KMS) signs and broadcasts them. LayerHop never holds funds or keys.

Which Python versions work?

Python 3.9 and newer.

Is there an async client?

Yes: AsyncLayerHop, used as an async context manager, with the same methods awaited.