Engineer reviewing real-time oracle price feeds on ultrawide monitor, data visualizations on second screen, clean desk setup in bright apartment.
Protocols

AssemblyScript Mapping API

Specification for the subgraph mapping runtime environment and graph-ts library, including host imports for cryptographic functions, data source contexts, and logging. Changes affect all subgraph developers writing transformation logic.
introduction
MAPPING RUNTIME SPECIFICATION

Introduction

The AssemblyScript Mapping API defines the deterministic runtime environment for all subgraph transformation logic on The Graph.

The AssemblyScript Mapping API is the foundational specification for the graph-ts library and the host environment in which subgraph mappings execute. Every subgraph developer writing event handlers, call handlers, or block handlers interacts with this API, which provides the bridge between raw blockchain data and the structured entities stored in the subgraph's database. The specification governs critical host imports for cryptographic functions (crypto.keccak256), data source context management (dataSource.context), logging (log.info), and Ethereum-specific data types (Address, BigInt, Bytes).

Changes to this API are high-impact events for the entire ecosystem. A modification to a core type, a new required host function, or a deprecation of an existing import can break every active subgraph that depends on the altered behavior. This creates a cascading risk: indexers must upgrade their Graph Node software to support the new API, subgraph developers must refactor and redeploy their mappings, and all downstream API consumers—dApps, wallets, analytics dashboards—must verify that query responses remain consistent after the transition. The deterministic indexing guarantee means that any divergence in mapping execution across indexers will fracture the network's data consensus.

For teams operating production subgraphs, the AssemblyScript Mapping API is not an abstract standard but a direct dependency with a narrow compatibility surface. Chainscore Labs can audit mapping codebases against upcoming API revisions, identify non-deterministic patterns that violate indexing guarantees, and model the downstream impact of host import changes on query consumers. A proactive review before a graph-ts major version bump is the difference between a planned migration and an emergency redeployment.

ASSEMBLYSCRIPT MAPPING API

Quick Facts

Operational impact and compatibility assessment for changes to the subgraph mapping runtime and graph-ts library.

AreaWhat changesWho is affectedAction

Host Import APIs

New or modified cryptographic, logging, and data source context functions in the graph-ts library.

Subgraph developers writing AssemblyScript mappings.

Audit mapping code for usage of deprecated imports and test against new runtime versions.

Runtime Behavior

Changes to deterministic execution guarantees, event ordering, or error handling in the mapping runtime.

Indexers, exchanges, and DeFi protocols consuming indexed data.

Verify indexing determinism across Graph Node versions to prevent state divergence.

Data Source Contexts

Modifications to the dataSource namespace, including context, address, and network fields.

Subgraph developers using dynamic data sources or multi-chain templates.

Review data source creation logic to ensure context is correctly propagated.

Cryptographic Functions

Addition or deprecation of hashing and signature verification host imports.

Subgraphs performing on-chain validation or identity verification.

Test all cryptographic assertions against the new API to confirm compatibility.

Logging and Debugging

Changes to log namespace severity levels, output format, or availability.

Indexer operators and developers debugging subgraph failures.

Adjust log aggregation and monitoring to parse new log formats.

Ethereum JSON-RPC Integration

Alterations to how mappings call eth_call or access block and transaction properties.

Subgraphs relying on contract state lookups within mappings.

Validate that all eth_call invocations return expected results under the new runtime.

BigInt and Type System

Updates to BigInt, BigDecimal, or Bytes type handling and arithmetic operations.

All subgraph developers performing numeric computation.

Run unit tests on all mapping logic involving token amounts, prices, or precision-sensitive math.

ABI Decoding

Changes to ethereum.decode or tuple/event decoding behavior.

Subgraphs parsing complex event logs or calldata.

Verify event and function decoding against updated ABI specifications.

technical-context
RUNTIME CONTRACT & HOST IMPORTS

Technical Mechanism

How the AssemblyScript mapping runtime connects subgraph logic to The Graph's host environment via the graph-ts library.

The AssemblyScript Mapping API defines the deterministic execution environment for subgraph transformation logic within The Graph. When a subgraph developer writes mapping.ts files, they are not writing code that runs directly on a bare-metal machine or a standard Node.js runtime. Instead, the code compiles to WebAssembly and executes inside a sandboxed runtime provided by Graph Node. This runtime exposes a set of host imports—functions imported from the host environment—that provide the only bridge between the deterministic mapping logic and external data sources like the Ethereum Virtual Machine, IPFS, or cryptographic primitives. The graph-ts library (@graphprotocol/graph-ts) acts as the typed AssemblyScript interface to these host imports, defining classes like ethereum, crypto, ipfs, and dataSource.

The core mechanism relies on a strict separation of concerns: the mapping code is purely functional and deterministic, while the host imports handle all side effects and data retrieval. For example, when a mapping calls crypto.keccak256(), it invokes a host import that executes the hashing operation outside the WebAssembly sandbox. Similarly, ethereum.call() performs a static call to an Ethereum node managed by the indexer. This architecture ensures that given the same input events and the same block state, every indexer produces identical output, which is the foundation of Proof of Indexing (POI). The API also provides context objects like dataSource.context() and dataSource.address() that allow the same mapping logic to be reused across multiple contract instances, a critical feature for factory-deployed contracts.

Operationally, changes to this API—such as adding new host imports for cryptographic functions, modifying the behavior of ethereum.decode(), or introducing new data source kinds—require coordinated upgrades across the graph-ts library, Graph Node implementations, and all downstream subgraphs. A breaking change in the mapping API can cause subgraphs to fail synchronization, produce non-deterministic results, or become incompatible with newer Graph Node versions. Teams operating subgraphs should monitor graph-ts releases and Graph Node changelogs for API deprecations. Chainscore Labs can audit mapping code for compatibility with upcoming API changes, identify reliance on deprecated host imports, and verify that subgraph logic remains deterministic across indexer implementations.

ASSEMBLYSCRIPT MAPPING API CHANGES

Affected Actors

Subgraph Developers

Mapping API changes directly impact the core logic of every subgraph. Developers must audit mapping.ts files for deprecated host imports, altered cryptographic function signatures, or new data source context requirements introduced in updated graph-ts versions.

Action Steps:

  • Pin graph-ts versions in package.json and test against release candidates.
  • Review changelogs for breaking changes to crypto.keccak256, dataSource.context, or log functions.
  • Update manifest apiVersion if required by the new specification.
  • Run deterministic indexing tests to verify identical output across Graph Node versions.

Chainscore can audit mapping codebases for compatibility gaps and identify non-deterministic patterns introduced by API migrations.

implementation-impact
MAPPING API CHANGES

Implementation Impact

Changes to the AssemblyScript Mapping API directly affect the transformation logic of every subgraph. Developers must assess host import deprecations, new cryptographic requirements, and data source context modifications to prevent indexing failures.

02

Cryptographic Host Import Changes

The mapping API exposes cryptographic primitives via host imports. Changes to available hash functions, signature verification algorithms, or elliptic curve operations directly affect subgraphs that perform on-chain data validation or identity proofs. A removed or altered crypto import can silently corrupt derived data. Teams should verify their mapping's cryptographic assumptions against the latest API specification and implement fallback patterns where necessary.

03

Data Source Context Modifications

The dataSource context object provides runtime information about the current indexing source. Changes to its structure, such as new fields for multi-chain support or modified address resolution, can break mappings that depend on context properties. Indexers and developers must ensure their mapping logic handles new context shapes gracefully to avoid crashes during synchronization.

04

Logging and Debugging Interface

API-level changes to the log module affect how subgraphs emit diagnostic information. New log levels, structured logging requirements, or changes to output formatting can impact indexer monitoring and developer debugging workflows. Operational teams should update their log aggregation pipelines to parse any new formats and ensure critical errors remain visible during indexing.

05

Deterministic Execution Guarantees

The AssemblyScript Mapping API must enforce strict determinism to ensure all indexers produce identical databases. Any new API feature that introduces non-deterministic behavior—such as timestamps, random number generation, or external API calls—creates a proof of indexing divergence risk. Chainscore can audit your mapping code for non-deterministic patterns and verify compliance with the latest determinism rules.

06

Subgraph Upgrade Sequencing

When the mapping API introduces breaking changes, subgraph developers must coordinate a version upgrade that maintains backward compatibility for existing API consumers. A poorly sequenced upgrade can disrupt dApp frontends, analytics pipelines, and downstream services. Chainscore can plan your subgraph version transition, including deprecation windows and consumer communication strategies.

ASSEMBLYSCRIPT MAPPING API

Compatibility and Risk Matrix

Operational impact and required actions for teams building, maintaining, or consuming subgraphs when the AssemblyScript mapping runtime or graph-ts library changes.

AreaWhat changesWho is affectedAction

Host Import APIs

Addition, deprecation, or signature change to host functions (e.g., crypto, dataSource, log)

Subgraph developers, indexer operators

Audit mapping code for deprecated imports; test against new Graph Node version before release

graph-ts Library

New types, utility functions, or breaking changes to existing class methods

All subgraph developers

Pin graph-ts version in package.json; run full test suite against updated library; review changelog for removed methods

Data Source Context

Changes to dataSource.context(), address, or network fields

Subgraph developers using dynamic data sources

Verify context access patterns; check for assumptions about field availability after data source creation

Cryptographic Primitives

New or modified crypto host imports (keccak256, sha256, ripemd160)

Subgraph developers implementing hashing logic

Validate hash outputs against known test vectors; confirm availability of new primitives before deploying

Logging Interface

Changes to log level behavior, output format, or log filtering

Indexer operators, subgraph developers debugging mappings

Review log output format for monitoring tool compatibility; adjust log level usage to avoid excessive indexer overhead

Ethereum Value Types

Changes to BigInt, BigDecimal, Bytes, Address, or ByteArray handling

All subgraph developers

Check for implicit conversion changes; test edge cases with large numbers and zero-value handling

Entity and Store API

Modifications to store.set, store.remove, or entity instantiation patterns

Subgraph developers, dApp frontend teams

Verify entity creation and update logic; test GraphQL query responses for schema consistency after migration

JSON and Data Parsing

Changes to JSON parsing host imports, try_fromBytes, or data extraction helpers

Subgraph developers processing complex event data

Test parsing of malformed or edge-case event data; confirm error handling behavior aligns with expected failure modes

ASSEMBLYSCRIPT MAPPING API UPGRADE READINESS

Developer Migration Checklist

A structured checklist for subgraph development teams preparing to migrate mapping logic in response to changes in the AssemblyScript Mapping API or `graph-ts` library. Each item identifies a critical verification step, explains why it matters for deterministic indexing and query integrity, and specifies the signal or artifact that confirms readiness.

Review every graph-ts host import (e.g., crypto, ethereum, store, log, dataSource) used in your mapping handlers. API upgrades may deprecate, rename, or alter the behavior of these imports.

Why it matters: Host imports are the bridge between AssemblyScript mapping logic and the indexer's runtime. A changed or removed import will cause a deterministic indexing failure, corrupting the subgraph's database state across all indexers.

Readiness signal: A complete inventory of all host imports used in your subgraph, with each import verified against the latest graph-ts changelog and the canonical AssemblyScript Mapping API specification. No import is flagged as deprecated or experimental without a documented migration path.

Chains We Build On

Looking to build on a specific blockchain?

We build smart contracts, DeFi applications, wallets, tokenization platforms, and blockchain infrastructure across the major ecosystems teams choose today. That includes Ethereum, Arbitrum, Optimism, Polygon, Avalanche, Solana, Sui, Aptos, Hedera, Stellar, and NEAR, with support for additional EVM and non-EVM networks based on your product requirements.

EVM ecosystems

  • Ethereum logo
    Ethereum
  • Arbitrum logo
    Arbitrum
  • Optimism logo
    Optimism
  • Polygon logo
    Polygon
  • Avalanche logo
    Avalanche
  • Cronos logo
    Cronos

Non-EVM ecosystems

  • Solana logo
    Solana
  • Sui logo
    Sui
  • Aptos logo
    Aptos
  • Hedera logo
    Hedera
  • Stellar logo
    Stellar
  • NEAR logo
    NEAR

Additional ecosystems

  • Polkadot logo
    Polkadot
  • Cosmos logo
    Cosmos
  • TON logo
    TON
  • Cardano logo
    Cardano
  • Algorand logo
    Algorand
  • Tempo logo
    Tempo

Also available for Base, appchains, custom EVM networks, and cross-chain product architecture.

ASSEMBLYSCRIPT MAPPING API FAQ

Frequently Asked Questions

Common questions from subgraph developers about the AssemblyScript mapping runtime, host imports, and graph-ts library compatibility.

The mapping runtime provides a deterministic set of host imports exposed via the graph-ts library. These include:

  • Cryptographic functions: crypto.keccak256(), crypto.sha256(), and crypto.ripemd160() for hashing operations.
  • Data source context: dataSource.address(), dataSource.network(), and dataSource.context() to access the triggering data source's configuration.
  • Logging: log.debug(), log.info(), log.warning(), log.error(), and log.critical() for structured log output during indexing.
  • Ethereum utilities: ethereum.encode(), ethereum.decode(), and ethereum.crypto for ABI encoding/decoding and elliptic curve operations.

Why this matters: Using unsupported host imports causes deterministic indexing failures. Indexers must produce identical database outputs, so any non-deterministic or unavailable import will cause subgraph synchronization errors.

Compatibility signal: Review the graph-ts version specified in your package.json against the Graph Node release notes. New host imports are added in minor graph-ts releases and require corresponding Graph Node versions.

Trusted by Industry Leaders

Delivering blockchain solutions for 5+ years.

We have partnered with 50+ leading DeFi protocols, NFT ecosystems, and fintech innovators to build secure, scalable, and capital-efficient blockchain products.

Selected Partners & Clients

ChainVote logo
Reax logo
Sokail logo
Swapsicle logo
SyntheX logo
Tekika logo
Telos logo
Zexe logo
ChainVote logo
Reax logo
Sokail logo
Swapsicle logo
SyntheX logo
Tekika logo
Telos logo
Zexe logo
ChainVote logo
Reax logo
Sokail logo
Swapsicle logo
SyntheX logo
Tekika logo
Telos logo
Zexe logo
ChainVote logo
Reax logo
Sokail logo
Swapsicle logo
SyntheX logo
Tekika logo
Telos logo
Zexe logo
“I've been working with Chainscore Labs for last 3+ years, they've consistently delivered with strong ownership across multiple projects. The team is reliable and detail-oriented.”
L
Lee Erswell
CEO, Telos Foundation
how to get started

How to get started?

If you're looking for blockchain integration, ChainScore Labs has 5+ years of experience helping teams build and integrate exchanges, wallets, smart contracts, tokenization solutions, and protocol-connected products, we can help you choose the right path, integrate securely, and get to production faster. Our team consists of experienced blockchain developers and architects who can help you with your blockchain integration needs.

01

Exploration & Strategy

Define your product goals and choose the right blockchain architecture for your use case.

02

Architecture & Design

Design the smart contracts, tokenomics, and security parameters of your system.

03

Development & Integration

Build and integrate with wallets, oracles, and front-end dApps for a seamless experience.

04

Security & Launch

Comprehensive audits followed by a risk-managed mainnet deployment to protect your users.

Start a build

Need a blockchain engineering team?

Send the project context and we will respond with next steps, scope questions, and a practical path to delivery.