Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

API Reference

Templar exposes three programmatic surfaces. The backend HTTP API is the main reference for applications and integrators; the gateway JSON-RPC service and direct contract calls are lower-level paths for those who need them. The generated Rust documentation covers the contract types every surface returns.

Backend HTTP API

The backend HTTP API is the primary way to read protocol data and prepare user flows without handling contract calls yourself: a conventional web API over HTTPS with JSON request and response bodies. Its interactive documentation is the authoritative catalogue of endpoints, parameters, schemas, examples, and error responses:

api.templarfi.org/docs

The live reference is split into eight OpenAPI documents:

APIUse it forLive reference
MarketsMarket configuration and metrics, positions, wallet balances, prices, and asset metadataMarkets, accounts, prices, assets
LendingPreparing borrow, repay, collateral, and supply transactionsBorrow, supply
SwapsSupported tokens, quotes, deposit confirmation, and swap statusGet a quote, check status
BridgePreparing and tracking NEAR Intents deposits and withdrawalsDeposits and withdrawals
AnalyticsWarehouse-backed views, protocol state, metrics, and indexed eventsViews, state, metrics, events
CampaignsCampaign periods, Merkl data and rewards, and NEAR-to-Stellar payout linksCampaigns
ComplianceAdvisory off-chain wallet screeningScreen a wallet
RelayerSponsored submissions, account history, and universal accountsSubmissions, accounts, universal accounts

The server base URL shown by the live specifications is https://api.templarfi.org/v1. Where an operation requires authentication, its specification marks that requirement and uses the X-API-Key header. Use the version displayed by the selected live specification and its downloadable OpenAPI document rather than copying schemas from this guide.

Use this guide for protocol semantics behind the responses: Risk Parameters explains market configuration fields, Oracles explains price provenance, and Stellar Curated Vaults explains vault behavior.

Rust API Documentation

The generated Rust API documentation, built from the contract sources with cargo doc, is the authoritative reference for every contract type, method, argument, and error. It is served under /doc/ on this site. Useful entry points:

CrateWhat it documentsEntry point
templar_commonTypes shared by every contract: market configuration and interface, asset and amount types, fees, interest-rate strategies, registry recordstemplar_common
Market configurationThe immutable per-market parameters listed on Risk ParametersMarketConfiguration
Market interfaceEvery method a market exposes, with argument and return typesMarketExternalInterface
Interest-rate strategiesThe Linear, Piecewise, and Exponential2 curvesInterestRateStrategy
Registry recordsThe Deployment record (version key, code hash, block height) returned by get_deploymentDeployment
templar_proxy_oracle_kernelThe chain-agnostic proxy oracle pipeline: sources, freshness filters, aggregation, circuit breakerstemplar_proxy_oracle_kernel
templar_vault_kernelThe chain-agnostic vault state machine, fee math, and withdrawal queuetemplar_vault_kernel
Contract cratesThe NEAR contract entry points themselvestemplar_market_contract, templar_registry_contract, templar_proxy_oracle_near_contract

The /doc/ links resolve on the published site (docs.templarfi.org). When serving this guide locally with mdbook serve they return 404, because the Rust documentation is built separately by script/build-docs.sh and copied next to the guide.

Gateway JSON-RPC

Integrators who need transaction-level control without signing NEAR transactions directly can use the gateway service, a JSON-RPC API in front of the contracts. Its method catalog, generated from the service's own method registry, is at gateway/METHODS.md.

Calling Contracts Directly

Examples throughout this guide use near-cli-rs view calls. The pages that catalogue them:

  • Market: configuration, positions, snapshots, and the supply, borrow, and liquidate flows.
  • Registry: versions and deployments.
  • Oracles: proxy oracle feeds, cached prices, and circuit-breaker state.
  • Monitoring and Risk Management: the health checks Templar's own monitoring runs.

templarfi.org links to the published guide. The app should also expose a guide/API documentation link; that implementation belongs in the frontend repository.