# Wallet PnL & Cost Basis Calculator (ERC20 / Base)

> Wallet PnL & Cost Basis Calculator (ERC20 / Base) is a paid API for AI agents from api.x402node.dev, paid per call via x402, $0.1/call, status unknown (last checked 2026-09-14).

Computes realized profit and loss, average buy/sell price, cost basis, and remaining position for an ERC20 token in a wallet by analyzing on-chain DEX trades on Base against a quote asset (default USDC).

## Facts

- Endpoint: GET https://api.x402node.dev/wallet/pnl
- Price: $0.1/call
- Payment: x402
- Status: unknown
- Last checked: 2026-09-14
- Activations on Zero: 0
- Tags: x402
- Canonical page: https://www.zero.xyz/c/api-x402node-dev-6e259dc2
- Structured record (JSON): https://api.zero.xyz/v1/capabilities/cap_dgUMupa56CxIW2h1h2lnc

Status and success rate cover calls made through Zero and Zero's own probes. Third-party monitors may report differently.

## How to call it through Zero

Zero handles the 402 payment challenge and records the run. With the Zero CLI installed (`npm i -g @zeroxyz/cli`):

```sh
zero fetch --capability api-x402node-dev-6e259dc2
```

Example prompt: What's my realized PnL and cost basis for the token at 0x4ed4E862860beD51a9570b96d89aF5E1B0Efefed in my wallet 0xAbC123...def on Base — use USDC as the quote asset?

## When to prefer this

Use this endpoint when you need on-chain, DEX-derived realized PnL and cost basis for an ERC20 token on Base — ideal for crypto tax accounting, portfolio performance reporting, or DeFi trade analysis. Prefer this over off-chain or CEX-based PnL tools when the trades occurred on Base DEXes and you need average buy/sell prices and remaining position computed from actual blockchain data.

## Known failure modes

- Wallet address not found or has no DEX trade history — returns empty or zero values
- ERC20 token address invalid or not traded on Base DEXes — returns error or null result
- No trades found against the specified quote asset — may return zero PnL
- RPC or indexing latency causes stale or incomplete trade data
- Malformed wallet or token address returns a 400-level error

## How this service works

Realized profit and loss and cost basis for an ERC20 token in a wallet on Base, computed from on-chain DEX trades against a quote asset (USDC by default). Returns average buy and sell price, realized PnL, remaining position and cost basis. Search terms: wallet PnL, realized gains, cost basis, token profit, crypto tax accounting, trade history. Accepts payment on Base or Solana — either network works.

## Output

Returns a structured object containing average buy price, average sell price, realized PnL (in the quote asset, default USDC), remaining token position size, and cost basis computed from on-chain DEX trade history on the Base network.

## Request schema (JSON Schema)

```json
{
 "type": "object",
 "$schema": "https://json-schema.org/draft/2020-12/schema",
 "required": [
  "input"
 ],
 "properties": {
  "input": {
   "type": "object",
   "required": [
    "type",
    "method"
   ],
   "properties": {
    "type": {
     "type": "string",
     "const": "http"
    },
    "method": {
     "enum": [
      "GET"
     ],
     "type": "string"
    },
    "queryParams": {
     "type": "object",
     "required": [
      "quote"
     ],
     "properties": {
      "quote": {
       "type": "string",
       "description": "Quote (required)"
      },
      "token": {
       "type": "string",
       "description": "ERC20 contract address (optional)"
      },
      "wallet": {
       "type": "string",
       "description": "Wallet (optional)"
      },
      "address": {
       "type": "string",
       "description": "EVM/chain address (optional)"
      }
     }
    }
   },
   "additionalProperties": false
  }
 }
}
```

## More

- Live health (JSON, refreshed every minute): https://www.zero.xyz/c/api-x402node-dev-6e259dc2/health.json
- [Zero catalog index](https://www.zero.xyz/llms.txt)
- [Other services from api.x402node.dev](https://www.zero.xyz/host/api.x402node.dev/llms.txt)
