Reference

TypeScript SDK

Build autonomous trading agents on the same guardrailed engine the MCP server uses.

The pouch-rwa package doubles as a TypeScript SDK. Everything the MCP server can do — discovery, classification, quoting, guardrailed execution — is importable, with the same policy engine enforcing the same limits.

npm install pouch-rwa

The Pouch class

The high-level entry point covering the common loop:

import { Pouch } from "pouch-rwa";

const pouch = new Pouch();

// find the real tokenized TSLA among the fakes
const results = await pouch.search("TSLA");
for (const candidate of results) {
  const profile = await pouch.profile(candidate.address);
  if (profile.tier === "official") {
    // bytecode-verified Robinhood stock token with live USDG liquidity
    await pouch.buyUsd(profile.address, 50); // $50, guardrails enforced
    break;
  }
}

console.log(await pouch.portfolio());

Methods

MethodWhat it does
address / keySourceThe wallet address and where its key came from
search(query)Find tokens by name or symbol
profile(address)Trust-tier classification with reasons
quote(tokenIn, tokenOut, amountIn)Executable price from the best live pool
swap(params)Guardrailed exact-input swap
buyUsd(token, usd, slippageBps?)Buy a USD amount of a token with USDG
sell(token, amount, slippageBps?)Sell a token amount back to its quote currency
send(params)Guardrailed outbound transfer (requires policy.transfers)
portfolio()ETH, USDG, and live balances of traded positions
limits()Active policy and rolling 24h budget usage
trades(limit?) / transfers(limit?)Recent history

Guardrail violations throw with a readable reason — catch them and let your agent adapt.

Lower-level building blocks

The primitives underneath are exported too, for agents that need finer control:

  • Discovery: searchTokens, profileToken, findQuotePools, findPairPools
  • Trading: getQuote, executeSwap, executeSend, getPortfolio, resolvePair
  • Guardrails & history: checkTradeAllowed, checkTransferAllowed, spentUsdLast24h, tradeHistory, transferHistory
  • Quoting & execution: bestQuote, swapV4, usdValue, ethUsdPrice
  • Market hours: usMarketStatus, OFF_HOURS_WARNING
  • Chain constants: CHAIN_ID, USDG, NATIVE, OFFICIAL_STOCK_CODEHASH, OFFICIAL_ISSUER, and the shared viem clients

All types (TokenProfile, QuoteResult, SwapResult, TradeRecord, …) are exported alongside.

Keys and config

The SDK reads the same wallet and policy as the MCP server: the key from ~/.pouch/wallet.json (or POUCH_PRIVATE_KEY), config from POUCH_CONFIG, ./pouch.config.json, or ~/.pouch/config.json. One pouch, one policy, whichever surface drives it.

On this page