Wallet PnL (average cost, on-chain prices)
POST /api/wallet-pnlRealized and unrealized profit and loss of an EVM wallet on one chain (base, ethereum, arbitrum, optimism, polygon) over the last 1-30 days...
Details
Realized and unrealized profit and loss of an EVM wallet on one chain (base, ethereum, arbitrum, optimism, polygon) over the last 1-30 days, computed here from its ERC-20 Transfer logs and Uniswap v3 Swap events for a listed token set: trades priced from their own USDC amounts, from the native coin leg read off the transaction receipt (wrapped-coin Deposit or Withdrawal), or from Uniswap v3 pool state at their block, the opening balance costed at the window's first block, average-cost basis, per-token realized and unrealized USD, and a reconciliation against the balance at the head. Log ranges and historical price reads are bounded (at most 36 reads); the answer states the window it covered, what it skipped (native coin legs past the receipt budget, unlisted tokens, unpriced lots) and its method fields.
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
address | string | yes | 0x-prefixed 40-hex EVM wallet address. Also accepted as addr, wallet, account. The example sends 0x464C71f6c2F760DdA6093dCB91C24c39e5d6e18c. |
network | string (one of: base, ethereum, arbitrum, optimism, polygon) | no | One of base, ethereum, arbitrum, optimism, polygon (default base). One of base, ethereum, arbitrum, optimism, polygon. |
days | number | no | Window length in days, 1-30 (default 7). The example sends 1. |
Example request
curl -i -X POST https://agent402.tools/api/wallet-pnl \
-H "Content-Type: application/json" \
-d '{"address":"0x464C71f6c2F760DdA6093dCB91C24c39e5d6e18c","network":"ethereum","days":1}'Watch a call get paid
POST /api/wallet-pnl$0.02 USDCPAYMENT-SIGNATUREon 14 chains200 OKAgent402-ReceiptEd25519Example response
{
"address": "0x464c71f6c2f760dda6093dcb91c24c39e5d6e18c",
"network": "ethereum",
"chainId": 1,
"window": {
"days": 1,
"requestedFromBlock": 26514160,
"fromBlock": 26514160,
"toBlock": 26521359,
"fromTime": "2026-11-28T13:54:23.000Z",
"toTime": "2026-11-29T13:57:59.000Z",
"coversRequested": true,
"logRangesRead": 1
},
"tokens": [
{
"symbol": "USDT",
"contract": "0xdac17f958d2ee523a2206206994597c13d831ec7",
"openingAmount": 1,
"openingPriceUsd": 0.9991925957,
"acquiredAmount": 0,
"disposedAmount": 0,
"transferredInAmount": 0,
"transferredOutAmount": 0,
"closingAmount": 1,
"balanceNow": 1,
"reconciled": true,
"priceNowUsd": 0.9992329935,
"averageCostUsd": 0.9991925957,
"costBasisUsd": 1,
"realizedUsd": 0,
"unrealizedUsd": 0,
"lots": 1,
"pnlState": "ok"
},
{
"symbol": "WETH",
"contract": "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2",
"openingAmount": 0.0191484560532,
"openingPriceUsd": 1638.97474,
"acquiredAmount": 0,
"disposedAmount": 0,
"transferredInAmount": 0,
"transferredOutAmount": 0,
"closingAmount": 0.0191484560532,
"balanceNow": 0.0191484560532,
"reconciled": true,
"priceNowUsd": 1653.096437,
"averageCostUsd": 1638.97474,
"costBasisUsd": 31.38,
"realizedUsd": 0,
"unrealizedUsd": 0.27,
"lots": 1,
"pnlState": "ok"
},
{
"symbol": "WBTC",
"contract": "0x2260fac5e5542a773aa44fbcfedf7c193bc2c599",
"openingAmount": 0.00033045,
"openingPriceUsd": 59157.71126,
"acquiredAmount": 0,
"disposedAmount": 0,
"transferredInAmount": 0,
"transferredOutAmount": 0,
"closingAmount": 0.00033045,
"balanceNow": 0.00033045,
"reconciled": true,
"priceNowUsd": 59632.22708,
"averageCostUsd": 59157.71126,
"costBasisUsd": 19.55,
"realizedUsd": 0,
"unrealizedUsd": 0.16,
"lots": 1,
"pnlState": "ok"
},
{
"symbol": "cbBTC",
"contract": "0xcbb7c0000ab88b473b1f5afd9ef808440eed33bf",
"openingAmount": 0.00019639,
"openingPriceUsd": 59134.31281,
"acquiredAmount": 0,
"disposedAmount": 0,
"transferredInAmount": 0,
"transferredOutAmount": 0,
"closingAmount": 0.00019639,
"balanceNow": 0.00019639,
"reconciled": true,
"priceNowUsd": 59571.32698,
"averageCostUsd": 59134.31281,
"costBasisUsd": 11.61,
"realizedUsd": 0,
"unrealizedUsd": 0.09,
"lots": 1,
"pnlState": "ok"
},
{
"symbol": "DAI",
"contract": "0x6b175474e89094c44da98b954eedeac495271d0f",
"openingAmount": 1.06026024796,
"openingPriceUsd": 1.000044419,
"acquiredAmount": 0,
"disposedAmount": 0,
"transferredInAmount": 0,
"transferredOutAmount": 0,
"closingAmount": 1.06026024796,
"balanceNow": 1.06026024796,
"reconciled": true,
"priceNowUsd": 1.00002496,
"averageCostUsd": 1.000044419,
"costBasisUsd": 1.06,
"realizedUsd": 0,
"unrealizedUsd": 0,
"lots": 1,
"pnlState": "ok"
},
{
"symbol": "wstETH",
"contract": "0x7f39c581f595b53c5cb19bd0b3f8da6c935e2ca0",
"openingAmount": 2e-18,
"openingPriceUsd": 2051.76925,
"acquiredAmount": 0,
"disposedAmount": 0,
"transferredInAmount": 0,
"transferredOutAmount": 0,
"closingAmount": 2e-18,
"balanceNow": 2e-18,
"reconciled": true,
"priceNowUsd": 2067.346023,
"averageCostUsd": 2051.76925,
"costBasisUsd": 0,
"realizedUsd": 0,
"unrealizedUsd": 0,
"lots": 1,
"pnlState": "ok"
},
{
"symbol": "LINK",
"contract": "0x514910771af9ca656af840dff83e8264ecf986ca",
"openingAmount": 5.71277358285,
"openingPriceUsd": 9.119130794,
"acquiredAmount": 0,
"disposedAmount": 0,
"transferredInAmount": 0,
"transferredOutAmount": 0,
"closingAmount": 5.71277358285,
"balanceNow": 5.71277358285,
"reconciled": true,
"priceNowUsd": 9.256836915,
"averageCostUsd": 9.119130794,
"costBasisUsd": 52.1,
"realizedUsd": 0,
"unrealizedUsd": 0.79,
"lots": 1,
"pnlState": "ok"
},
{
"symbol": "UNI",
"contract": "0x1f9840a85d5af5bf1d1762f925bdaddc4201f984",
"openingAmount": 65.2412758136,
"openingPriceUsd": 4.64890478,
"acquiredAmount": 0,
"disposedAmount": 0,
"transferredInAmount": 0,
"transferredOutAmount": 0,
"closingAmount": 65.2412758136,
"balanceNow": 65.2412758136,
"reconciled": true,
"priceNowUsd": 4.693598989,
"averageCostUsd": 4.64890478,
"costBasisUsd": 303.3,
"realizedUsd": 0,
"unrealizedUsd": 2.92,
"lots": 1,
"pnlState": "ok"
}
],
"totals": {
"realizedUsd": 0,
"unrealizedUsd": 4.23,
"tokensCounted": 8,
"tokensIncomplete": 0,
"basis": "Sums over the tokens whose every lot was priced; incomplete tokens are not in them."
},
"trades": [],
"tradesTotal": 0,
"returned": 0,
"matched": 0,
"complete": true,
"truncated": false,
"transfersRead": 0,
"skipped": {
"nativeLegs": {
"candidates": 0,
"receiptsRead": 0,
"found": 0,
"skipped": 0
},
"unlistedTokens": "only the 10 listed tokens are read",
"priceBlocksSkipped": 0,
"openingRead": true,
"eventCapReached": false,
"lane": "no keyed lane on this deployment: wide log ranges and historical reads may be refused"
},
"tokenList": [
"USDC",
"USDT",
"WETH",
"WBTC",
"cbBTC",
"DAI",
"wstETH",
"LINK",
"UNI",
"AAVE"
],
"method": {
"costBasis": "Average cost per token, in block order. The opening balance (at the block before the covered window) is costed at that block's pool price.",
"trades": "A transaction in which the wallet sent one listed token and received another. With USDC on one side and one token on the other, the token's price is the trade's own USDC amount per token; otherwise the pool price at that block.",
"transfers": "A transfer in is an acquisition at the pool price at its block; a transfer out leaves at average cost and realizes nothing.",
"realized": "Amount sold x (sale price - average cost at the sale).",
"unrealized": "Closing tracked amount x the head block's pool price - the remaining cost.",
"prices": "USDC is the quote unit and is counted as 1 USD; every other price is the token's Uniswap v3 spot price in USDC at the answer's block (the one of its USDC pools with the most in-range liquidity), not an exchange or oracle price.",
"nativeLegs": "A transaction the wallet sent whose listed-token transfers go one way (one token, no USDC) is read for a native coin leg (up to 6 receipts, newest first): the wrapped native token's Deposit events for a buy, Withdrawal events for a sale, priced from the wrapped native token's USDC pool at that block.",
"notRead": "Tokens outside the list, gas fees, native coin legs past the receipt budget."
},
"reads": {
"rpcCalls": 7,
"max": 36
},
"fetchedAt": "2026-11-29T13:58:11.027Z"
}| Field | Type | Always present | In the example |
|---|---|---|---|
address | string | yes | 0x464c71f6c2f760dda6093dcb91c24c39e5d6e18c |
network | string | yes | ethereum |
chainId | number | yes | 1 |
window | object | yes | 8 fields: days, requestedFromBlock, fromBlock, toBlock, fromTime and 3 more |
tokens | array of objects | yes | 8 items in the example |
totals | object | yes | 5 fields: realizedUsd, unrealizedUsd, tokensCounted, tokensIncomplete, basis |
trades | array | yes | 0 items in the example |
tradesTotal | number | yes | 0 |
returned | number | yes | 0 |
matched | number | yes | 0 |
complete | boolean | yes | true |
truncated | boolean | yes | false |
transfersRead | number | yes | 0 |
skipped | object | yes | 6 fields: nativeLegs, unlistedTokens, priceBlocksSkipped, openingRead and 2 more |
tokenList | array of string | yes | 10 items in the example |
method | object | yes | 8 fields: costBasis, trades, transfers, realized, unrealized, prices and 2 more |
reads | object | yes | 2 fields: rpcCalls, max |
fetchedAt | string | yes | 2026-11-29T13:58:11.027Z |
From an MCP client
catalog.call {
"slug": "wallet-pnl",
"params": {
"address": "0x464C71f6c2F760DdA6093dCB91C24c39e5d6e18c",
"network": "ethereum",
"days": 1
}
}Hosted connector (https://agent402.tools/mcp): paid in the call. Stdio package (npx -y agent402-mcp@0.18.0): pays from a wallet or an AGENT402_CREDITS_KEY issued earlier.
Errors and behavior
- Pay $0.02 per call over x402 or MPP. Wallet-only: this tool reaches the network or stored state, so it has no proof-of-work tier. A card-credits key issued earlier (
Authorization: Bearer a402_...) also pays it. - Required:
address; a rejected input answers 4xx witherror,tool,expected,requiredandexample. - On this route, a call ending in any status of 400 or above is not charged over x402, MPP or a credits key. A Tempo push credential pays before the call; a failure is a refund owed.
- A bodyless
GETorHEADreturns the same 402 quote. - An
Idempotency-Keyreplays the first 200 uncharged (an answer larger than 1 MB is not replayed).
Paid call (JavaScript agent)
import { wrapFetchWithPayment } from "@x402/fetch";
import { x402Client } from "@x402/core/client";
import { registerExactEvmScheme } from "@x402/evm/exact/client";
import { privateKeyToAccount } from "viem/accounts";
const client = new x402Client();
client.setSpendControls?.({ maxAmountPerPayment: "$0.02" }); // refuse any quote above this tool's price
registerExactEvmScheme(client, { signer: privateKeyToAccount(process.env.AGENT_KEY) });
const payFetch = wrapFetchWithPayment(fetch, client);
const res = await payFetch("https://agent402.tools/api/wallet-pnl", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
"address": "0x464C71f6c2F760DdA6093dCB91C24c39e5d6e18c",
"network": "ethereum",
"days": 1
}),
});Get a wallet or run npx -y agent402-mcp@0.18.0 wallet new.
The quote (Python)
import base64, json, urllib.error, urllib.request
req = urllib.request.Request("https://agent402.tools/api/wallet-pnl", method="POST", data="{\"address\":\"0x464C71f6c2F760DdA6093dCB91C24c39e5d6e18c\",\"network\":\"ethereum\",\"days\":1}".encode(), headers={"Content-Type": "application/json"})
try:
urllib.request.urlopen(req)
except urllib.error.HTTPError as e:
quote = json.loads(base64.b64decode(e.headers["PAYMENT-REQUIRED"]))
print(e.code, [(a["network"], a["amount"]) for a in quote["accepts"]]) # the price, per chain, in base units