npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

langchain-x402

v1.0.0

Published

LangChain tools for x402 Engine — pay-per-call AI, crypto, and storage APIs via HTTP 402 micropayments

Readme

langchain-x402

LangChain tools for x402 Engine — pay-per-call AI, crypto, and storage APIs via HTTP 402 micropayments.

Give your LangChain agents the ability to generate images, execute code, transcribe audio, look up crypto prices, analyze wallets, and pin data to IPFS — all paid with stablecoins (USDC on Base/Solana, USDm on MegaETH).

Install

npm install langchain-x402 @langchain/core

Quick Start

import { createX402Tools } from "langchain-x402";

// Create all tools with shared config
const tools = createX402Tools({
  paymentHeader: process.env.X402_PAYMENT_HEADER,
});

// Or import individual tools
import { GenerateImageTool, CryptoPriceTool } from "langchain-x402";

const imageTool = new GenerateImageTool();
const priceTool = new CryptoPriceTool();

With a LangChain Agent

import { ChatOpenAI } from "@langchain/openai";
import { createToolCallingAgent, AgentExecutor } from "langchain/agents";
import { ChatPromptTemplate } from "@langchain/core/prompts";
import { createX402Tools } from "langchain-x402";

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

const prompt = ChatPromptTemplate.fromMessages([
  ["system", "You are a helpful assistant with access to x402 Engine APIs."],
  ["human", "{input}"],
  ["placeholder", "{agent_scratchpad}"],
]);

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

const result = await executor.invoke({
  input: "What's the current price of Bitcoin and Ethereum?",
});

Configuration

Tools accept an optional config object and/or read from environment variables:

| Config Key | Env Variable | Description | | --------------- | ---------------------- | ---------------------------------------- | | baseUrl | X402_BASE_URL | Gateway URL (default: https://x402engine.app) | | paymentHeader | X402_PAYMENT_HEADER | Pre-signed X-PAYMENT header for x402 | | devBypass | X402_DEV_BYPASS | Dev bypass token to skip payment |

Available Tools

Compute

| Tool | Description | Price | | ---------------------- | -------------------------------------------- | ----------- | | GenerateImageTool | AI image generation (fast/quality/text tiers) | $0.015-$0.12 | | ExecuteCodeTool | Sandboxed code execution (Python, JS, Bash, R) | $0.005 | | TranscribeAudioTool | Audio-to-text transcription (Deepgram Nova-3) | $0.10 |

Crypto Data

| Tool | Description | Price | | ---------------------- | -------------------------------------------- | ----------- | | CryptoPriceTool | Real-time cryptocurrency prices | $0.001 | | CryptoMarketsTool | Market rankings with detailed data | $0.002 | | CryptoHistoryTool | Historical price/volume/mcap data | $0.003 | | TrendingCryptoTool | Currently trending coins | $0.001 | | CryptoSearchTool | Search coins by name or symbol | $0.001 |

Blockchain Analytics

| Tool | Description | Price | | ------------------------ | ------------------------------------------ | ----------- | | WalletBalancesTool | Token balances across 20+ chains | $0.005 | | WalletTransactionsTool | Transaction history with labels | $0.005 | | WalletPnlTool | Portfolio profit/loss analysis | $0.01 | | TokenPricesTool | DEX-derived token prices (up to 200/req) | $0.005 | | TokenMetadataTool | Token metadata (name, symbol, decimals) | $0.002 |

Storage

| Tool | Description | Price | | ------------------- | --------------------------------------------- | ----------- | | PinJsonToIpfsTool | Pin JSON to IPFS, returns CID | $0.01 | | GetFromIpfsTool | Retrieve content from IPFS by CID | $0.001 |

How x402 Payment Works

x402 is an open protocol for HTTP-native micropayments. When a tool makes a request:

  1. If no payment header is configured, the API returns HTTP 402 with payment requirements
  2. The tool returns the payment details so your agent (or a higher-level system) can handle payment
  3. With a valid X-PAYMENT header, the request succeeds and the API responds normally

For automatic payment handling, use @x402/client to generate payment headers from a wallet.

Payment Networks

| Network | Stablecoin | Confirmation | | --------- | ---------- | ------------ | | Base | USDC | ~2s | | Solana | USDC | ~400ms | | MegaETH | USDm | ~10ms |

Extending

All tools extend X402BaseTool, which itself extends LangChain's StructuredTool. You can create custom tools by extending the base class:

import { z } from "zod";
import { X402BaseTool } from "langchain-x402";

class MyCustomTool extends X402BaseTool {
  name = "my_custom_tool";
  description = "My custom x402 tool";
  schema = z.object({ input: z.string() });

  async _call(input: { input: string }) {
    const res = await this.callApi("POST", "/api/my-endpoint", undefined, input);
    return this.formatResult(res);
  }
}

Links

License

MIT