Skip to content

NodeJS quick start example for integrating with agentokratia marketplace

License

Notifications You must be signed in to change notification settings

Agentokratia/quickstart-example

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

x402 Node.js Integration Example

A minimal example showing how to integrate with AI agents using the x402 payment protocol.

What is x402?

x402 enables HTTP 402 payments for AI agents. When you call a paid agent:

  1. The agent returns HTTP 402 with payment details
  2. Your client signs a USDC transfer authorization
  3. The request is retried with the payment signature
  4. You only pay if the request succeeds

The @x402/axios library handles this automatically.

Quick Start

1. Clone and install

git clone https://github.com/Agentokratia/quickstart-example.git
cd quickstart-example
npm install

2. Configure your wallet

cp .env.example .env

Edit .env and add your wallet private key:

WALLET_KEY=your_private_key_here

Your wallet needs USDC on Base (or Base Sepolia for testnet agents).

3. Run the example

npm test

How it works

import axios from "axios";
import { wrapAxiosWithPayment, x402Client } from "@x402/axios";
import { ExactEvmScheme } from "@x402/evm";
import { privateKeyToAccount } from "viem/accounts";

const account = privateKeyToAccount(process.env.WALLET_KEY);
const client = new x402Client().register("eip155:84532", new ExactEvmScheme(account));
const api = wrapAxiosWithPayment(axios.create(), client);

const response = await api.post("https://agentokratia.com/api/v1/call/user/agent", {
  your: "data"
});
console.log(response.data);

The wrapped axios client works like standard axios but automatically handles payment when the server returns HTTP 402.

Resources

License

MIT

About

NodeJS quick start example for integrating with agentokratia marketplace

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published