Prerequisites
- Node.js 18+ or Python 3.11+
- A LangChain agent (we'll use
createReactAgent from langchain/agents)
- A free Proco account — sign up here
- ~20 minutes
1 Install the SDK
Proco's SDK wraps the payment primitives and provides a pre-built LangChain tool you can drop straight into your agent's tool list:
terminal
npm install @proco/sdk @proco/langchain
2 Provision an agent wallet
Run this once to create a persistent identity for your agent. The wallet address is deterministic — the same agentId always produces the same address, so you can redeploy without losing the agent's payment history.
provision.ts
import { ProcoAgent } from '@proco/sdk';
const agent = await ProcoAgent.create({
agentId: 'langchain-research-agent',
label: 'Research Agent (LangChain)',
network: 'base',
spendingPolicy: {
maxPerTransaction: '1.00',
dailyLimit: '20.00',
},
});
console.log('Wallet address:', agent.walletAddress);
// Save this — you'll reference it in your agent config
Then fund the agent wallet from your Proco dashboard or via the SDK:
fund.ts
import { ProcoTreasury } from '@proco/sdk';
const treasury = new ProcoTreasury({
apiKey: process.env.PROCO_API_KEY
});
await treasury.fundAgent({
agentId: 'langchain-research-agent',
amount: '10.00', // Fund with $10 to start
});
3 Create the payment tool
The @proco/langchain package exports a ProcoPaymentTool that wraps the wallet and exposes it as a LangChain StructuredTool. The agent uses the tool's description to decide when to invoke it:
tools/payment.ts
import { ProcoPaymentTool } from '@proco/langchain';
export const paymentTool = new ProcoPaymentTool({
agentId: 'langchain-research-agent',
apiKey: process.env.PROCO_API_KEY!,
description: `
Use this tool to pay for external services, APIs, or data.
Input: { recipient: string, amount: string, memo: string }
- recipient: wallet address or vendor identifier
- amount: USD amount as a string, e.g. "0.05"
- memo: brief description of what you're paying for
Returns a payment receipt with transaction ID.
`,
});
4 Add an x402-aware fetch tool
For APIs that use the x402 protocol, Proco intercepts the 402 response and handles payment automatically. Wrap your HTTP calls with ProcoFetchTool to get this behavior:
tools/fetch.ts
import { ProcoFetchTool } from '@proco/langchain';
export const fetchTool = new ProcoFetchTool({
agentId: 'langchain-research-agent',
apiKey: process.env.PROCO_API_KEY!,
description: `
Fetch data from a URL. Handles x402 payment requests automatically.
Input: { url: string, method?: string }
Returns the response body as a string.
`,
});
5 Wire the tools into your agent
Add the Proco tools to your existing tool list and pass them to createReactAgent:
agent.ts
import { createReactAgent } from 'langchain/agents';
import { ChatAnthropic } from '@langchain/anthropic';
import { paymentTool } from './tools/payment';
import { fetchTool } from './tools/fetch';
import { searchTool, calcTool } from './tools/existing';
const llm = new ChatAnthropic({ model: 'claude-3-5-sonnet-20241022' });
const agent = await createReactAgent({
llm,
tools: [
searchTool, // your existing tools
calcTool,
paymentTool, // Proco payment tool
fetchTool, // x402-aware HTTP fetch
],
});
const result = await agent.invoke({
input: `
Research the current market cap of the top 5 AI infrastructure companies.
Use the market data API at https://data.example.com if needed — it may require payment.
Summarize the findings and tell me how much you spent.
`,
});
console.log(result.output);
6 Add a spend reporting tool
It's useful to give the agent visibility into its own spending — both for self-reporting in responses and for making cost-aware decisions about which APIs to use:
tools/spend.ts
import { ProcoSpendTool } from '@proco/langchain';
export const spendTool = new ProcoSpendTool({
agentId: 'langchain-research-agent',
apiKey: process.env.PROCO_API_KEY!,
description: `
Check your current spending balance and transaction history.
Input: { period?: "today" | "week" | "month" }
Returns current balance, amount spent in period, and recent transactions.
`,
});
Now your agent can say things like "I've spent $0.43 today, mainly on market data lookups" — because it actually has access to that information as a tool call.
7 Test in sandbox mode
Proco's sandbox environment lets you test the full payment flow without executing real transactions. Set PROCO_ENV=sandbox in your environment variables and all payments will be simulated — but the API behavior is identical to production:
terminal
PROCO_ENV=sandbox PROCO_API_KEY=sk_sandbox_... npx ts-node agent.ts
Sandbox tip: The sandbox mirrors the production policy enforcement engine. If your spending policy would block a payment in sandbox, it will block it in production too. Test your policy boundaries in sandbox before going live.
8 Deploy and monitor
Once you're satisfied with sandbox behavior, switch to production credentials and deploy. Your Proco dashboard will show per-agent transaction history, balance alerts, and any policy violations — all attributed to the langchain-research-agent identity you created in step 2.
What to read next