BNB Smart Chain Mainnet
- Type
- mainnet
- Protocol
- ethereum
- Identifier
- bsc
- Chain ID
- eip155:56
- Native Currency
- BNB
Indexing Data on BSC
BNB Smart Chain (BSC) is a high-performance, EVM-compatible Layer 1 that has run in production since September 2020, with sub-second block times and transaction fees of a fraction of a cent. It hosts one of the largest DeFi ecosystems in crypto — tens of billions of dollars in total value locked across protocols like PancakeSwap (DEX), Venus (lending), and 1,500+ live dApps spanning trading, gaming, and payments.
The Graph can index that onchain activity, including DEX swaps, pools, and liquidity; lending and borrowing positions; token transfers and holder balances; and contract events. That powers DeFi frontends, analytics dashboards, block explorers, portfolio trackers, and onchain agents without teams having to run their own indexing infrastructure.
BSC is supported by The Graph in two ways:
- Subgraphs: The blockchain indexing standard perfect for small to medium-sized projects that need hosted APIs. Data consumers manage their service in Subgraph Studio while Indexers on The Graph Network sync and serve queries.
- Substreams: A real-time streaming engine for transaction-heavy projects, high-throughput chains, and institutions that need custom data infrastructure. Data consumers can manage their service and get indexing via The Graph Market.
Find Existing Subgraphs on BSC
ExploreBefore you build, check whether the data you need is already live. Many of the most-used protocols on BSC publish Subgraphs on The Graph that you can query today:
Browse Graph Explorer to search all published Subgraphs on BSC by protocol, signal, and query volume before deciding to build your own.
Indexing BSC with Subgraphs
Get API KeyGetting smart contract data is hard. You write your own indexer, run your own database, and handle chain reorganizations yourself. Subgraphs remove that work, giving you an open API that you query with GraphQL.
BSC is EVM-compatible, so the Subgraph workflow is the same as on most EVM chains. You point a Subgraph at your BSC contract, define the entities you want, deploy and publish it through Subgraph Studio, and Indexers on The Graph Network keep those entities current and queryable.
Quick Start: Build Your Own Subgraph
Building a Subgraph for BSC takes five steps:
- Create your Subgraph in Subgraph Studio.
- Build a Subgraph project from your smart contract.
- Deploy it to Subgraph Studio.
- Publish it to The Graph Network from Subgraph Studio.
- Query Subgraph with your API key.
See the Subgraph pricing page for current query rates and free-tier limits.
Step 1: Create your Subgraph in Subgraph Studio
Open Subgraph Studio and connect your wallet. Create a Subgraph, copy its slug and your deploy key from the Subgraph details page to use in the CLI. For a full walkthrough, see Using Subgraph Studio.
Step 2: Initialize and build your Subgraph project
Install the Graph CLI, verify the install, and initialize a project from your BSC contract:
1# Install the Graph CLI (or with yarn: yarn global add @graphprotocol/graph-cli)2npm install -g @graphprotocol/graph-cli@latest34# Verify the install5graph --version67# Initialize from your BSC contract8graph initThe CLI walks you through a set of prompts:
- Protocol: choose
ethereum. BSC is EVM-compatible. - Subgraph slug: use the slug of the Subgraph you created in Subgraph Studio, for example
my-bsc-subgraph. - Directory: where the project is scaffolded.
- Ethereum network: select
bscfrom the list of supported networks. - Contract address: the address of the contract you want to index. Find it on bscscan.com.
- ABI: if the CLI cannot fetch the ABI, export it from your build artifacts or the BscScan contract page. Supply it as a JSON file.
- Start block: the block your contract was deployed at. Set this so indexing does not scan from genesis. The explorer shows the deployment block.
- Contract name: the name of your contract.
- Index contract events as entities: set this to
true. The CLI then scaffolds entities and mappings for every emitted event.
To customize your Subgraph, you work with three files:
- Manifest:
subgraph.yamldefines which data sources your Subgraph indexes. - Schema:
schema.graphqldefines the entities you want to query. - Mappings:
src/mapping.tsuses AssemblyScript that translates on-chain events into your entities.
Point the manifest at BSC:
1dataSources:2- kind: ethereum3 name: MyContract4 network: bsc5 source:6 address: '0xYourBscContractAddress'7 abi: MyContract8 startBlock: 123456 # your contract's deployment blockFor a full walkthrough of schema and mapping authoring, see Creating a Subgraph. Then generate types and build:
1graph codegen && graph buildStep 3: Deploy to Subgraph Studio
Authenticate the CLI and deploy your Subgraph to Subgraph Studio:
1# Authenticate with the deploy key from your Subgraph details page2graph auth <DEPLOY_KEY>34# Deploy to Subgraph Studio (the CLI asks for a version label such as 0.0.1)5graph deploy <SUBGRAPH_SLUG>Deploying pushes your Subgraph to Subgraph Studio, where you can test it in the playground, query the development endpoint, and check indexing logs. It does not publish it to the decentralized network yet.
Optional: Verify locally with Graph Node Dev Mode
Run your Subgraph on your machine with Graph Node Dev Mode (GND), pointed at an RPC endpoint for BSC. From your Subgraph project directory:
1# Install gnd with the Graph CLI2graph node install34# Build, deploy, and index your Subgraph locally, redeploying on changes5gnd --ethereum-rpc bsc:https://bsc.rpc.service.pinax.network --watchQuery your Subgraph at http://localhost:8000/subgraphs/name/subgraph-0/ until your entities look right, then publish. On Windows, gnd also needs a --postgres-url. See Graph Node Dev Mode for setup.
Step 4: Publish & Curate on The Graph Network
Publishing a Subgraph is an on-chain action that:
- makes it available for Curators to add signal that attracts Indexers,
- makes your Subgraph available for decentralized Indexers to index,
- and makes it publicly searchable and queryable in Graph Explorer.
To publish, open your Subgraph in the Subgraph Studio dashboard and click Publish. Connect your wallet, add metadata (name, description, image), and confirm the transaction. Publishing happens on Arbitrum One, where The Graph’s protocol contracts live, not on BSC. For details, see Publishing a Subgraph, which also covers publishing from the CLI with graph publish.
During the publish transaction, you can add GRT in curation signal to save on gas fees. Signal tells Indexers that your Subgraph is worth indexing. Any Subgraph with 1,000 GRT or more signal will be likely to be indexed quickly; without signal, no Indexer is incentivized to pick up your Subgraph.
Step 5: Query your Subgraph
After you publish, open your Subgraph in Graph Explorer and copy its query URL from the Query button.
- Create an API key from the API Keys dashboard at thegraph.com/studio. This dashboard handles API keys and billing for The Graph Network.
- Send GraphQL queries to the query URL with your API key.
See the Subgraph pricing page for query rates, and Querying The Graph for the full query API.
Indexing BSC with Substreams
Get API KeySubstreams is a parallelized, real-time streaming engine for extracting and transforming blockchain data. Where a Subgraph indexes into a hosted GraphQL API, Substreams lets you consume high-throughput data directly or via 10+ supported sinks. BSC is served with the extended EVM block model, so Substreams modules have access to full transaction, call, and event data. Modules are written in Rust and composed into reusable packages.
Find an Existing Module on Substreams.dev
Before writing any code, check the Substreams Registry for a package that already does what you need. The registry hosts community- and team-built modules — DEX trades, token transfers, contract events, and more — that you can run as-is or compose into your own pipeline. Search for the protocol or data you want on BSC; if a module fits, you can consume its output directly or import it as a dependency in your own project.
Develop Your Own Substreams Module
If no existing module fits, you can build one. The Substreams Quick Start is the full walkthrough. In short:
- Install the Substreams CLI and get a key at The Graph Market.
- Scaffold a project with
substreams initand choose the EVM path, pointing it at your BSC contract. - Write your extraction and transformation logic in Rust, then run
substreams build. - Stream the output with
substreams gui(orsubstreams run) to iterate, then publish your package to the Substreams Registry to reuse or share it.