Skip to main content
HomeLanding pagesLangChain wallet tool
LANDING PAGE

LangChain wallet tool

8 min read·Last updated June 2, 2026

A LangChain wallet tool is a DynamicStructuredTool that wraps the x402 client, so the agent can pay any endpoint that returns HTTP 402 in USDC on Base by calling one tool. Build it once around createX402Client from @blockchain0x/x402, add it to the agent's tools, and the agent transacts through it. There is no LangChain wallet package; the tool is the pattern.

What the wallet tool is

A LangChain wallet tool is a single reusable tool that gives an agent the ability to pay. Under the hood it wraps the x402 client, so when the agent calls the tool with a target, the tool fetches it, settles any 402 in USDC on Base, and returns the result. The agent gets a wallet the way it gets any capability in LangChain: as a tool in its tools list.

There is no Blockchain0x LangChain package to install. The wallet tool is a pattern you build from @blockchain0x/node and @blockchain0x/x402, which keeps it honest and on the verified surface. This page is the focused artifact; for the broader integration overview see langchain-payment-integration, and for the task walkthrough see how-to-add-payments-to-langchain-agent. The payment API product page is the reference.

What it exposes to the agent

Keep the tool's surface small and clear, because the agent reasons about it from its description. The core operation is pay-by-calling: give the tool a URL (and optionally a method and body) and it returns the response, having settled any payment along the way. That single operation covers the common case, an agent paying for data, an API, or another agent's service.

You can extend the same tool with a read operation so the agent can see its own budget, the spend limit enforced on its wallet, which lets a planner avoid attempting a call it cannot afford. Beyond pay and read-limit, resist adding more; the wallet tool is most useful when it does one obvious thing. The wallet's spend limit, set in the dashboard, is what bounds whatever the tool does, so the tool itself does not need to enforce budgets. A common temptation is to add a "send payment to address X" operation; think hard before you do, because an open-ended send tool is a much larger attack surface than a pay-for-what-you-call tool, and the pay-by-calling shape is enough for almost every agent use case. Keep the tool to what the agent genuinely needs and let the wallet limit be the backstop.

Build the tool

The whole tool is a DynamicStructuredTool wrapping fetchWithPay.

TYPESCRIPT
import { DynamicStructuredTool } from "@langchain/core/tools";
import { createClient } from "@blockchain0x/node";
import { createX402Client } from "@blockchain0x/x402/client";
import { z } from "zod";

const sdk = createClient({ apiKey: process.env.B0X_API_KEY! });
const fetchWithPay = createX402Client({ sdk });

export const walletTool = new DynamicStructuredTool({
  name: "pay_and_fetch",
  description: "Fetch a URL, paying in USDC if it requires payment. Returns the response body.",
  schema: z.object({ url: z.string(), method: z.string().optional(), body: z.string().optional() }),
  func: async ({ url, method, body }) => {
    const res = await fetchWithPay(url, { method: method ?? "GET", body });
    return res.ok ? await res.text() : `Request failed with status ${res.status}.`;
  },
});

Add it to any agent with tools: [walletTool, /* ... */]. That is the wallet tool: one definition, reusable across agents, and the only payment code in your stack.

Add a balance-aware read

To let the agent reason about budget, add a second tool that reads the spend limit. It is a plain GET, so it stays simple:

TYPESCRIPT
export const limitTool = new DynamicStructuredTool({
  name: "check_spend_limit",
  description: "Return this agent's current spend limit (per-transaction cap and period allowance).",
  schema: z.object({}),
  func: async () => {
    const res = await fetch(
      `https://api.blockchain0x.com/v1/agents/${process.env.AGENT_ID}/spend-permissions`,
      { headers: { Authorization: `Bearer ${process.env.B0X_API_KEY!}` } },
    );
    return await res.text(); // per_tx_wei, allowance_wei, period_seconds
  },
});

Give the planner both tools and it can check the limit before a large purchase. The limit is still enforced by the wallet regardless, so this read is for smarter planning, not for safety, the safety is the server-side cap.

Compatibility

Because the wallet tool is an ordinary DynamicStructuredTool, it works wherever LangChain tools work.

LangChain surface Works? Notes
AgentExecutor Yes Add the tool to the executor's tools
createToolCallingAgent Yes The common shape in 2026
create_react_agent Yes The ReAct prompt reads the tool description
LangGraph nodes Yes Put the tool in the node's tool list
TypeScript runtime Yes The x402 client ships for Node
Python runtime Via a Node proxy The client is Node-only; a Python tool calls a local proxy, as in the CrewAI guide

When to use it

Reach for the wallet tool when an agent needs to pay for things it calls and you want that capability packaged as one reusable unit rather than threaded through each tool. It is the right shape when several agents share the same paying behavior, since you build the tool once and add it everywhere, and when you want payment to be a first-class capability the planner can invoke deliberately.

It is the wrong shape when only one specific tool should ever pay, in which case wrap that tool's own fetch directly rather than giving the agent a general pay capability, and when the agent is purely internal with one trusted endpoint and a shared key, where a wallet adds nothing. Match the tool to whether paying is a general capability the agent should have or a one-off behavior of a single tool.

One wallet tool, many agents

The reusability is the point, so use it. In a multi-agent system, you do not write payment code per agent; you build the wallet tool once and add it to whichever agents should be able to pay. Each agent still has its own wallet and its own spend limit, so giving them the same tool does not pool their money; the tool is shared code, the wallets are separate accounts.

Bind each agent's tool to that agent's key so the right wallet pays. The cleanest pattern is a small factory that takes a key and returns a wallet tool bound to it:

TYPESCRIPT
export function makeWalletTool(apiKey: string) {
  const sdk = createClient({ apiKey });
  const fetchWithPay = createX402Client({ sdk });
  return new DynamicStructuredTool({
    name: "pay_and_fetch",
    description: "Fetch a URL, paying in USDC if required.",
    schema: z.object({ url: z.string() }),
    func: async ({ url }) => {
      const res = await fetchWithPay(url);
      return res.ok ? await res.text() : `Failed: ${res.status}`;
    },
  });
}

Now makeWalletTool(researcherKey) and makeWalletTool(writerKey) give two agents the same capability on their own wallets, with per-agent attribution and limits intact. Build the pattern once, reuse it across the fleet.

Pricing

The tool is free; you build it from open packages. What you pay is the wallet platform fee per agent on the pricing page: Free is $0 per agent per month at a 5% transaction fee, Pro is $9 at 2%, and Business is $29 at 1%. Per-agent pricing means you pay for the agents that actually transact through the tool, not a flat seat. Start on Free, read your real volume, and move the busiest agents to Pro when the math favors it.

What to ship today

Build the pay_and_fetch wallet tool around createX402Client, add it to an agent's tools, and make one paid call on Base Sepolia. Add the check_spend_limit read if the planner should reason about budget. For the full integration overview see langchain-payment-integration. Pricing is on the pricing page.

FAQ

Frequently asked questions.

Is there a LangChain wallet package from Blockchain0x?

No, and you do not need one. The wallet tool is a small DynamicStructuredTool you build around createX402Client from @blockchain0x/x402, depending only on that and @blockchain0x/node. There is no dedicated LangChain adapter package; the tool is a pattern you assemble from the real client, which keeps every identifier on the verified surface.

What does the wallet tool let the agent do?

Pay. The agent calls the tool with a target, and the tool fetches it through the x402 client, which settles any HTTP 402 in USDC on Base and returns the result. You can extend the same tool to read the agent's spend limit so it can reason about budget, but the core capability is paying for what it calls.

How is this different from the LangChain payment integration page?

The integration page is the broad reference for adding payments to a LangChain agent. This page is about one concrete artifact: a reusable wallet tool you can drop into any agent. Same underlying client, narrower focus. Use the integration page for the overview and this for the tool you actually add to tools=[].

Does the agent need to know it is spending money?

Not necessarily. To the planner the wallet tool looks like any other tool that returns a result; the payment happens inside it. You can surface cost in the tool description if you want the planner to weigh it, but the default is that the tool pays transparently, bounded by the wallet's spend limit, and returns the result.

Which network and token does it use?

USDC, 6 decimals, on Base. A sk_test_ key settles on Base Sepolia (eip155:84532), a sk_live_ key on Base mainnet (eip155:8453). The SDK reads the network from the key prefix, so the same tool works on either by swapping the key.

Create your free agent wallet in 5 minutes.

First payment confirmed in under ten minutes. Free to start.