Skip to main content

Overview

Data sources define what blockchain data will be ingested and how it will be transformed. Each data source specifies:
  • The type of blockchain (e.g., Ethereum)
  • The smart contract to index
  • Which network the contract is on
  • When to start indexing
  • How to transform the data (mappings)

Data Source Fields

String
required
The type of data source.Possible values:
  • ethereum/contract - Ethereum smart contract data source
String
required
The name of the source data. Will be used to generate APIs in the mapping and also for self-documentation purposes.Must be unique across all data sources in the manifest.
String
required
For blockchains, this describes which network the subgraph targets.Supported Ethereum networks:
  • mainnet - Ethereum Mainnet
  • goerli - Goerli testnet
  • sepolia - Sepolia testnet
  • matic - Polygon Mainnet
  • mumbai - Polygon Mumbai testnet
  • arbitrum-one - Arbitrum One
  • optimism - Optimism Mainnet
  • bsc - BNB Smart Chain
  • gnosis - Gnosis Chain (formerly xDai)
  • fantom - Fantom Opera
  • avalanche - Avalanche C-Chain
  • celo - Celo Mainnet
For an up-to-date list, see the graph-cli code.
EthereumContractSource
required
The source data on a blockchain such as Ethereum.See Ethereum Contract Source for details.
Mapping
required
The transformation logic applied to the data prior to being indexed.See Mappings for complete documentation.

Ethereum Contract Source

The source field for Ethereum data sources specifies which contract to index and from which block to start.
String
required
The address of the smart contract on the blockchain.Must be a valid Ethereum address (0x-prefixed hex string).
String
required
The name of the ABI for this Ethereum contract.Must reference an ABI defined in the mapping.abis section.
BigInt
The block number to start indexing this data source from.Recommended: Set this to the block where your contract was deployed to improve sync performance.

Example

Data Source Templates

Data source templates allow you to create data sources dynamically at runtime. This is useful when:
  • New contracts are created by a factory contract
  • You need to index multiple instances of the same contract type
  • Contract addresses aren’t known at deployment time

Template Structure

A data source template has all the same fields as a normal data source, except:
  • No address field under source (address is provided when creating the template instance)
  • Must be defined in the templates array at the top level of the manifest
String
required
Unique name for the template. Used when creating template instances in mapping code.
String
required
Must be ethereum/contract for Ethereum templates.
String
required
The network this template targets.
Object
required
Source configuration without an address field.
Mapping
required
The mapping configuration for this template. Same structure as regular data sources.See Mappings for details.

Creating Template Instances

In your mapping code, create a new data source from a template using:

Template Example

Multiple Data Sources

You can define multiple data sources to index multiple contracts:

Best Practices

Always set startBlock to the block where your contract was deployed. This significantly improves indexing performance by avoiding unnecessary block processing.You can find the deployment block on block explorers like Etherscan.
Choose clear, descriptive names for your data sources. These names:
  • Appear in generated code
  • Help with debugging
  • Make your manifest self-documenting
Good: UniswapV2Factory, USDC Bad: Contract1, Token
For templates, use names that indicate they are templates and what they create:
  • Good: PairTemplate, ERC20Token
  • Avoid: Pair (ambiguous if you also have a Pair entity)
Ensure all data sources and templates in your manifest target the same network. Mixing networks in a single subgraph is not supported.
The abi field in source must match a name in the mapping.abis array. Double-check that:
  • Names match exactly (case-sensitive)
  • The ABI file exists at the specified path
  • The ABI contains all events/functions you’re handling

Common Patterns

Single Contract

Indexing a single deployed contract:

Factory + Template

Indexing a factory that creates multiple contract instances:
Indexing several contracts that interact:

Next Steps

Mappings

Configure event handlers and mapping logic

Manifest Spec

View complete manifest specification