ToknWrks for Agents
The data and tools behind ToknWrks, as an API an AI agent can call and pay for on its own. Each call is paid in USDC on Base over the x402 protocol. There is no account, no API key and no subscription.
Tools and prices
- Token SearchFind a token and get the slug the price call takes.Free
- Token PricesLive USD price and 24-hour change of one token.$0.01
- PortfolioEverything one address holds, valued in USD: liquid, staked, liquidity positions and unclaimed rewards.$0.05
- Staking ClaimsStaking rewards one address claimed on a Cosmos chain, each priced on the day it was claimed.$0.05
- Osmosis TradesSwaps one address made on Osmosis: what was sold, what was bought and the USD value.$0.05
- V4 PositionsThe Uniswap V4 liquidity positions an address holds on one chain.$0.05
- V4 Remove LiquidityAn unsigned transaction that removes liquidity from a Uniswap V4 position.$0.05
- V4 RebalanceAn unsigned transaction that re-centres a Uniswap V4 position on the current price, without a swap.$0.05
Every route is a GET on https://www.toknwrks.com and answers JSON. Use the www host: the bare domain redirects.
How a paid call works
- Call the route. It answers
402 Payment Requiredwith the terms in apayment-requiredheader: the amount, USDC on Base, and the address to pay. - The agent's wallet signs a USDC transfer authorisation for exactly that amount and repeats the call with it in a
payment-signatureheader. - The payment is verified, the route does its work, and the payment settles only if the answer is a good one. The answer carries a
payment-responseheader with the settlement transaction.
This is x402 version 2 with the exact scheme, so any x402 client works. The script below is a whole client: it reads the terms, refuses a price over your cap, pays and prints the answer.
// npm i @x402/core @x402/evm viem
// AGENT_PRIVATE_KEY=0x… node pay.mjs "<url>" <most you will pay, in USD>
import { decodePaymentRequiredHeader, encodePaymentSignatureHeader } from "@x402/core/http";
import { x402Client } from "@x402/core/client";
import { ExactEvmScheme } from "@x402/evm/exact/client";
import { privateKeyToAccount } from "viem/accounts";
const [url, maxUsd] = [process.argv[2], Number(process.argv[3])];
const BASE = "eip155:8453";
const res = await fetch(url);
if (res.status !== 402) { console.log(res.status, await res.text()); process.exit(); }
const required = decodePaymentRequiredHeader(res.headers.get("payment-required"));
const offer = required.accepts.find((a) => a.scheme === "exact" && a.network === BASE);
if (!offer) throw new Error("no USDC-on-Base offer");
if (Number(offer.amount) / 1e6 > maxUsd) throw new Error("price is over the cap");
const client = new x402Client();
client.register(BASE, new ExactEvmScheme(privateKeyToAccount(process.env.AGENT_PRIVATE_KEY)));
const payload = await client.createPaymentPayload({ ...required, accepts: [offer] });
const paid = await fetch(url, { headers: { "payment-signature": encodePaymentSignatureHeader(payload) } });
console.log(paid.status, await paid.text());AGENT_PRIVATE_KEY=0x… node pay.mjs "https://www.toknwrks.com/api/agent/price?slug=cosmos" 0.01Use a wallet made for the agent, holding only what it may spend. Never give an agent the key to a wallet that holds more.
The tools
Token Search
FreeFind a token and get the slug the price call takes.
GET /api/agent/tokens?q=atom- qrequired
- Symbol or name, for example
atom. - limit
- 1 to 40. Default 10.
Returns. Matching tokens: slug, symbol, name and market-cap rank.
Token Prices
$0.01 per callLive USD price and 24-hour change of one token.
GET /api/agent/price?slug=cosmos- slugrequired
- A token slug from the search call, for example
cosmos.
Returns. Slug, symbol, name, USD price, 24-hour change in percent and the time it was read.
- An unknown slug, or a token nothing prices, is a 404 and is not charged.
Portfolio
$0.05 per callEverything one address holds, valued in USD: liquid, staked, liquidity positions and unclaimed rewards.
GET /api/agent/portfolio?address=0x…- addressrequired
- A 0x, Cosmos (cosmos1, osmo1, inj1…), thor1 or Solana address.
Returns. Total USD value and, per chain, each holding with amount, price, value, and its unclaimed rewards.
- A 0x address is read on Ethereum, Base and Robinhood Chain. One Cosmos address covers Cosmos Hub, Osmosis, Akash, Regen, Celestia, AtomOne, Juno, Arkeo, Sentinel and Jackal; Injective and TX need their own address.
- Holdings under $0.25, and tokens nothing prices, are left out.
Staking Claims
$0.05 per callStaking rewards one address claimed on a Cosmos chain, each priced on the day it was claimed.
GET /api/agent/claims?address=cosmos1…&chain=cosmos&from=2026-09-01&to=2026-11-30- addressrequired
- A Cosmos address. A cosmos1 address is converted for the chain asked for.
- chainrequired
- One of
cosmos,osmosis,akash,regen,celestia,atomone,juno. - from
- First day, YYYY-MM-DD (UTC). Default: 90 days before
to. - to
- Last day, YYYY-MM-DD (UTC). Default: today.
- cursor
- The
nextCursorof the previous answer, for older rows.
Returns. Each claim: transaction hash, time, amount, that day's USD price, USD value and the validators it came from. Plus totals.
- The day's price is the average of hourly prices over that UTC day.
- One call reads up to 200 transactions, newest first, then returns
nextCursor.
Osmosis Trades
$0.05 per callSwaps one address made on Osmosis: what was sold, what was bought and the USD value.
GET /api/agent/trades?address=osmo1…&token=ATOM- addressrequired
- An osmo1 address, or the cosmos1 address of the same wallet.
- token
- Keep only swaps with this symbol on either side, for example
ATOM. - from
- First day, YYYY-MM-DD (UTC). Default: 90 days before
to. - to
- Last day, YYYY-MM-DD (UTC). Default: today.
- cursor
- The
nextCursorof the previous answer, for older rows.
Returns. Each swap: transaction hash, time, token and amount sold, token and amount bought, USD value. Plus the total.
- Reads exact-amount-in swaps. Split-route and exact-amount-out swaps are not read.
- USD value is the stablecoin side when there is one, else the sold token at that day's price.
V4 Positions
$0.05 per callThe Uniswap V4 liquidity positions an address holds on one chain.
GET /api/agent/positions?address=0x…- addressrequired
- A 0x address.
- chainId
- 8453 Base (default), 1 Ethereum, 4663 Robinhood Chain.
Returns. Each position: tokenId, pool, fee, price range, whether it is in range, principal, uncollected fees and USD values.
- Uniswap V3 positions are in the portfolio call.
- One call reads up to 500 position NFTs.
truncated: truemeans the address holds more, and the list and totals are partial.
V4 Remove Liquidity
$0.05 per callAn unsigned transaction that removes liquidity from a Uniswap V4 position.
GET /api/agent/positions/remove?address=0x…&tokenId=123456&percent=50- addressrequired
- The 0x address that holds the position NFT.
- tokenIdrequired
- The position NFT id, from the positions call.
- chainId
- 8453 Base (default), 1 Ethereum, 4663 Robinhood Chain.
- percent
- Share of the liquidity to remove, 1 to 100. Default 100.
- slippage
- Percent the pool price may move before the transaction reverts, 0.1 to 20. Default 1.
Returns. The transaction, the amounts expected, the minimum it will accept and the fees paid out with it.
- The answer holds
transaction:{ chainId, from, to, data, value, validUntil }. Sign and send it from the holding wallet beforevalidUntil(20 minutes). ToknWrks signs and sends nothing. - The transaction is simulated from the holder first. One that would revert is a 422, and a position the address does not hold is a 404; neither is charged.
- Liquidity and all uncollected fees go to the holder. No fee is taken in the transaction.
V4 Rebalance
$0.05 per callAn unsigned transaction that re-centres a Uniswap V4 position on the current price, without a swap.
GET /api/agent/positions/rebalance?address=0x…&tokenId=123456&width=10- addressrequired
- The 0x address that holds the position NFT.
- tokenIdrequired
- The position NFT id, from the positions call.
- chainId
- 8453 Base (default), 1 Ethereum, 4663 Robinhood Chain.
- width
- Distance from the price to each edge of the new range, in percent, 0.1 to 100. Default: the width the position has now.
- slippage
- Percent the pool price may move before the transaction reverts, 0.1 to 20. Default 1.
Returns. The transaction and the plan: the base range, the limit range, the amounts each takes, the minimums and the fee.
- All liquidity comes out and goes back in one transaction as two positions: a base position centred on the price, holding the two tokens in balance, and a limit position next to the price holding the token left over. Trading through the limit position converts the surplus.
- A position holding only one token (out of range, or at the very edge of its range) gets no base position:
baseis null and everything goes into the limit position, which sits beside the price, not around it, and is half as wide aswidth. - The answer holds
transaction:{ chainId, from, to, data, value, validUntil }. Sign and send it from the holding wallet beforevalidUntil(20 minutes). ToknWrks signs and sends nothing. - The transaction is simulated from the holder first. One that would revert is a 422, and a position the address does not hold is a 404; neither is charged.
- The two positions are new NFTs minted to the holder; the old one is left empty.
- 10% of the position's uncollected fees goes to ToknWrks inside the transaction, never any principal (
fee.bips1000 is that share of the fees;fee.amount0andfee.amount1are what it comes to). That is on top of the call price.
Signing a position transaction
The remove and rebalance calls answer with a transaction for the wallet that holds the position. Read the plan in the answer, then send the transaction as it is, from that wallet, on the chain named in it. It is built for the pool price at the moment of the call: if the price moves past the slippage asked for, or the 20 minutes pass, it reverts and nothing changes. Ask again for a fresh one.
const { transaction } = await paidAnswer.json();
await wallet.sendTransaction({
to: transaction.to,
data: transaction.data,
value: BigInt(transaction.value),
}); // from transaction.from, on chain transaction.chainIdQuestions
Do I need an account or an API key?
No. A paid call is authorised by the payment itself. The only thing an agent needs is a wallet holding USDC on Base.
What does the agent's wallet need?
USDC on Base. The payment is a signed USDC authorisation that the payment facilitator submits, so the wallet needs no ETH to pay for a call. Sending a position transaction the API returns is different: that is the agent's own transaction and needs gas on the position's chain.
When is a call not charged?
Every unpaid call gets the price first. After payment is checked, the call is settled only if it is answered: a request with bad input, a token that is not found, a position the address does not hold, a transaction that would revert, or a failure upstream is not charged.
Does ToknWrks ever hold or move my funds?
No. The data calls only read public chain data. The position calls return an unsigned transaction; the agent's own wallet signs and sends it. Nothing is signed or sent from ToknWrks.
Why Uniswap V4 only for remove and rebalance?
On V4 the whole action is one transaction with no token approvals. A V3 rebalance is four transactions that each depend on what the one before paid out, which does not fit one call.
Rather do it by hand? The same data is in the app: Portfolio, Tokens.