Blockchain indexing for app backends
What it is
Blockchain indexing for an app backend is turning your contracts’ events into rows in the database your app reads, and keeping those rows in step with the chain; the service that does it is called an indexer.
Wallets, DeFi protocols and fintech apps need it because their screens and APIs read from tables, and reading the chain directly for every screen is slow and can’t sort, filter or join.
Goldsky decodes the events and keeps your tables current, correcting rows when the chain replaces recent blocks, while the API your app calls and the data model behind it stay yours.
You can build it two ways: stream decoded events into your own database with Turbo Pipelines, or index them in a subgraph that Goldsky hosts behind a GraphQL API.
Who it’s for
Wallet apps, DeFi protocols and fintech apps that serve their users from their own backend.
How blockchain indexing keeps an app’s database in sync
The diagram follows one user action from the chain to the screen your app serves from its own tables, and shows who does each step. Your setup may differ.
Ways to index blockchain data for an app backend
Rows from the pipeline go into a database you own, which your API queries and joins with your app’s data; the subgraph keeps the index with Goldsky and serves it over GraphQL.
- Best for
- High event volume, joined with your own tables
- Products
- Turbo
- What you run
- The destination: your database, queue or bucket, or a Postgres database Goldsky hosts
- What you write
- Pipeline YAML and SQL; TypeScript transforms when needed
- Where your data lives
- In your own database or systems
- How results reach you
- Pushed to you
- Best for
- Moderate traffic, with no database to run
- Products
- Subgraphs
- What you run
- Nothing; Goldsky runs indexing, storage and the API
- What you write
- A schema and mapping handlers, or a no-code or low-code config for simple contracts
- Where your data lives
- Hosted by Goldsky
- How results reach you
- You query; changes are pushed
| Usual setupOption 1: Stream to your database | Option 2: Hosted subgraph | |
|---|---|---|
| Best for | High event volume, joined with your own tables | Moderate traffic, with no database to run |
| Products | Turbo | Subgraphs |
| What you run | The destination: your database, queue or bucket, or a Postgres database Goldsky hosts | Nothing; Goldsky runs indexing, storage and the API |
| What you write | Pipeline YAML and SQL; TypeScript transforms when needed | A schema and mapping handlers, or a no-code or low-code config for simple contracts |
| Where your data lives | In your own database or systems | Hosted by Goldsky |
| How results reach you | Pushed to you | You query; changes are pushed |
Record the user’s action on the chain
A mint, trade or claim happens when the user’s transaction is included in a block.
Your contract emits an event that describes what happened. For a short time the newest blocks can still be replaced (a reorg), so an event seen once may disappear or change.
Decode the event
Handled by Goldsky TurboContract events arrive as encoded bytes, and your app needs typed fields like player, item and amount.
Each event is decoded with the contract’s ABI into a row with a stable ID, so the same event always maps to the same row. Without that ID, a repeated delivery becomes a duplicate row.
A Turbo Pipelines SQL transform decodes each log with
Decode logs with _gs_log_decode (opens in a new tab)_gs_log_decode()and your ABI, and carries the dataset’sidthrough as the row key.Sync your app’s database
Handled by Goldsky TurboYour app reads its own tables, so each decoded event has to land there as it happens.
Rows are inserted or updated by key, so a delivery that repeats overwrites the same row. A table written with plain inserts collects duplicates after any restart.
The database sink in Turbo Pipelines creates the table if it doesn’t exist and upserts on the
Upsert rows into Postgres (opens in a new tab)primary_keyyou set.Correct rows after a reorg
Handled by Goldsky TurboWhen the chain replaces recent blocks, the events in them can vanish or change, and your tables have to follow.
Rows from a replaced block have to be deleted or updated. If they aren’t, your app shows items and balances the chain no longer has.
Goldsky’s Turbo Pipelines passes reorg corrections through as deletes and updates, and keyed database sinks apply them to the same rows.
How reorgs reach your tables (opens in a new tab)Serve the app from your tables
Your screens and API read from the database, which can sort, filter and join in ways the chain can’t.
Your API queries the tables and combines them with your own data, such as user profiles. Screens that show money can mark the newest rows as pending until they’re a few blocks deep.
What to know about streaming into your app’s database
- Goldsky runs the pipeline; you run the database and the API on top of it, and design the tables.
- Rows arrive as blocks do, so nothing in your backend polls the chain.
- Tables keyed on a
primary_keytake reorg corrections as updates and deletes, so they follow the chain without code on your side. - History can be loaded from your contracts’ first block before the pipeline follows new ones.
Record the user’s action on the chain
A mint, trade or claim happens when the user’s transaction is included in a block.
Your contract emits an event that describes what happened. For a short time the newest blocks can still be replaced (a reorg), so an event seen once may disappear or change.
Define the schema and mappings
The index has to know which events matter and how to turn each one into records your app can query.
The schema sets the records (entities) and their fields, and the mappings are the code that creates or updates them from each event. A field left out can’t be queried later without a new version and a fresh index.
Index the events and follow reorgs
Handled by Goldsky SubgraphsYour app needs every past event and each new one, with records that match the chain after a reorg.
Indexing starts at the block where the contract was deployed, runs every event through the mappings and then keeps up with new blocks. Records from a replaced block have to be rolled back, or the app shows state the chain no longer has.
Goldsky Subgraphs runs the same mapping code as other subgraph hosts and stores every version of each entity with its
Deploy a subgraph (opens in a new tab)block_range, which is how changes from replaced blocks are told apart and rolled back.Serve the index over GraphQL
Handled by Goldsky SubgraphsYour app reads the data by sending queries to an endpoint.
The endpoint keeps responding while new blocks are indexed. Anyone who finds an open endpoint can query it, so data that isn’t meant to be public needs one that requires a key.
Subgraphs gives every subgraph and tag its own GraphQL endpoint. You can switch a tag to a private endpoint, which accepts only requests with a project API token in the
Set up public and private endpoints (opens in a new tab)Authorizationheader.Push record changes to your backend
Handled by Goldsky SubgraphsSome features, such as a notification after a mint, react to a change instead of asking for it.
Each change reaches your server with enough detail to tell a new record from an update or a rollback. Changes can arrive out of order, so your server compares versions instead of trusting arrival order.
You can attach a webhook to an entity in Subgraphs, and every change arrives as an
Set up subgraph webhooks (opens in a new tab)INSERT,UPDATEorDELETEpayload carrying the version’sblock_range.Serve the app from the index
Your screens query the index, through one address that survives new versions of the subgraph.
Point the app at a tag, a stable name you move to a new version once it has caught up. A hard-coded version turns every subgraph update into an app release too.
What to know about a hosted subgraph
- Goldsky runs indexing, storage and the API, so the data lives in the subgraph, not in your database.
- The index holds only what your contracts emit; joining it with your own data happens in your app.
- Indexing and query delay grow as event volume climbs, so contracts with heavy traffic suit a pipeline better.
- Subgraphs written for other hosts deploy without code changes.
What you control
- Your team
- Serve the app from your tables
Security and deployment
- SOC 2 Type IIIndependently audited security controls.
- Dedicated infrastructureSingle-tenant options for production workloads.
- Data residencyCloud, on-premises or co-located.
More use cases that stream chain data to your systems
- Blockchain data in your own warehouseStream decoded chain data into your own warehouse for BI.
- Power a blockchain data productFeed a resold data product with multi-chain data and fast backfills.
- Onchain data for index and benchmark calculationsSupply the onchain fundamentals an index or benchmark provider calculates from.
- Onchain data for risk ratings and scoringSupply wallet and protocol history to the models that rate DeFi risk or score borrowers.
- How to build a subgraphWrite a schema and mappings for your contracts and serve the index over a hosted GraphQL API.
- Speed up subgraph indexing and queriesCut the time a subgraph takes to sync, reindex and answer queries.
- Replace in-house blockchain ETL and cut its costRetire your own nodes and ETL jobs and load the same chain data tables from a managed pipeline.
Use cases built the same way
- Authorize and capture stablecoin paymentsHold a buyer’s stablecoins in an escrow contract at checkout, capture them to the merchant as orders ship, void what can’t be filled and refund after capture.
- Programmable escrow for B2B stablecoin paymentsHold a buyer’s stablecoin payment until delivery, a milestone or a deadline, then release it to the seller or refund the buyer.
- Cross-chain transfer trackingSee every cross-chain stablecoin transfer as settled, in flight or stalled, and catch the stuck ones.
- Stablecoin dollar accountsOffer dollar accounts held in stablecoins, with balances and history kept in step with the chain.
Index blockchain data for an app backend with Goldsky
We’ll map it to your systems and show you what Goldsky runs, so your team builds the product, not the pipelines underneath it.