Skip to main content
LangChain’s DynamicStructuredTool lets you expose any HTTP endpoint as a callable tool inside an agent graph. By combining it with createAgentClient from @meterlane/x402/client, your agent handles x402 payment negotiation invisibly — it sends a request, receives 402 if unpaid, signs an ERC-3009 USDC authorization, and retries with the payment header, all before returning a result to the model.
All examples on this page target Base Sepolia (eip155:84532) and the public sandbox demo route. Do not use mainnet keys or mainnet URLs in development or CI.
1

Install dependencies

You need @langchain/core for the tool primitive, zod for the parameter schema, and @meterlane/x402 for the payment client.
Import the MIT-licensed client entry point specifically — not the server middleware:
2

Set your environment variable

Never hard-code your private key in source files or commit it to version control. Store it in an environment variable and load it at runtime. Use a dedicated hot wallet funded only with the USDC you need for testing — do not reuse cold-storage or exchange keys.
Create a .env file (and add it to .gitignore):
Get test USDC for Base Sepolia from the Circle faucet — select Base Sepolia before requesting.
3

Build the tool

Save the following as langchain-meterlane-tool.ts. The tool calls the public sandbox demo route, but you can replace the URL with any active Meterlane gateway route.
Run the smoke test directly:
You should see the first 200 characters of the demo route’s 200 response body.
4

Register the tool with your agent

Wire meterlanePaidGetTool into your agent the same way you would any other LangChain tool — via bindTools, a ReAct executor, or a LangGraph tool node:
The agent decides when to call the tool; createAgentClient handles the 402 → pay → retry cycle transparently each time.

How it works

When your tool calls paidFetch(url) instead of raw fetch, the following happens automatically:
  1. The client sends the original GET request.
  2. If the server returns 402, it reads the X-Payment-Requirements header for the USDC amount and receiver address.
  3. ExactEvmScheme uses your private key to produce an ERC-3009 signed authorization on Base Sepolia.
  4. The client retries the request with the payment authorization header attached.
  5. On 200, your tool function receives the response body and returns it to the model.
The MIT license on @meterlane/x402/client means you can — and should — audit the payment logic before running it with a funded wallet.