Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
110 changes: 110 additions & 0 deletions examples/spraay_crypto_payments/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
# Spraay Crypto Payments Agent

An AI agent that executes cryptocurrency payments across 13 blockchains using the [Spraay x402 gateway](https://gateway.spraay.app). The agent can batch-send tokens, create escrow contracts, check balances, get token prices, and hire robots via the Robot Task Protocol (RTP).

## Overview

This example demonstrates how to build a **crypto payment agent** using NeMo Agent Toolkit with custom tools that interact with the Spraay x402 protocol gateway. The agent uses a ReAct pattern to reason about payment tasks and execute them via HTTP API calls.

### What is x402?

The [x402 protocol](https://www.x402.org) enables AI agents to pay for API services using USDC micropayments over HTTP. When an agent calls a paid endpoint, the server returns HTTP 402 (Payment Required) with payment details. The agent signs a USDC transaction, resends the request with the payment proof, and the server executes the operation.

### Supported Chains

Base · Ethereum · Arbitrum · Polygon · BNB Chain · Avalanche · Solana · Bitcoin · Stacks · Unichain · Plasma · BOB · Bittensor

## Prerequisites

- Python 3.11+
- [uv](https://docs.astral.sh/uv/) package manager
- NVIDIA API key from [build.nvidia.com](https://build.nvidia.com)

## Setup

1. Clone this repository and navigate to the example:

```bash
cd examples/spraay_crypto_payments
```

2. Install dependencies:

```bash
uv venv --python 3.12 --seed .venv
source .venv/bin/activate # Linux/Mac
# .venv\Scripts\activate # Windows
uv pip install nvidia-nat httpx
```

3. Set environment variables:

```bash
export NVIDIA_API_KEY=<your-nvidia-api-key>
export SPRAAY_GATEWAY_URL=https://gateway.spraay.app
```

## Running the Example

### Using the CLI

```bash
nat run --config_file configs/config.yml --input "What chains does Spraay support and what is the current price of ETH on Base?"
```

### Example Prompts

- `"Check the USDC balance for address 0xAd62f03C7514bb8c51f1eA70C2b75C37404695c8 on Base"`
- `"What is the current price of ETH on Base?"`
- `"List all available Spraay gateway routes and their pricing"`
- `"Discover available robots on the RTP network"`

## Architecture

```
┌─────────────────────────────────────────┐
│ NeMo Agent Toolkit │
│ │
│ ┌───────────────────────────────────┐ │
│ │ ReAct Agent (Nemotron) │ │
│ │ │ │
│ │ Tools: │ │
│ │ ├── spraay_health │ │
│ │ ├── spraay_routes │ │
│ │ ├── spraay_chains │ │
│ │ ├── spraay_balance │ │
│ │ ├── spraay_price │ │
│ │ ├── spraay_batch_send │ │
│ │ ├── spraay_escrow_create │ │
│ │ └── spraay_rtp_discover │ │
│ └──────────────┬────────────────────┘ │
│ │ │
└─────────────────┼────────────────────────┘
│ HTTP + x402
┌────────────────────────┐
│ Spraay x402 Gateway │
│ gateway.spraay.app │
│ │
│ 76+ paid endpoints │
│ 13 blockchains │
│ USDC micropayments │
└────────────────────────┘
```

## Files

| File | Description |
|------|-------------|
| `configs/config.yml` | NeMo Agent Toolkit workflow configuration |
| `src/spraay_crypto_payments/spraay_tools.py` | Custom Spraay gateway tools |
| `src/spraay_crypto_payments/__init__.py` | Package init with tool registration |
| `pyproject.toml` | Project dependencies |

## Links

- [Spraay Gateway Docs](https://docs.spraay.app)
- [x402 Protocol](https://www.x402.org)
- [Spraay MCP Server](https://smithery.ai/server/@plagtech/spraay-x402-mcp)
- [NeMo Agent Toolkit Docs](https://docs.nvidia.com/nemo/agent-toolkit/latest/)
- [Spraay on OpenShell](https://github.com/NVIDIA/OpenShell-Community/pull/50)
63 changes: 63 additions & 0 deletions examples/spraay_crypto_payments/configs/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# Spraay Crypto Payments Agent
# NeMo Agent Toolkit workflow configuration
#
# This agent uses the Spraay x402 gateway to execute cryptocurrency
# payments across 13 blockchains via USDC micropayments.

functions:
# Query tools (free endpoints — no x402 payment required)
spraay_health:
_type: spraay_health
description: "Check the health status of the Spraay x402 gateway"

spraay_routes:
_type: spraay_routes
description: "List all available Spraay gateway routes with pricing info"

spraay_chains:
_type: spraay_chains
description: "List all supported blockchains on the Spraay gateway"

spraay_balance:
_type: spraay_balance
description: "Check the token balance of a wallet address on a specific chain"

spraay_price:
_type: spraay_price
description: "Get the current price of a token on a specific chain"

# Action tools (paid endpoints — requires x402 USDC payment)
spraay_batch_send:
_type: spraay_batch_send
description: "Send tokens to multiple recipients in a single batch transaction"

spraay_escrow_create:
_type: spraay_escrow_create
description: "Create an escrow contract with milestone-based fund releases"

spraay_rtp_discover:
_type: spraay_rtp_discover
description: "Discover available robots and IoT devices on the RTP network"

llms:
nim_llm:
_type: nim
model_name: nvidia/nemotron-3-nano-30b-a3b
temperature: 0.0
chat_template_kwargs:
enable_thinking: false

workflow:
_type: react_agent
tool_names:
- spraay_health
- spraay_routes
- spraay_chains
- spraay_balance
- spraay_price
- spraay_batch_send
- spraay_escrow_create
- spraay_rtp_discover
llm_name: nim_llm
verbose: true
parse_agent_response_max_retries: 3
18 changes: 18 additions & 0 deletions examples/spraay_crypto_payments/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
[project]
name = "spraay-crypto-payments"
version = "0.1.0"
description = "Spraay x402 crypto payment tools for NVIDIA NeMo Agent Toolkit"
readme = "README.md"
license = { text = "Apache-2.0" }
requires-python = ">=3.11,<3.14"
dependencies = [
"nvidia-nat>=1.5.0",
"httpx>=0.27.0",
]

[build-system]
requires = ["setuptools>=75.0"]
build-backend = "setuptools.build_meta"

[tool.setuptools.packages.find]
where = ["src"]
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# SPDX-FileCopyrightText: Copyright (c) 2026, NVIDIA CORPORATION & AFFILIATES.
# SPDX-License-Identifier: Apache-2.0

"""Spraay Crypto Payments — NeMo Agent Toolkit plugin.

Registers Spraay x402 gateway tools for use in NeMo Agent Toolkit workflows.
"""

from nat.components.functions.tool import tool
from nat.registry import register

from .spraay_tools import (
spraay_balance,
spraay_batch_send,
spraay_chains,
spraay_escrow_create,
spraay_health,
spraay_price,
spraay_routes,
spraay_rtp_discover,
)


@register("spraay_health")
def _register_health(**kwargs):
return tool(spraay_health, description=kwargs.get("description", ""))


@register("spraay_routes")
def _register_routes(**kwargs):
return tool(spraay_routes, description=kwargs.get("description", ""))


@register("spraay_chains")
def _register_chains(**kwargs):
return tool(spraay_chains, description=kwargs.get("description", ""))


@register("spraay_balance")
def _register_balance(**kwargs):
return tool(spraay_balance, description=kwargs.get("description", ""))


@register("spraay_price")
def _register_price(**kwargs):
return tool(spraay_price, description=kwargs.get("description", ""))


@register("spraay_batch_send")
def _register_batch_send(**kwargs):
return tool(spraay_batch_send, description=kwargs.get("description", ""))


@register("spraay_escrow_create")
def _register_escrow_create(**kwargs):
return tool(spraay_escrow_create, description=kwargs.get("description", ""))


@register("spraay_rtp_discover")
def _register_rtp_discover(**kwargs):
return tool(spraay_rtp_discover, description=kwargs.get("description", ""))
Loading