DEV Community

Cover image for 💧 Give Your LangChain Agent a Smart Wallet on Base
Mr Hamlin
Mr Hamlin

Posted on

💧 Give Your LangChain Agent a Smart Wallet on Base

Your AI agent can write emails, search the web, and query databases. But can it deploy a smart wallet?

Now it can.

I just published @spraay/langchain-agent-wallet — 5 LangChain StructuredTool classes that let your agent provision smart wallets, manage session keys, and predict wallet addresses on Base. Every call is paid with USDC micropayments via the x402 protocol. No API keys. No subscriptions. Just pay-per-call.

The Problem

AI agents are getting good at planning and reasoning. But when it comes to actually holding money and executing transactions, most frameworks punt. You end up with the agent's private key embedded in code, full access to everything, zero permission scoping.

That's not how you'd let a human employee operate. Why let your agent?

The Solution: Agent Wallets with Session Keys

Spraay's Agent Wallet infrastructure deploys a smart contract wallet for each agent on Base. The wallet is owned by you, but the agent gets a session key — a scoped, time-limited permission to act on behalf of the wallet.

Think of it like giving an employee a corporate card with a spending limit instead of handing them the company bank login.

The 5 Tools

npm install @spraay/langchain-agent-wallet @langchain/core
Enter fullscreen mode Exit fullscreen mode
Tool What it does Cost
spraay_provision_wallet Deploy a new smart wallet on Base $0.05
spraay_add_session_key Grant scoped permissions to an address $0.02
spraay_get_wallet_info Query wallet details and balance $0.005
spraay_revoke_session_key Remove a session key $0.02
spraay_predict_address Pre-compute CREATE2 wallet address $0.001

Quick Start

import { ChatOpenAI } from "@langchain/openai";
import { createToolCallingAgent, AgentExecutor } from "langchain/agents";
import { ChatPromptTemplate } from "@langchain/core/prompts";
import { createSpraayWalletTools } from "@spraay/langchain-agent-wallet";

// Create all 5 tools with one function
const tools = createSpraayWalletTools({
  privateKey: process.env.EVM_PRIVATE_KEY!,
});

const llm = new ChatOpenAI({ model: "gpt-4o" });

const prompt = ChatPromptTemplate.fromMessages([
  ["system", "You are a Web3 agent that manages smart wallets on Base."],
  ["human", "{input}"],
  ["placeholder", "{agent_scratchpad}"],
]);

const agent = createToolCallingAgent({ llm, tools, prompt });
const executor = new AgentExecutor({ agent, tools });

// The agent decides which tool to call based on natural language
const result = await executor.invoke({
  input: "Deploy a new wallet for 0x1234...abcd labeled 'treasury'",
});
Enter fullscreen mode Exit fullscreen mode

The LLM reads the tool descriptions and zod schemas to figure out which tool to call and what parameters to pass. You don't write any routing logic.

How x402 Payments Work

Every tool call hits the Spraay gateway at gateway.spraay.app. Instead of an API key, the request includes a signed payment header — your agent's private key authorizes a USDC micropayment on Base.

The gateway verifies the signature, settles the payment, and executes the operation. It's like HTTP 402 (Payment Required) actually working the way it was supposed to.

This means:

  • No API keys to manage or rotate
  • No rate limits — you pay for what you use
  • No subscription tiers — $0.001 to $0.05 per call
  • Permissionless — any agent with USDC on Base can use it

What's Deployed

The wallet contracts are live on Base mainnet:

  • Factory: 0xFBD832Db6D9a05A0434cd497707a1bDC43389CfD
  • Implementation: 0x61818Ae8bC161D1884Fd8823985B80e6733C34E7

The gateway serves 76+ paid endpoints across 16 categories and 13 chains. Agent Wallet is Category 17.

What's Next

This is one piece of a bigger push to get Spraay tooling into every major agent framework:

If your agent needs to hold money, send payments, or manage wallets — and you don't want to hand it your private key — give this a try.

npm: @spraay/langchain-agent-wallet
GitHub: plagtech/langchain-spraay-wallet
Docs: docs.spraay.app


Built by @lostpoet / @Spraay_app

Top comments (0)