# Best Practices for Integrating Onchain Token Data into Web2-Style Fintech Stacks

> Best practices for integrating onchain token data into Web2 fintech stacks: canonical IDs, raw vs display units, price types, and push-first real-time.

Source: https://www.codex.io/blog/onchain-data-api-fintech-integration
Published: 2026-07-17
Updated: 2026-10-29
Author: Codex

## Why Onchain Token Data Now Belongs in Web2 Fintech

Prediction markets, onchain tokens, and DeFi are no longer niche.

Pew reports that monthly trading volume on Kalshi and Polymarket jumped from under $5B in September 2025 to about $24B by April 2026. At the same time, [consumer apps](https://www.codex.io/blog/on-chain-data-api-social-gaming) and brokerages are racing to add crypto and prediction market exposure next to stocks and ETFs.

If you run a Web2-style fintech stack—portfolios, P&L, charts, or risk—you now need:

- Reliable, normalized token data across 80+ networks
- Trading-grade prices and charts for long-tail assets
- A way to map onchain assets to your existing off-chain identifiers and models

This guide walks through concrete best practices for integrating onchain token data into existing fintech systems, using Codex as the reference data API.

## Principle 1: Use Canonical IDs, Not Symbols

Token symbols are ambiguous. Canonical IDs are not.

There are many `USDT`s and `PEPE`s across chains and even on the same chain. If you key assets purely by symbol, your portfolio and risk models will eventually misattribute balances or prices.

**Reliable pattern for token identity:**

- Use **chain + contract address** as the canonical ID
- Codex uses `address:networkId` for token IDs
- Standards like **CAIP‑2/CAIP‑19** define chain-agnostic blockchain and asset identifiers you can adopt or map to

**Practical recommendations:**

- In your core data model, represent tokens as:
  - `token_id` (internal surrogate key)
  - `network_id` (or CAIP‑2 `chain_id`)
  - `contract_address` (or mint address)
  - Optional: `caip19_id` for future interoperability
- Treat [**symbol** and **name** as metadata](https://www.codex.io/token-enrichment), not as primary keys

**Using Codex as the source of truth:**

- Use the `token` and token-listing endpoints to fetch:
  - `address`
  - `networkId`
  - `decimals`
  - `symbol`, `name` (best-effort metadata)
  - `isScam` to filter bad assets early
- Persist `address + networkId` as your canonical foreign key from:
  - Positions and balances
  - Trades and fills
  - Chart and OHLC caches

This single decision avoids most of the “wrong asset” bugs that show up when a new meme coin launches.

## Principle 2: Store Raw Units and Display Units Separately

Onchain token balances are stored as integers in **base units**, not human-readable amounts.

The ERC‑20 spec explicitly says `decimals()` is optional, and many tokens don’t implement it correctly. If you only store “display” amounts, you lose the ability to recompute or adjust if metadata changes.

**Best-practice pattern:**

For every onchain amount (balance, transfer, trade size), store **two fields:**

- `amount_raw` – integer as seen onchain (e.g., `1000000`)
- `amount` – human-readable decimal (e.g., `1.0` for a 6-decimal token)

**Codex’s approach you can mirror:**

- Codex always ingests raw onchain amounts and then exposes normalized values using the token’s `decimals`
- Key fields like balances, pair stats, and `getBars` chart data are already decimals-adjusted

**Implementation steps:**

1. **Land raw events as-is**
   - From Codex webhooks or subscriptions, capture payloads into a raw store (e.g., BigQuery JSON or Snowflake `VARIANT`)
   - Do not coerce numeric strings prematurely
2. **Join token metadata**
   - Use Codex `token` query keyed by `address + networkId`
   - Persist `decimals` alongside the token
3. **Derive normalized amounts in a curated layer**
   - `amount = amount_raw / POWER(10, decimals)`
   - In SQL marts, materialize both `amount_raw` and `amount` columns

This allows you to fix decimals if a token’s metadata is corrected, without re-ingesting chain logs.

## Principle 3: Treat Price Types as Separate Concepts

In Web2 fintech, you already separate:

- Last traded price
- VWAP
- Reference price for risk/P&L

Onchain token data needs a similar separation. Codex’s API design reflects this.

**Key price concepts and which Codex endpoints to use:**

- **Portfolio/reference price** (what you show in balances):
  - Use `getTokenPrices` for fast, aggregated quotes
  - Prices are aggregated across valid pools
- **Venue-specific price** (per DEX or pair):
  - Use `pairMetadata` and pair-level endpoints
  - Preserve which pool/venue provided the price
- **Chart/analytics price** (OHLC, candles):
  - Use `getBars` with appropriate resolution and `currencyCode` (USD vs native)
  - Note Codex caps responses at **1,500 datapoints** per request; sub-1m resolutions only go back **24 hours**

**How to model this in your data warehouse:**

- Define three separate data sets:
  - `token_reference_prices` – output of `getTokenPrices` for portfolio valuation
  - `venue_prices` – pair-level prices keyed by `pair_id` or venue
  - `token_ohlc` – candles from `getBars`, keyed by token + resolution
- Persist a `price_type` dimension (e.g., `REFERENCE`, `VENUE`, `CHART`), instead of trying to funnel everything into a single `price` column.

This makes it much easier to:

- Explain P&L vs execution slippage
- Offer users a toggle between “global price” and “DEX price”
- Backtest strategies using historical pair-level data

## Principle 4: Design for Push-First, Not Poll-First, Real-Time

Polling APIs is simple but expensive and brittle at scale.

Most fintech UIs—trading terminals, live portfolios, alerting—are sensitive to latency and staleness. Spamming REST endpoints every second does not scale.

Codex is built with **push-first** real-time delivery:

- GraphQL queries for on-demand reads
- **Subscriptions** for continuously changing data
- **Webhooks** for events with full payloads, deduplication, and hash verification

**Recommended pattern:**

- Use **webhooks** and subscriptions to:
  - Capture trades, transfers, position changes, and prediction market events
  - Trigger enrichment jobs in your backend
- Use REST/GraphQL queries for:
  - Backfills and historical syncs
  - On-demand analytics and drill-down

**System design checklist:**

- Implement **idempotent consumers** using Codex webhook IDs or hashes
- Buffer incoming events into a streaming platform or queue (e.g., Kafka, Pub/Sub, SQS)
- Land events into your raw storage (BigQuery/Snowflake) before transforming

This approach minimizes API traffic, while keeping user-facing data fresh and consistent.

## Principle 5: Map Onchain Assets to Off-Chain Identifiers

To make crypto “feel native” in a Web2 fintech product, you must connect onchain tokens to your existing entities:

- Users and [KYC records](https://www.codex.io/blog/blockchain-compliance-for-banks-kyc-aml-and-onchain-data-controls)
- Portfolios and accounts
- Instruments, tickers, and risk buckets

**Core mapping patterns:**

1. **User ↔ Wallet mapping**
   - Maintain a `user_wallets` table with:
     - `user_id`
     - `wallet_address`
     - `network_id`
     - Status (self-custodied, managed wallet, testnet)
   - Use Codex wallet endpoints to [aggregate balances across chains](https://www.codex.io/blog/wallet-token-balance-apis-pillar-designing-ach-alchemy-payaware-apps-with-spenda)
2. **Internal instrument IDs ↔ Onchain tokens**
   - Extend your `instruments` table with:
     - `token_id`
     - `network_id`
     - `contract_address`
     - Optional: `caip19_id`
   - For synthetic products (e.g., a token basket), map multiple onchain tokens to a single instrument
3. **Prediction markets ↔ Asset universe**
   - For trading or analytics frontends, treat each market as a first-class instrument:
     - `market_id` (internal)
     - `venue` (e.g., `POLYMARKET`, `KALSHI`)
     - `codex_market_id` (if using Codex prediction market endpoints)
     - Event metadata (question, resolution date, underlying category)

Codex’s prediction market endpoints (`filterPredictionEvents`, `filterPredictionMarkets`, trader stats) help you normalize data from venues that otherwise expose incompatible APIs.

## Principle 6: Integrate Codex with BigQuery and Snowflake the Right Way

Most fintech stacks already centralize analytics in BigQuery or Snowflake.

The simplest pattern is:

1. Land raw Codex payloads in a semi-structured column
2. Build curated, typed marts for pricing, positions, markets, and analytics

### BigQuery + Codex

BigQuery’s native JSON support is essentially **schema-on-read:**

- JSON columns cannot be partitioned or clustered directly
- Nesting depth is limited to **500 levels**
- Ingestion via batch loads or **Storage Write API**

**Recommended architecture:**

- **Raw layer**
  - Table: `raw_codex_events`
  - Columns: `event_time`, `source` (e.g., `webhook`, `subscription`), `payload` (JSON)
  - Partition by `event_date` derived from `event_time`
- **Transform layer** (using SQL or Dataflow):
  - Extract fields like `networkId`, `address`, `amount_raw`, `event_type`
  - Join to `tokens` and `wallets` dimension tables
- **Curated marts:**
  - `token_balances` (per user/wallet/token)
  - `token_trades` (per trade with price, venue, slippage)
  - `prediction_positions` (per event/market/outcome)

This pattern lets you evolve schemas without constant migrations.

### Snowflake + Codex

Snowflake’s guidance on semi-structured data maps cleanly to onchain payloads:

- Use `VARIANT` while query needs are evolving
- Flatten into typed columns when you need better pruning and lower costs
- `VARIANT` has a max size of **128 MB** uncompressed (not usually an issue for Codex payloads)

**Recommended architecture:**

- **Landing table**
  - `raw_codex_events(payload VARIANT, event_time TIMESTAMP, source STRING)`
- **Staging views**
  - Access nested fields using `payload:<field>`
- **Typed tables** when patterns stabilize:
  - `trades_fact` with numeric columns for `amount_raw`, `amount`, `price`, `fee`
  - `tokens_dim` with canonical IDs and metadata

This approach gives your data and quant teams fast, SQL-native access to onchain data without losing the flexibility of semi-structured landing zones.

Here’s how the overall flow looks from Codex to your warehouse.

![Diagram of Codex onchain data flowing into raw storage, curated warehouse tables, and fintech apps](https://www.codex.io/blog/inline/onchain-data-api-fintech-integration-1.webp)
_Event data flows from Codex webhooks into raw JSON storage, then into curated tables for tokens, prices, and positions._

## Principle 7: Build Around Reliability, Latency, and Coverage

For trading-adjacent fintech apps, data quality is not negotiable.

When choosing an onchain data provider, optimize for:

- **Reliability & correctness** – consistent prices and balances, especially for long-tail tokens
- **Low latency** – Codex targets sub‑1 second freshness on paid plans
- **Coverage** – Codex indexes **70M+ tokens**, **700M+ wallets**, **80+ networks**, and **27B+ historical events**

Codex positions itself as the **fastest and most reliable blockchain data API** for token and prediction market data, and it already powers apps like Coinbase, TradingView, Uniswap, Magic Eden, Rainbow, MoonPay, and others.

When benchmarking Codex (or any provider), measure:

- Time-to-first-byte for critical endpoints (`getTokenPrices`, `getBars`)
- Freshness of prices vs major CEX quotes
- Coverage for:
  - Newly launched tokens
  - Launchpad-linked assets
  - Less common networks your users might hold

## Putting It All Together: Reference Architecture

A pragmatic reference architecture for Web2 fintech teams adding onchain data:

1. **Token & wallet model**
   - Canonical IDs: `networkId + address`
   - Store `decimals`, `symbol`, `name`, `isScam`
2. **Real-time ingestion**
   - Subscribe to Codex webhooks for transfers, trades, prediction events
   - Push into a queue or streaming system
3. **Raw data landing**
   - BigQuery JSON or Snowflake `VARIANT` tables for raw payloads
4. **Curated marts**
   - `tokens_dim`, `wallets_dim`, `markets_dim`
   - Facts for balances, trades, prices, prediction positions
   - Separate `REFERENCE`, `VENUE`, `CHART` price types
5. **APIs & UI layer**
   - Portfolio and P&L views backed by reference prices
   - Trading views and charts backed by `getBars` and pair stats
   - Prediction market frontends powered by Codex prediction endpoints

Follow these patterns and you can add “crypto-native” features [without rebuilding your entire stack](https://www.codex.io/blog/on-chain-data-apis-trading-apps).

## FAQ

### How should we key onchain assets in our existing instruments table?

Use a canonical combination of chain + contract address (e.g., networkId + address) rather than symbol. Optionally add a CAIP‑19 ID. Symbols and names should be treated as metadata, not keys.

### Do we really need to store both raw and normalized token amounts?

Yes. Store amount_raw as the onchain integer and amount as the decimals-adjusted value. ERC‑20 decimals() is optional and sometimes wrong; keeping raw units lets you fix and re-derive display amounts without re-ingesting data.

### Which Codex endpoints should we use for portfolio valuation vs charts?

For portfolio valuation, use getTokenPrices to fetch aggregated reference prices. For venue-specific analytics, use pair-level endpoints like pairMetadata. For charts and OHLC, use getBars, respecting its 1,500-datapoint per-request limit and resolution constraints.

### How do we integrate Codex data into BigQuery or Snowflake?

Land Codex responses as semi-structured data first—JSON in BigQuery, VARIANT in Snowflake. Then build curated SQL tables for tokens, balances, trades, prices, and prediction markets, flattening only the fields you query regularly for better performance.

### Why use Codex instead of building our own indexers and RPC-based ETL?

Indexing 80+ networks, normalizing 70M+ tokens and 700M+ wallets, and maintaining trading-grade prices is a multi-year infrastructure project. Codex exposes all of this via a unified GraphQL-style API with sub-second latencies, letting your engineers focus on product instead of chain plumbing.

### What is a compute unit?

Usage is metered in compute units. Every query, subscription message and delivered webhook costs a number of compute units based on the operation and the data it returns; the dashboard lists the base cost of each operation. Overage on Growth plans bills at the plan's rate plus 15%, from $115 to $138 per 1M compute units.

### What networks does Codex support?

80+ networks and counting, including Ethereum, Solana, Base, BNB Chain, Arbitrum, and Optimism, with new networks added regularly.

### What payment methods does Codex accept?

Card payments through the dashboard; enterprise customers can arrange invoicing.

### Is it easy to migrate to Codex?

Yes: the GraphQL API, TypeScript SDK, and comprehensive docs make migrations straightforward, and our team helps enterprise customers move over.
