Let users send, receive, and trade crypto directly in your Chainlit conversation. Add a wallet, place live trades, and accept payments — all from message actions, no page navigation required.
Chainlit makes it easy to build chat-based AI interfaces with persistent sessions, message history, and user authentication. Purple Flea adds the financial layer — so your chat app can actually move money.
Each Chainlit user session gets an associated crypto wallet. Check balance, send funds, and receive payments without leaving the chat.
Users describe trades in natural language. Your Chainlit agent interprets the intent, validates risk parameters, and executes on Hyperliquid — all in the chat thread.
Let users play provably fair casino games through conversational commands. "Bet 0.01 ETH on heads" → flip → result. Winnings sent instantly to their wallet.
Multi-turn conversations to negotiate and lock escrow agreements between two parties. Chainlit's session tracking makes multi-step escrow flows natural.
Search available domains, check prices, and register with crypto — all through a conversational interface powered by Chainlit + Purple Flea domain API.
Generate one-time payment links inside the chat. Share with users, track completion, auto-release on confirmation. Ideal for freelance payment collection.
A complete Chainlit app that lets users check their portfolio and place trades via natural language — under 80 lines of Python.
# Install: pip install chainlit httpx openai # Run: chainlit run app.py import chainlit as cl import httpx, json from openai import AsyncOpenAI PURPLE_FLEA_KEY = "your-api-key" oai = AsyncOpenAI() TOOLS = [ { "type": "function", "function": { "name": "get_portfolio", "description": "Get the user's current portfolio value and positions", "parameters": {"type": "object", "properties": {}} } }, { "type": "function", "function": { "name": "place_trade", "description": "Place a perpetual futures trade", "parameters": { "type": "object", "properties": { "symbol": {"type": "string", "description": "e.g. BTC, ETH, SOL"}, "side": {"type": "string", "enum": ["long", "short"]}, "size_usd": {"type": "number"}, "leverage": {"type": "number"} }, "required": ["symbol", "side", "size_usd"] } } } ] async def call_purple_flea(tool_name: str, args: dict) -> str: async with httpx.AsyncClient() as client: if tool_name == "get_portfolio": r = await client.get( "https://purpleflea.com/api/portfolio", headers={"X-API-Key": PURPLE_FLEA_KEY} ) elif tool_name == "place_trade": r = await client.post( "https://purpleflea.com/api/trade", json=args, headers={"X-API-Key": PURPLE_FLEA_KEY} ) return json.dumps(r.json()) @cl.on_message async def handle_message(message: cl.Message): history = cl.user_session.get("history", []) history.append({"role": "user", "content": message.content}) msg = cl.Message(content="") await msg.send() response = await oai.chat.completions.create( model="gpt-4o", messages=[{"role": "system", "content": "You are a crypto trading assistant. Help users manage their portfolio and place trades."}] + history, tools=TOOLS, stream=True ) async for chunk in response: delta = chunk.choices[0].delta if delta.content: await msg.stream_token(delta.content) # Handle tool calls if response.choices[0].message.tool_calls: for tc in response.choices[0].message.tool_calls: result = await call_purple_flea( tc.function.name, json.loads(tc.function.arguments) ) history.append({"role": "tool", "content": result, "tool_call_id": tc.id}) await msg.update() cl.user_session.set("history", history)
Add "Confirm Trade" and "Cancel" action buttons to trade confirmations. One click to execute, one to abort.
Persist wallet address and API key per user session. Each user has their own Purple Flea wallet automatically.
Show intermediate steps like "Checking balance... Validating trade... Executing on Hyperliquid..." for transparency.
Render portfolio charts, trade history tables, and price charts as rich elements inside the chat thread.
Gate crypto features behind Chainlit's built-in authentication. Users must log in before accessing their wallet.
Pre-populate the chat with starter prompts: "Show my portfolio", "What's BTC price?", "Place a $50 long".
Always ask for confirmation before executing trades. Chainlit's Action API makes this elegant — no extra UI needed.
import chainlit as cl @cl.on_message async def handle(message: cl.Message): # Parse trade intent (simplified) trade = {"symbol": "BTC", "side": "long", "size_usd": 500} # Ask for confirmation with action buttons actions = [ cl.Action(name="confirm", label="✓ Confirm Trade", value="confirm"), cl.Action(name="cancel", label="✗ Cancel", value="cancel"), ] await cl.Message( content=f"Placing **LONG $500 BTC** at 5x leverage. Confirm?", actions=actions ).send() @cl.action_callback("confirm") async def on_confirm(action: cl.Action): async with httpx.AsyncClient() as client: r = await client.post( "https://purpleflea.com/api/trade", json={"symbol": "BTC", "side": "long", "size_usd": 500, "leverage": 5}, headers={"X-API-Key": PURPLE_FLEA_KEY} ) trade_id = r.json()["trade_id"] await cl.Message(content=f"Trade executed. ID: `{trade_id}`").send() await action.remove() @cl.action_callback("cancel") async def on_cancel(action: cl.Action): await cl.Message(content="Trade cancelled.").send() await action.remove()
Chainlit excels at conversational UX — streaming responses, step visibility, session management. Purple Flea handles the financial infrastructure. Together, you can build a full-featured crypto-powered chat application in an afternoon, with no frontend engineering required beyond Python.
Get a Purple Flea API key and combine it with Chainlit to build the next generation of financial chat interfaces.