LangChain + BananaCrystal: Complete Agent Wallet Integration Guide — BananaCrystal
Integration Guide

LangChain + BananaCrystal: complete integration guide

A step-by-step guide to connecting a LangChain agent to BananaCrystal's MCP server — giving it the ability to check balances, transfer stablecoins, swap currencies, and handle fiat operations autonomously.

BananaCrystal EngineeringMarch 202615 min read
What you will have after this guide: A LangChain agent with a live BananaCrystal wallet that can check its balance, execute stablecoin transfers, swap currencies, and initiate fiat operations — all autonomously, within configurable spending limits.

Prerequisites

  • Python 3.9+ or Node.js 18+
  • A BananaCrystal API key — get one free at agents.bananacrystal.com
  • LangChain installed (pip install langchain langchain-openai)
  • An OpenAI API key (or any LangChain-compatible LLM)

What you are building

You are building a LangChain agent with real financial autonomy. The agent will be able to check wallet balance, transfer stablecoins, swap currencies, get live exchange rates, view transaction history, and check spending limits.

Setting up BananaCrystal MCP

Step 1 — Install the SDK

terminal
# Python
pip install bananacrystal langchain langchain-openai langchain-mcp

# Node.js
npm install @bananacrystal/sdk langchain @langchain/openai @langchain/mcp-adapters

Step 2 — Set environment variables

.env
BANANACRYSTAL_API_KEY=bc_live_xxxxxxxxxxxx
BANANACRYSTAL_ENV=production
OPENAI_API_KEY=sk-xxxxxxxxxxxx

Step 3 — Initialize the client

setup.py
import bananacrystal as bc
import os

client = bc.Client(api_key=os.getenv("BANANACRYSTAL_API_KEY"))
wallet = client.wallets.get_or_create(
    agent_id="langchain-research-agent-v1",
    currency="USDC",
    spending_limit=50,
    max_tx_amount=10,
    allowed_currencies=["USDC", "USDb", "EURb"]
)

Creating the LangChain payment tool

payment_tool.py
from langchain.tools import tool

@tool
def transfer_payment(amount: float, recipient: str, currency: str = "USDb") -> str:
    """Transfer stablecoins to a recipient. Use for paying vendors or services."""
    result = client.transfers.send(
        from_wallet=wallet.id, to=recipient, amount=amount, currency=currency
    )
    return f"Transfer complete. TX: {result.tx_hash} · Fee: ${result.fee}"

Configuring spending limits

Spending limits are enforced at the infrastructure level — the agent cannot exceed them regardless of what the LLM decides.

  • spending_limit — maximum total spend per 24-hour rolling window
  • max_tx_amount — maximum single transaction amount
  • allowed_currencies — whitelist of currencies the agent can use
  • allowed_recipients — optional allowlist of recipient addresses

Building a full payment-capable agent

agent.py
from langchain.agents import AgentExecutor, create_openai_tools_agent
from langchain_openai import ChatOpenAI

llm = ChatOpenAI(model="gpt-4o", temperature=0)
tools = [transfer_payment, check_balance, get_exchange_rate]
agent = create_openai_tools_agent(llm, tools, prompt)
executor = AgentExecutor(agent=agent, tools=tools, verbose=True)

result = executor.invoke({
    "input": "Pay vendor-api-7g2 $12.50 for API usage this month"
})

Production checklist

  • Set BANANACRYSTAL_ENV=production (not sandbox)
  • Configure spending limits appropriate for your use case
  • Use separate API keys per agent for independent audit trails
  • Enable webhook notifications for transaction confirmations
  • Test with small amounts before increasing limits
You're done. Your LangChain agent now has a live wallet, can transfer stablecoins, swap currencies, and handle fiat — all within the spending limits you configured.
Continue reading
How MCP payments work — the complete technical flow