# Agent Wallet Spend Report — x402 & MPP Payments (`samgov-tools/agent-spend`) Actor

See what an AI-agent wallet spent on paid APIs: x402 USDC payments on Base and MPP session channels on Tempo. Totals, top payees, daily spend, budget flags. Public chain data, read-only.

- **URL**: https://apify.com/samgov-tools/agent-spend.md
- **Developed by:** [AgentReady Tools](https://apify.com/samgov-tools) (community)
- **Categories:** AI, Developer tools, Automation
- **Features:** Limited permissions
- **Stats:** 2 total users, 1 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

from $2.00 / 1,000 wallet day scanneds

This Actor is paid per event. You are not charged for the Apify platform usage, but only a fixed price for specific events.

Learn more: https://docs.apify.com/actors/running/actors-in-store.md#pay-per-event

## What's an Apify Actor?

An Actor is a serverless cloud program that runs on the Apify platform. It has two run modes.
In Batch mode, an Actor accepts a well-defined JSON input, performs an action which can take anything from a few seconds to a few hours,
and optionally produces a well-defined JSON output, datasets with results, or files in key-value store.
In Standby mode, an Actor provides a web server which can be used as a website, API, or an MCP server.

Apify vocabulary and the platform model are defined once, in the agent quickstart at https://apify.com/agents.md.

## How to integrate an Actor?

If asked about integration, you help developers integrate Actors into their projects.
You adapt to their stack and deliver integrations that are safe, well-documented, and production-ready.

Do not guess an integration path. Every one of them is in the agent quickstart at https://apify.com/agents.md: the Apify MCP server, Agent Skills with the Apify CLI, the JavaScript and Python clients, the REST API, and the account-free path for an agent with no human to sign in. It also carries the rule on stating cost before the first paid run.

For examples already wired to this Actor's own input schema, see the [API](#api) section below.

Each client library has reference documentation the quickstart does not restate: [JavaScript/TypeScript](https://docs.apify.com/api/client/js/docs.md) (`npm install apify-client`) and [Python](https://docs.apify.com/api/client/python/docs.md) (`pip install apify-client`).

# README

## Agent Wallet Spend Report: x402 & MPP Payments

See what an AI-agent wallet actually paid for. Give it one or more public wallet addresses and it reads public blockchain data to report:

- **x402 payments on Base**: USDC sent with a signed EIP-3009 authorization, the way x402 sellers get paid.
- **MPP sessions on Tempo**: Machine Payments Protocol payment channels, with the amount paid to each seller, deposits, refunds and still-open channels.
- **Per wallet**: total agent spend, top payees, spend per day, and alerts for budget overruns, single large payments, daily spikes and new payees.

It is read-only. It needs no API keys and never signs or sends a transaction. It reads public RPC nodes only.

### For AI agents

Apify MCP: `https://mcp.apify.com?tools=samgov-tools/agent-spend`

Example prompt: "Use samgov-tools/agent-spend on wallet 0x… for the last 7 days with a $20 budget, and tell me who it paid and whether anything looks wrong."

- Input `{"addresses": ["0x…"], "lookbackDays": 7, "budgetUsd": 20}`. The dataset begins with one `kind: "address-summary"` item per wallet, followed by its payment rows (newest first). `OUTPUT` holds all summaries plus run totals.
- Read `totals.agentPaymentsUsd`, which is x402 plus MPP sessions. Unclassified outgoing transfers (`totals.unclassifiedOutgoingUsd`) and Tempo fees (`totals.tempoFeesUsd`) are kept separate on purpose.
- `flags[].code` values are stable, so you can branch on them: `over_budget`, `payment_over_limit`, `daily_spike`, `new_payees_24h`, `channel_opened_before_window`, `network_incomplete`, `rows_truncated`.
- Every row has an `explorerUrl`, so you can show the user the proof.
- Set `maxRowsPerAddress: 0` when you only need the summaries.
- A wallet is charged only when its report is complete. If a requested network fails, the report is still delivered with `network_incomplete` and is free.

#### Paying agents without an Apify account (x402 / MPP)

An agent without an Apify account can buy a prepaid Apify API token from Apify AGI (`agi.apify.com`) with x402 (USDC on Base or Solana), MPP (Tempo or Solana) or Skyfire. It then uses that token for the REST call below, with the Actor id `samgov-tools~agent-spend`, or with the Apify MCP server.

This Actor uses limited permissions, which prepaid tokens require. Apify's current terms: minimum $1, the token expires after 14 days, unused balance is non-refundable, and the feature is experimental. Check `agi.apify.com` for current terms before paying.

### Quick start

```bash
curl -X POST "https://api.apify.com/v2/acts/samgov-tools~agent-spend/run-sync-get-dataset-items?token=$APIFY_TOKEN" \
  -H 'content-type: application/json' \
  -d '{"addresses":["0x77d8e9f17187c8a4d917858dfa220be00395d2d4"],"lookbackDays":7,"budgetUsd":5}'
```

### Input

| Field | Default | Meaning |
|---|---|---|
| `addresses` | demo wallet | 1–10 EVM addresses (`0x` + 40 hex). The same address is checked on Base and Tempo. |
| `lookbackDays` | 7 | 1–7 days back from now. |
| `networks` | both | `base-x402`, `tempo-mpp`. The price is the same either way. |
| `includeUnclassifiedTransfers` | true | Also list other outgoing stablecoin transfers, reported separately. |
| `budgetUsd` | – | Flags `over_budget` when agent spend in the window is above this amount. |
| `perPaymentLimitUsd` | – | Flags any single payment or channel above this amount. |
| `maxRowsPerAddress` | 500 | Rows stored per wallet (0–10,000). Totals always use every row. |

### Output

Summary item (abridged, from a real run on 2026-11-14):

```json
{
  "kind": "address-summary",
  "address": "0x77d8e9f17187c8a4d917858dfa220be00395d2d4",
  "window": { "from": "2026-11-07T22:20:00.000Z", "to": "2026-11-14T22:20:00.000Z", "days": 7 },
  "networks": { "base": "ok", "tempo": "ok" },
  "totals": { "agentPaymentsUsd": 8.96, "x402Usd": 8.96, "x402Count": 448, "mppSessionUsd": 0, "unclassifiedOutgoingUsd": 0 },
  "topPayees": [{ "payee": "0x7284d41b5b852f2bd4c99bdf95043d84452d299c", "network": "base", "protocol": "x402-payment", "usd": 8.96, "count": 448 }],
  "flags": [{ "code": "over_budget", "message": "Agent payments $8.96 exceed the budget of $5 for this window." }]
}
```

Payment row:

```json
{
  "kind": "mpp-session", "network": "tempo", "payee": "0xca4e835f803cb0b7c428222b3a3b98518d4779fe",
  "tokenSymbol": "OUSD", "amountUsd": 0.001, "channelStatus": "open", "depositedUsd": 0.001,
  "timestamp": "2026-11-14T20:23:32.000Z", "explorerUrl": "https://explore.tempo.xyz/tx/0x…"
}
```

### Pricing

Pay per event: **$0.002 per wallet per day scanned** (`address-day`). Both networks are included.

- 1 wallet × 7 days = 14 events = $0.028.
- 10 wallets × 7 days = $0.14.

You are charged only after a wallet's complete report is stored. Partial reports (a network failed) and invalid input are free. Your run's maximum cost setting is respected: the Actor scans only as many wallets as fit within it.

### What is and is not counted

- **x402**: USDC on Base sent with an EIP-3009 `transferWithAuthorization` signed by the wallet. MPP's EVM method and some gasless wallets use the same mechanism, so a few non-x402 payments can appear. Not covered: x402 on Solana or other EVM chains, and the permit2-based `upto` scheme.
- **MPP sessions**: payment-channel escrow events on Tempo (both the legacy escrow and the TIP-1034 precompile). The amount paid is the final amount at close, or the highest settled amount while the channel is open. Vouchers the seller has not yet settled on-chain are invisible.
- **MPP one-time charges** on Tempo are ordinary token transfers and cannot be told apart from other payments, so they appear as unclassified transfers.
- Stablecoins (USDC, USDC.e, OUSD, pathUSD and the MACH credit) are valued at $1. Other tokens get `amountUsd: null`.
- Blockchain addresses are pseudonymous. This Actor does not identify people.

### Limits and behavior

- Uses the free public RPC nodes `base-rpc.publicnode.com` and `rpc.tempo.xyz`, at no more than 2 requests per second per node. It retries 429 and 5xx responses with backoff, and halves the block range when a node rejects a range or result size.
- The window is capped at 7 days because the free Base node answers older history very slowly. A 7-day run for 2 wallets took 51 s and 92 RPC calls in testing.
- Only read methods are sent (`eth_blockNumber`, `eth_getBlockByNumber`, `eth_getLogs`, `eth_call`).
- The RPC endpoints are fixed, so the input cannot point the Actor at other hosts.

### Local development

```bash
npm install
npm test          # 14 tests; replay recorded RPC responses, no network
npm run live -- 0x…   # live smoke run, re-records test/fixtures/recorded.json
apify run         # full local Actor run (INPUT in storage/key_value_stores/default)
python3 scripts/make-schemas.py   # regenerate .actor schemas
```

### FAQ

**Is this the wallet's full spending?** No. It shows agent payments that leave public on-chain evidence on Base (x402) and Tempo (MPP). Card payments, custodial balances and other chains are not visible.

**Why does an open MPP channel show a small amount?** Sellers settle vouchers in batches. The on-chain amount catches up when they settle or close the channel.

**Can it block payments?** No. It only reads. Use the flags to alert a person or another agent.

# Actor input Schema

## `addresses` (type: `array`):

1 to 10 public EVM wallet addresses (0x followed by 40 hex characters) whose agent spending you want to see. The same address is checked on Base and Tempo. Duplicates are removed. ENS names are not resolved. Empty uses a public demo wallet that pays an x402 API.

## `lookbackDays` (type: `integer`):

How many days back from now to scan, 1 to 7 (older history on the free public Base node is too slow to read reliably). Price is per wallet per day, so 7 days for 1 wallet is 7 events. Totals cover the whole window.

## `networks` (type: `array`):

base-x402 finds USDC payments on Base made with signed EIP-3009 authorizations (how x402 pays). tempo-mpp finds Machine Payments Protocol session channels on Tempo. Both are included in the same price.

## `includeUnclassifiedTransfers` (type: `boolean`):

Also list other outgoing USDC transfers on Base and stablecoin transfers on Tempo (MPP one-time charges look like plain transfers). They are reported separately and not counted as agent payments. Tempo network fees are reported as fees.

## `budgetUsd` (type: `number`):

Optional. If x402 plus MPP spend in the window is above this amount, the summary gets an over_budget flag. Nothing is blocked; this Actor only reads.

## `perPaymentLimitUsd` (type: `number`):

Optional. Flags any single x402 payment or MPP channel above this amount with payment_over_limit.

## `maxRowsPerAddress` (type: `integer`):

Most recent payment rows stored per wallet, 0 to 10,000. Totals, payees and the daily breakdown always use every payment found. Use 0 for summaries only.

## Actor input object example

```json
{
  "addresses": [
    "0x77d8e9f17187c8a4d917858dfa220be00395d2d4",
    "0xe9b37d4d9c61769f6d9295fa8e2f6413556d0617"
  ],
  "lookbackDays": 7,
  "networks": [
    "base-x402",
    "tempo-mpp"
  ],
  "includeUnclassifiedTransfers": true,
  "maxRowsPerAddress": 500
}
```

# Actor output Schema

## `results` (type: `string`):

Default dataset: an address-summary item per wallet followed by its payment rows, newest first.

## `summary` (type: `string`):

OUTPUT: all wallet summaries, charged address-days, RPC requests and stop reason.

# API

You can run this Actor programmatically using our API. Below are code examples in JavaScript, Python, and CLI, as well as the OpenAPI specification and MCP server setup.

## JavaScript example

```javascript
import { ApifyClient } from 'apify-client';

// Initialize the ApifyClient with your Apify API token
// Replace the '<YOUR_API_TOKEN>' with your token
const client = new ApifyClient({
    token: '<YOUR_API_TOKEN>',
});

// Prepare Actor input
const input = {
    "addresses": [
        "0x77d8e9f17187c8a4d917858dfa220be00395d2d4",
        "0xe9b37d4d9c61769f6d9295fa8e2f6413556d0617"
    ]
};

// Run the Actor and wait for it to finish
const run = await client.actor("samgov-tools/agent-spend").call(input);

// Fetch and print Actor results from the run's dataset (if any)
console.log('Results from dataset');
console.log(`💾 Check your data here: https://console.apify.com/storage/datasets/${run.defaultDatasetId}`);
const { items } = await client.dataset(run.defaultDatasetId).listItems();
items.forEach((item) => {
    console.dir(item);
});

// 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/js/docs

```

## Python example

```python
from apify_client import ApifyClient

# Initialize the ApifyClient with your Apify API token
# Replace '<YOUR_API_TOKEN>' with your token.
client = ApifyClient("<YOUR_API_TOKEN>")

# Prepare the Actor input
run_input = { "addresses": [
        "0x77d8e9f17187c8a4d917858dfa220be00395d2d4",
        "0xe9b37d4d9c61769f6d9295fa8e2f6413556d0617",
    ] }

# Run the Actor and wait for it to finish
run = client.actor("samgov-tools/agent-spend").call(run_input=run_input)

# Fetch and print Actor results from the run's dataset (if there are any)
print(f"💾 Check your data here: https://console.apify.com/storage/datasets/{run.default_dataset_id}")
for item in client.dataset(run.default_dataset_id).iterate_items():
    print(item)

# 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/python/docs/quick-start

```

## CLI example

```bash
echo '{
  "addresses": [
    "0x77d8e9f17187c8a4d917858dfa220be00395d2d4",
    "0xe9b37d4d9c61769f6d9295fa8e2f6413556d0617"
  ]
}' |
apify call samgov-tools/agent-spend --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,samgov-tools/agent-spend"
        }
    }
}
```

The hosted server signs you in with OAuth on first connect, so no API token belongs in this config. Clients without OAuth support can send an `Authorization: Bearer <APIFY_API_TOKEN>` header instead, using a token from API & Integrations in Apify Console (https://console.apify.com/settings/integrations).

## OpenAPI specification

Download the OpenAPI definition: https://api.apify.com/v2/actors/V4fId0aftgaj659Ie/builds/Xlew93t0vlPrJVQg3/openapi.json
