Skip to content

PayNodeLabs/paynode-sdk-js

Repository files navigation

PayNode JavaScript SDK

Official Documentation NPM Version

The official TypeScript/JavaScript SDK for the PayNode Protocol. PayNode is a stateless, non-custodial M2M payment gateway that standardizes the HTTP 402 "Payment Required" flow for AI Agents, settling instantly in USDC on Base L2.

📖 Read the Docs

For complete installation guides, advanced usage, API references, and architecture details, please visit our official documentation: 👉 docs.paynode.dev

⚡ Quick Start

Installation

npm install @paynodelabs/sdk-js ethers

Agent Client (Payer)

import { PayNodeAgentClient } from "@paynodelabs/sdk-js";

const client = new PayNodeAgentClient("YOUR_AGENT_PRIVATE_KEY", ["https://mainnet.base.org", "https://rpc.ankr.com/base"]);

async function main() {
  // Automatically handles 402 challenges, pays USDC, and retries the request
  const response = await client.requestGate("https://api.merchant.com/premium-data");
  console.log(await response.text());
}
main();

🚀 Run the Demo

The SDK includes a full merchant/agent demonstration in the examples/ directory.

1. Setup Environment

cp .env.example .env
# Edit .env with your PRIVATE_KEY and RPC_URL

2. Get Test Tokens (Required for Base Sepolia)

If you're testing on Sepolia, run the helper script to mint 1,000 mock USDC:

npx ts-node examples/mint-test-tokens.ts

3. Run the Merchant Server (Express)

npx ts-node examples/express-server.ts

4. Run the Agent Client

In another terminal:

npx ts-node examples/agent-client.ts

The demo will perform a full loop: 402 Handshake -> On-chain Payment -> 200 Verification.


📦 Publishing to NPM

To publish a new version of the SDK:

  1. Build the project:
    npm run build
  2. Login to NPM (if not already):
    npm login
  3. Publish:
    npm publish --access public

Built for the Autonomous AI Economy by PayNodeLabs.

About

Node.js/TypeScript middleware for merchants to intercept API requests and verify on-chain x402 payments.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors