Examples · Copy-paste flows

Pick an example and run it.

Start with Plain Node — it's the fastest path to a working payment without any AI SDK in the way. Once that confirms, swap in the Claude or OpenAI example.

Start here

New here? Start with Plain Node.

Use the first example below if you want the fastest path to a real payment. It is the clearest way to learn Oryn before adding Claude or OpenAI.

Use Base Sepolia first.
Use two wallets: one payer, one recipient.
Make sure the payer has ETH and USDC.
Use the live ORYN_PAYMENT_CONTRACT_ADDRESS.
v1 rule: one wallet can register one permanent agent ID.
One wallet = one agent identity

If your system has multiple agents, each needs its own wallet and private key. Use PRIVATE_KEY for the sender and a separate RECIPIENT_PRIVATE_KEY for the receiver — this is intentional design, not example scaffolding.

1. Plain Node.js
Best first example · simplest mental model
NodeTypeScriptTwo wallets

Use this first if you want to understand Oryn itself without any AI SDK in the way. One wallet acts as the sender agent, another as the recipient agent, and the payer sends USDC after both identities exist onchain.

import { OrynSDK } from "@oryn/sdk";

const payer = new OrynSDK({
  contractAddress: process.env.ORYN_PAYMENT_CONTRACT_ADDRESS!,
  usdcAddress: "0x036CbD53842c5426634e7929541eC2318f3dCF7e",
  chainId: 84532
});

const recipient = new OrynSDK({
  contractAddress: process.env.ORYN_PAYMENT_CONTRACT_ADDRESS!,
  usdcAddress: "0x036CbD53842c5426634e7929541eC2318f3dCF7e",
  chainId: 84532
});

await payer.connect(process.env.PRIVATE_KEY!, process.env.BASE_SEPOLIA_RPC_URL!);
await recipient.connect(process.env.RECIPIENT_PRIVATE_KEY!, process.env.BASE_SEPOLIA_RPC_URL!);

await payer.registerAgent("planner-agent-001");
await recipient.registerAgent("compute-agent-001");

const fee = await payer.estimateFee(0.5);
console.log("Estimated fee:", fee, "USDC");

const receipt = await payer.pay("planner-agent-001", "compute-agent-001", 0.5);
console.log("Payment confirmed:", receipt.hash);

Required env vars

  • BASE_SEPOLIA_RPC_URL for Base Sepolia access
  • PRIVATE_KEY for the payer wallet
  • RECIPIENT_PRIVATE_KEY for the recipient wallet
  • ORYN_PAYMENT_CONTRACT_ADDRESS for the live Oryn contract

Wallet requirements

  • Payer wallet needs Base Sepolia ETH for gas
  • Payer wallet needs Base Sepolia USDC for the transfer
  • Recipient wallet needs a little ETH for registration gas
  • Use two separate wallets for a real first-run test

Expected output

You should see both wallets connect, the agent IDs register or get detected as already registered, a fee estimate print, and then a transaction hash from pay().

After the payment confirms, the recipient balance should increase and the payer balance should decrease by the sent amount plus any fee.

Use this when: you are building a backend workflow, queue worker, or orchestration service and you want the cleanest path to your first successful payment.
2. Claude agent pays a compute agent
Anthropic integration · task-driven payment
ClaudeAnthropic SDKStablecoin settlement

A Claude-powered agent receives a task, evaluates whether it needs outside help, and pays a registered compute agent only if it decides to delegate. The payment is conditional on the model's decision — not automatic.

import Anthropic from "@anthropic-ai/sdk";
import { OrynSDK } from "@oryn/sdk";

const anthropic = new Anthropic({ apiKey: process.env.ANTHROPIC_API_KEY! });
const oryn = new OrynSDK({
  contractAddress: process.env.ORYN_PAYMENT_CONTRACT_ADDRESS!,
  usdcAddress: "0x036CbD53842c5426634e7929541eC2318f3dCF7e",
  chainId: 84532
});

await oryn.connect(process.env.PRIVATE_KEY!, process.env.BASE_SEPOLIA_RPC_URL!);

// Ask Claude whether this task needs outside compute
const response = await anthropic.messages.create({
  model: "claude-3-5-haiku-latest",
  max_tokens: 300,
  messages: [{
    role: "user",
    content: "Review this PR — can you handle this, or should we delegate to compute-agent?"
  }]
});

const needsDelegation = response.content[0].text.toLowerCase().includes("delegate");

// Only pay if the model decided to delegate — payment is conditional, not automatic
// compute-agent-001 must already be registered by its own wallet before this runs
if (needsDelegation) {
  const receipt = await oryn.pay("claude-agent-001", "compute-agent-001", 0.5);
  console.log("Delegated and paid. Tx:", receipt.hash);
} else {
  console.log("Handled locally — no payment needed.");
}

Required env vars

  • ANTHROPIC_API_KEY for Claude
  • PRIVATE_KEY for the paying agent wallet
  • BASE_SEPOLIA_RPC_URL for the network connection
  • ORYN_PAYMENT_CONTRACT_ADDRESS for settlement

What this example assumes

  • claude-agent-001 is already registered to the connected wallet
  • compute-agent-001 is already registered by its own wallet
  • The payer wallet holds enough USDC to fund the task
  • Your app logic decides when the payment should happen

Expected output

You should see Claude return text first, then an onchain payment transaction hash after oryn.pay() runs.

If the payment fails, the most common causes are an unregistered recipient agent, missing USDC, or using the wrong network or contract address.

Important: the receiving wallet must already have registered compute-agent-001. Oryn does not create the counterparty identity for you at payment time.
3. OpenAI agent pays for a tool step
OpenAI integration · tool-or-service payment
OpenAITask workflowsBase

If your app uses OpenAI for orchestration, the payment flow is the same. The agent evaluates its task with the model, then pays another registered service agent only if the model determines a premium step is needed.

import OpenAI from "openai";
import { OrynSDK } from "@oryn/sdk";

const openai = new OpenAI({ apiKey: process.env.OPENAI_API_KEY! });
const oryn = new OrynSDK({
  contractAddress: process.env.ORYN_PAYMENT_CONTRACT_ADDRESS!,
  usdcAddress: "0x036CbD53842c5426634e7929541eC2318f3dCF7e",
  chainId: 84532
});

await oryn.connect(process.env.PRIVATE_KEY!, process.env.BASE_SEPOLIA_RPC_URL!);

// Ask the model whether premium search is needed for this task
const result = await openai.responses.create({
  model: "gpt-4.1-mini",
  input: "Does this task require premium search enrichment? Reply 'yes' or 'no'."
});

const needsPremiumSearch = result.output_text.toLowerCase().includes("yes");

// Only pay if the model determined premium search is needed
if (needsPremiumSearch) {
  const receipt = await oryn.pay("planner-agent-001", "search-agent-001", 0.1);
  console.log("Search agent paid. Tx:", receipt.hash);
} else {
  console.log("Standard search sufficient — no payment needed.");
}

Required env vars

  • OPENAI_API_KEY for the model call
  • PRIVATE_KEY for the paying wallet
  • BASE_SEPOLIA_RPC_URL for Base Sepolia
  • ORYN_PAYMENT_CONTRACT_ADDRESS for the Oryn contract

Best fit

  • Paying search, retrieval, or verification agents
  • Charging for premium tool steps inside a larger workflow
  • OpenAI-powered planners that outsource a subtask
  • Backends where payment should happen after a model decision

Expected output

You should see the OpenAI response first, followed by a transaction hash once the service agent has been paid onchain.

In production, continue the job only after the payment step succeeds and the downstream service can trust settlement.

Use this when: the model itself is not the thing being paid for. Oryn is best when your agent needs to pay another agent, tool, API, or infrastructure provider inside the workflow.
Expected flow

What a healthy Oryn integration looks like

1. Setup

Pick Base Sepolia first, add the live Oryn contract address, and fund the payer with ETH and USDC.

2. Identity

Register each wallet once with a stable agent ID that your workflow can reference later.

3. Payment

Call pay() only when the workflow has reached a point where another agent or service should be compensated.

Common confusion to avoid: Oryn is not the model provider. Claude or OpenAI powers the reasoning. Oryn handles identity, payment, and settlement once the workflow decides money should move.