The typical LangChain agent can search the web, call APIs, and read documents — but the moment it has to decide whether a contract is safe to interact with, it has no tool for the job. It can fetch the source, sure. It cannot reliably tell you that the withdraw function has a reentrancy hole, or that the onlyOwner check doesn't actually protect the funds.
That gap is what the new audit_smart_contract tool in @minia2a/langchain 0.1.3 fills. It joins the existing search, call, and list tools, so an agent can now discover a service, call it, and — when a contract is involved — verify it before it acts.
audit_smart_contract takes contract source code and returns a structured findings list, with a risk level, in two tiers:
| Tier | Price | Coverage |
|---|---|---|
static | $2 / call | 10 deterministic patterns: reentrancy, access-control, integer overflow, unvalidated call, tx.origin, delegatecall, selfdestruct, block.timestamp, assert misuse, owner-change. Solidity only. |
ai | $20 / call | 3×-sampled AI deep audit — business-logic, economic, and cross-contract flaws. Solidity, Rust (Solana), and Move. |
The input is source code, not a deployed address. The service reads the .sol/.rs/.move contents you pass it, which means it works on not-yet-deployed contracts — the state you actually want to check before money moves.
npm install @minia2a/langchain zod @langchain/core
Set one environment variable — the Base wallet that pays the fee — and the tool is part of the default toolkit:
export MINIA2A_PRIVATE_KEY=0x... # signs the x402 payment locally
import { Minia2aToolkit } from "@minia2a/langchain";
const toolkit = new Minia2aToolkit();
const tools = toolkit.getTools(); // search, call, list, audit_smart_contract
The agent then calls it the way it calls any other tool — with the source and a tier:
await executor.invoke({
input: "Audit this contract for vulnerabilities:\n\n" + contractSource
});
The tool returns something an agent can act on directly: a risk level, a numbered list of findings, and — for the AI tier — an upgrade suggestion when one applies. A high-risk reentrancy finding becomes a stop condition the agent can check before it signs a transaction.
The payment model is the reason this works unattended. There is no API key to provision and no account to create. The wallet in MINIA2A_PRIVATE_KEY signs an exact-permit2 payment in USDC on Base locally — the key never leaves the agent's process — and the x402 facilitator settles it. The payment itself is the credential.
If the key is missing, the tool fails gracefully with a two-line instruction rather than crashing the agent's run: set the key, and make sure minia2a-audit is installed. An unattended agent can surface that to its operator instead of dying silently.
The honest limits. The static scan is deterministic but only knows its 10 patterns. The AI tier is probabilistic — it may miss a vulnerability or flag a non-issue. Treat the output as guidance for a human review, not as proof of safety or a substitute for a professional audit of a contract holding real value. The right pattern is a pre-check gate: run the $2 scan before interacting, escalate to $20 or a human only when something looks wrong.
The useful shape is not "audit everything." It is a gate. An agent that is about to deposit into a vault, approve a spender, or sign a transaction that moves funds runs the $2 scan first. If the scan returns clean, proceed. If it flags reentrancy or an unvalidated call, stop and escalate. Two dollars and a deterministic wait time are cheap insurance against a transaction whose downside is far larger.
This is the same "verification is attribution" logic that makes contract auditing the natural pay-per-call vertical: a finding is only worth money if it reproduces, so the output has to be structured enough for an agent to act on without a human in the loop.
Try the $2 scan on a contract you have already reviewed by hand and compare the findings to yours — that comparison tells you more about whether the tool fits your workflow than any benchmark number. Full details in the package README.