Put the stock market in your app.
Stocklayer is the trading API for tokenized stocks on Robinhood Chain. Market data and checked trade plans for apps, wallets, and AI agents.
- Stock TokensOn Robinhood Chain
- StocklayerData, trade plans, and checks
- Apps, wallets, agentsBuilt on one integration
From a ticker to a checked trade.
Ask for a USDG-to-NVDA trade. Stocklayer resolves the stock token, checks the wallet, builds the route, and simulates the full sequence before returning anything to sign.
Your first checked trade plan.
Available now: the hosted sandbox, HTTP API, published TypeScript SDK, and all eight local MCP tools. Test keys use fixture prices, balances, quotes, and simulation results. Live USDG-to-NVDA quotes and unsigned plans have passed verification through Uniswap. Live routes depend on liquidity, provider access, and sufficient token and gas balances on Robinhood Chain. Never submit sandbox transactions to a real wallet.
Use Node.js 20.3 or later. This example spends 500 simulated USDG on NVDA with a test key. It needs no funded wallet and moves no money.
- Create a test key.Open the dashboard, create a test-environment API key, and enable the
trade:planscope. - Save and run the example.Save the code below as
quickstart.mjs. Install the SDK, replace the key placeholder with your test key, and run the file from your terminal. - Inspect the result.With no blocking project policy, the funded sandbox wallet returns an allowed plan with an approval followed by a swap.
npm install @stocklayer/sdkexport STOCKLAYER_PROJECT_KEY="stocklayer_test_..."node quickstart.mjsimport { StocklayerClient } from "@stocklayer/sdk";const stocklayer = new StocklayerClient({ baseUrl: "https://stocklayer.dev/api/v0", apiKey: process.env.STOCKLAYER_PROJECT_KEY,});const plan = await stocklayer.trades.plan({ wallet: "0x0000000000000000000000000000000000000001", intent: { type: "exact_input", tokenIn: "USDG", tokenOut: "NVDA", amountIn: "500", }, slippageTolerance: 0.5,});console.log(JSON.stringify({ status: plan.status, verdict: plan.verdict.outcome, simulation: plan.simulation.status, steps: plan.steps.map(step => step.kind), signing: plan.signing.mode,}, null, 2));{ "status": "ready", "verdict": "allow", "simulation": "passed", "steps": ["approve", "swap"], "signing": "wallet_controlled"}The SDK returns the full plan, including quote bounds, policy checks, expiry, and plan.signing.unsignedTransactions. This example prints a summary.
Authenticate server-side.
Create a test or live project key in the dashboard, pass it as a bearer token, and keep it in server environment variables. Keys are isolated by environment and never belong in a browser bundle. The API, SDK, and MCP server do not require token ownership.
Authorization: Bearer $STOCKLAYER_PROJECT_KEYmarket:readAssets, prices, and corporate actionsportfolio:readWallet balancestrade:planQuotes, trade plans, and plan lookuptransaction:simulateStandalone transaction simulationTest keys run against a deterministic sandbox.
A stocklayer_test_ key never reaches Robinhood, the chain, 0x, or Uniswap. Every call is answered from a fixed catalog with repeatable balances, so your integration tests need no provider credential. Pick an outcome by wallet address, or force one with the x-stocklayer-scenario header.
- fundedFunded; approval required before the swap
0x0000000000000000000000000000000000000001 - approvedFunded; approval already granted
0x0000000000000000000000000000000000000002 - insufficient_balanceHolds 1 USDG; plans fail closed
0x0000000000000000000000000000000000000003 - zero_balanceEmpty wallet
0x0000000000000000000000000000000000000004 - simulation_failedPlan is blocked with no signable transactions
0x0000000000000000000000000000000000000005 - provider_degradedQuote provider returns a retryable error
0x0000000000000000000000000000000000000006
Any other wallet behaves like zero_balance. The symbol HALT reports a trading halt. Plan and quote identifiers repeat when you send the same x-request-id. Sandbox responses carry x-stocklayer-sandbox: on.
Every plan tells you whether to allow, review, or block it.
Stocklayer first simulates the full sequence, then applies the active immutable policy for that project. Policies can allow or block stocks and payment tokens, and set warning or blocking thresholds for trade size and requested slippage. Every result includes structured checks a person or coding agent can explain.
One API. Explicit contracts.
All routes are versioned under /api/v0. Quantities use exact decimal strings, addresses are checksummed, and every response includes a request ID.
/assetsList canonical market assets
GET/assets/{symbol}Resolve a symbol to its canonical asset
GET/prices/{symbol}Read underlying and token-equivalent prices
GET/corporate-actionsRead splits, dividends, and other actions
GET/portfolios/{wallet}Read balances and portfolio context
POST/quotesRequest an exact-input or exact-output quote
POST/trades/planBuild and simulate an unsigned trade plan
GET/trade-plans/{planId}Retrieve a stored plan before it expires
POST/transactions/simulateSimulate an ordered transaction sequence
A response your app can act on.
Successful HTTP responses return data and meta. Failures return error and meta, with a stable code, message, retryability, and details. The SDK unwraps data and throws a typed StocklayerApiError for failures.
The OpenAPI schema contains the full request and response contract, including executable examples. API discovery, health, and OpenAPI are public; market endpoints require a project key.
Financial context stays explicit.
Resolve symbols to the official Robinhood Chain deployment, status, multiplier, and provenance. Inactive and halted assets fail before a trade is routed.
Read splits, dividends, and other stock token actions with source IDs, process dates, affected deployments, and provenance. Filter by symbol, action type, and status.
Underlying reference quotes and multiplier-adjusted token values are separate fields. Token-equivalent prices use the current multiplier; reference prices are not executable quotes.
Read native ETH and ERC-20 balances. Use the symbols filter for specific positions. Default catalog scans are bounded and report when the portfolio is partial.
Quote responses preserve the route, exact base-unit amounts, maximum spend, minimum receipt, provider, and expiry. Use exact_input with amountIn, or exact_output with amountOut. Slippage is a percentage from 0.01 to 5 in 0.01 increments.
Required approvals and swap calldata are returned in execution order with wallet and intent context. Retrieve a stored plan with stocklayer.trades.get(planId). The SDK retries plan creation with a stable idempotency key; expired plans require a fresh request.
Built-in safety and active project rules produce an explainable allow, warn, or block decision bound to the durable plan.
Ordered calls run through eth_simulateV1 so prerequisite state changes carry forward before signing. Standalone simulation accepts one to eight transactions. An unsupported RPC can return a labeled independent-call fallback; a trade plan cannot return signable transactions without the required complete simulation evidence.
Know the route before the wallet signs.
Stocklayer normalizes quotes from configured routing providers. The Uniswap connection has passed a live USDG-to-NVDA plan check; 0x aggregation is not enabled. The selected provider, route, amounts, and slippage come back on the quote and plan so your app can show them and your policy can rule on them.
Keep the plan. Retrieve it by ID.
Stocklayer stores each plan with its original policy verdict and simulation evidence and returns it by ID from the same project environment until it expires. Your wallet signs and submits the transactions. Stocklayer never submits for you, so your app owns the receipt and the record of what it sent.
Give your agent the same checked trade flow.
@stocklayer/mcp exposes the API as eight MCP tools, so Claude, Cursor, and any other MCP client can look up an asset, price it, quote it, preflight a trade, and hand back an unsigned plan. The project key stays in the local MCP process. Your wallet still signs.
- Create a test key.In the dashboard, select the test environment and enable market:read, portfolio:read, trade:plan, and transaction:simulate to use all eight tools.
- Connect your client.Install Node.js 22.13 or newer. Add the configuration below to your client’s MCP settings, replace stocklayer_test_... with your key, and reconnect the server. This is a local stdio server, not a remote MCP URL.
- Run a sandbox plan.Ask: “Use Stocklayer to prepare an exact-input trade of 500 USDG for NVDA with wallet 0x0000000000000000000000000000000000000001. Show the verdict, checks, and unsigned transactions.” With no blocking project policy, expect ready, allow, and two unsigned transactions.
Check the request in your dashboard logs. If tools do not appear, check Node.js and reconnect the client. A 401 means the key is missing, invalid, or revoked; a 403 can mean a required scope is missing. Keep keys private and never paste wallet signing keys into the server.
{ "mcpServers": { "stocklayer": { "command": "npx", "args": ["-y", "@stocklayer/mcp"], "env": { "STOCKLAYER_PROJECT_KEY": "stocklayer_test_..." } } }}stocklayer_get_assetResolve a symbol to the real contract.stocklayer_get_priceReference and token price.stocklayer_get_corporate_actionsSplits, dividends, multiplier changes.stocklayer_get_portfolioBalances and positions for a wallet.stocklayer_create_quoteExecutable quote with the selected route and bounds.stocklayer_get_trade_planRetrieve a durable plan by ID.stocklayer_preflight_tradeBuild, simulate, and check an unsigned plan.stocklayer_simulate_transactionsSimulate one to eight unsigned transactions.Usage and diagnostics are built into every request.
API access is free during public launch. A successful new quote, trade plan, or simulation uses one checked-action unit. Reads, stored-plan lookups, idempotent replays, and failed requests use zero units. A blocked plan is a completed checked action and uses one unit. The dashboard shows your project allowance.
Every authenticated call counts toward the organization ceiling of 10,000 requests per UTC month. Minute limits apply to reads and checked actions. Follow the response limit headers and Retry-After when a request is throttled.
Authenticated responses identify the resolved environment and plan, plus minute and monthly allowance headers. The dashboard separates test and live usage, searches recent requests by ID, route, status, key prefix, error, symbol, or wallet, and exports daily usage as CSV.
Errors are designed for software.
Every failure includes a stable code, plain-language message, retryability signal, details, and request ID. Branch on the error code, never the prose.
INVALID_REQUESTCorrect the payload before retrying.ASSET_NOT_FOUNDThe symbol does not resolve to a canonical asset.INSUFFICIENT_BALANCEThe wallet cannot cover the maximum input the trade may spend.RATE_LIMITEDRetry after the minute window reported in the response.MONTHLY_LIMIT_EXCEEDEDThe project has exhausted its operator-assigned monthly allowance.ORGANIZATION_USAGE_LIMIT_EXCEEDEDThe organization has reached its monthly request ceiling.UPSTREAM_UNAVAILABLERetry according to the response signal.