Overview
Mappings define the transformation logic that converts blockchain data into entities that can be queried through your subgraph’s GraphQL API. Each mapping specifies:- Which events, calls, or blocks to handle
- Which entities are affected
- Which ABIs are needed
- The AssemblyScript code that processes the data
Mapping Fields
Must be
ethereum/events for Ethereum event mappings.Semver string of the version of the Mappings API that will be used by the mapping script.Current recommended version:
0.0.7The language of the runtime for the Mapping API.Possible values:
wasm/assemblyscript- AssemblyScript compiled to WebAssembly
A list of entities that will be ingested as part of this mapping.Must correspond to entity names defined in your GraphQL schema.
ABIs for the contract classes that should be generated in the mapping.Each ABI entry has a
name and file field.Handlers for specific events, which will be defined in the mapping script.See Event Handlers for details.
A list of functions that will trigger a handler and the name of the corresponding handlers in the mapping.See Call Handlers for details.
Defines block filters and handlers to process matching blocks.See Block Handlers for details.
The path of the mapping script (AssemblyScript file).
Event Handlers
Event handlers are triggered when specific events are emitted by the smart contract. This is the most common type of handler.An identifier for an event that will be handled in the mapping script.For Ethereum contracts, this must be the full event signature to distinguish from events that may share the same name.Important:
- No alias types can be used
uintwill not work,uint256must be used- Use indexed parameters as shown in the ABI
The name of an exported function in the mapping script that should handle the specified event.This function must be exported from your mapping file.
A
0x prefixed hex string.If provided, events whose topic0 is equal to this value will be processed by the given handler. When topic0 is provided, only the topic0 value will be matched, and not the hash of the event signature.This is useful for processing anonymous events in Solidity, which can have their topic0 set to anything.By default, topic0 is equal to the hash of the event signature.Set to
true to receive the transaction receipt in the handler.When enabled, the handler will have access to receipt data including logs, gas used, and status.Event Handler Example
- Manifest
- Mapping Code
Call Handlers
Call handlers are triggered when specific functions are called on the smart contract. Useful for tracking state changes that don’t emit events.An identifier for a function that will be handled in the mapping script.For Ethereum contracts, this is the normalized function signature to filter calls by.
The name of an exported function in the mapping script that should handle the specified call.
Call Handler Example
- Manifest
- Mapping Code
Block Handlers
Block handlers are triggered for every block (or blocks matching a filter). Useful for tracking time-based state changes or aggregate statistics.The name of an exported function in the mapping script that should handle the block.
Definition of the filter to apply. If none is supplied, the handler will be called on every block.See Block Handler Filters for details.
Block Handler Filters
The selected block handler filter.Possible values:
call- Only run the handler if the block contains at least one call to the data source contract
Block Handler Example
- Manifest
- Mapping Code
Pre-declared Calls
Available from spec version 1.2.0. Struct field access available from spec version 1.4.0. Declared calls are performed in parallel before the handler is run and can greatly speed up syncing. Mappings access the call results simply by usingethereum.call from the mappings.
A label for the call for error messages and identification.
The call specification in the format:
<ABI>[<address>].<function>(<args>)Components:ABI- The name of an ABI from theabissectionaddress- An expression resolving to the contract addressfunction- The name of a view function in the contractargs- Expressions for the function arguments
Expression Types
The expressions in pre-declared calls can be:| Expression | Description |
|---|---|
event.address | The address of the contract that emitted the event |
event.params.<name> | A simple parameter from the event |
event.params.<name>.<index> | A field from a struct parameter by numeric index |
event.params.<name>.<fieldName> | A field from a struct parameter by field name (spec version 1.4.0+) |
Pre-declared Calls Example
- Manifest
- Mapping Code
ABI Configuration
ABIs must be specified for all contracts your mapping interacts with:The name used to reference this ABI in the mapping code and elsewhere in the manifest.
The path to the ABI JSON file.
ABI Example
Complete Mapping Examples
- Basic ERC20
- With Call Handlers
- With Block Handlers
- With Pre-declared Calls
Best Practices
Choose the Right Handler Type
Choose the Right Handler Type
- Event handlers: Best for most use cases. Fast and efficient.
- Call handlers: Use when you need to track function calls that don’t emit events.
- Block handlers: Use sparingly, only for time-based aggregations or when you absolutely need to process every block.
Use Pre-declared Calls
Use Pre-declared Calls
Pre-declared calls (available from spec 1.2.0+) can significantly improve indexing performance by:
- Fetching data in parallel before the handler runs
- Reducing the number of RPC calls during sync
- Making your code cleaner
Specify Event Signatures Correctly
Specify Event Signatures Correctly
Common mistakes:
- Using
uintinstead ofuint256 - Missing
indexedkeyword - Wrong parameter order
- Using alias types
Handle Null Cases
Handle Null Cases
Always check if entities exist before using them:
Keep Handlers Fast
Keep Handlers Fast
- Avoid complex computations in handlers
- Don’t load entities unnecessarily
- Use batch operations when possible
- Minimize contract calls (use pre-declared calls instead)
List All Affected Entities
List All Affected Entities
The
entities array should include all entities that your mapping creates or modifies. This:- Documents your mapping’s behavior
- Helps with debugging
- May be used for optimization in future versions
Handler Execution Order
Within a single transaction or block, handlers execute in this order:- Call handlers - In the order calls were made
- Event handlers - In the order events were emitted
- Block handlers - After all other handlers
Error Handling
By default, any error in a handler will cause the subgraph to stop syncing. To allow handlers to fail without stopping the subgraph:- Set
specVersionto0.0.4or higher - Add
nonFatalErrorsto thefeatureslist - Use try-catch or if-null checks in your mapping code
Next Steps
Manifest Spec
View complete manifest specification
Data Sources
Learn about data source configuration

