Free 30-min Web3 Consultation
Book Consultation
Smart Contract Security Audits
View Audit Services
Custom DeFi Protocol Development
Explore DeFi
Full-Stack Web3 dApp Development
View App Services
Free 30-min Web3 Consultation
Book Consultation
Smart Contract Security Audits
View Audit Services
Custom DeFi Protocol Development
Explore DeFi
Full-Stack Web3 dApp Development
View App Services
Free 30-min Web3 Consultation
Book Consultation
Smart Contract Security Audits
View Audit Services
Custom DeFi Protocol Development
Explore DeFi
Full-Stack Web3 dApp Development
View App Services
Free 30-min Web3 Consultation
Book Consultation
Smart Contract Security Audits
View Audit Services
Custom DeFi Protocol Development
Explore DeFi
Full-Stack Web3 dApp Development
View App Services
LABS
Guides

How to Map On-Chain and Off-Chain Data Flows for Compliance

A technical tutorial for developers to create a data flow map (DFM) for blockchain applications, tracing personal data from frontends through smart contracts, oracles, and storage layers.
Chainscore © 2026
introduction
COMPLIANCE GUIDE

Introduction to Data Flow Mapping for Blockchain

A practical guide to visualizing and documenting the movement of data across on-chain and off-chain systems to meet regulatory requirements.

Data flow mapping is the systematic process of identifying, documenting, and visualizing how information moves through a blockchain application. For compliance with regulations like GDPR, FATF Travel Rule, or MiCA, you must trace the journey of personal and financial data across both on-chain (public ledger) and off-chain (private databases, APIs) components. A clear map reveals where data originates, how it's processed, where it's stored, and who can access it. This is foundational for conducting risk assessments, implementing controls, and demonstrating accountability to auditors.

Start by cataloging all data types your dApp handles. This includes personally identifiable information (PII) like wallet addresses linked to KYC data, transaction amounts, and smart contract state variables. For each data type, identify its data sources (user input forms, oracle feeds, partner APIs) and data sinks (blockchain storage, internal databases, third-party analytics). A transaction's journey might begin off-chain with a user submitting KYC details via an API, which are then hashed and referenced in an on-chain smart contract governing a token sale.

To create the map, diagram the architecture. Use tools like diagrams.net or Miro to create a visual with clear swimlanes for on-chain and off-chain environments. For each component (e.g., frontend, backend service, smart contract, oracle), document: the data processed, its format (raw, encrypted, hashed), the legal basis for processing, and any cross-border transfers. For example, an NFT marketplace's flow would show user profile data (off-chain DB), asset metadata (IPFS), and immutable ownership records (on-chain). Code audits and events from providers like Chainscore Labs can help verify the actual on-chain data trails.

The core challenge is managing the dichotomy between immutable on-chain data and mutable off-chain data. A user's Ethereum address is permanently on-chain, but their associated email address in your customer database is off-chain and subject to deletion requests. Your map must show the cryptographic link (like a hash pointer) between these realms and the procedures for honoring off-chain data rights without corrupting on-chain state. This requires implementing reference architectures that separate data by sensitivity, using zero-knowledge proofs or state channels where possible.

Finally, translate your map into actionable compliance artifacts. Use it to generate a Record of Processing Activities (ROPA) for GDPR, identify Travel Rule message touchpoints for VASPs, or pinpoint locations requiring enhanced data encryption. Regularly update the map when you deploy new contracts or integrate new oracles. Automated monitoring tools that track real-time data flows against your documented baseline are essential for maintaining ongoing compliance in a dynamic Web3 environment.

prerequisites
PREREQUISITES AND SCOPE DEFINITION

How to Map On-Chain and Off-Chain Data Flows for Compliance

A systematic approach to defining the data sources and analytical scope required for effective blockchain compliance monitoring.

Mapping data flows for compliance begins with a clear scope definition. You must identify which blockchain networks, smart contracts, and off-chain services your project interacts with. For a DeFi protocol, this includes the underlying L1/L2 (e.g., Ethereum, Arbitrum), its deployed contract addresses, integrated oracles like Chainlink, and any associated front-end or API services. Defining this perimeter is critical; an incomplete scope leads to blind spots in monitoring. Start by documenting all entry and exit points for value and data.

The next prerequisite is establishing your data acquisition strategy. On-chain data is accessed via node providers (Alchemy, Infura) or indexed services (The Graph, Dune Analytics). For comprehensive flows, you'll need both raw transaction data and decoded log events from smart contracts. Off-chain data, such as KYC information from a backend database or exchange transaction records, must be linked via a common identifier, often a wallet address. The technical setup involves configuring RPC endpoints, API keys, and ensuring reliable data ingestion pipelines.

You must also define the compliance rules and risk indicators you intend to monitor. These translate regulatory requirements into on-chain logic. Common rules include: transaction volume thresholds (e.g., $10,000 for Travel Rule), screening addresses against sanction lists (OFAC), identifying mixing service interactions (Tornado Cash), and monitoring for patterns of layering. Each rule dictates the specific data points you need to extract and correlate, shaping your entire data mapping exercise. Without predefined rules, data collection lacks direction.

Finally, consider the temporal and attribution scope. Determine the look-back period for historical analysis and the required latency for real-time alerts. Attribution involves linking blockchain addresses to real-world entities—a complex challenge. Techniques include analyzing deposit addresses from known KYC'd exchanges, investigating ENS domains, and clustering addresses heuristically. Your mapping must account for these identity-resolution processes, as compliance ultimately concerns entities, not just anonymous public keys.

key-concepts-text
DATA INTEGRATION

Key Concepts: On-Chain vs. Off-Chain Data

A practical guide to mapping data flows between blockchains and external systems for effective compliance monitoring and reporting.

For compliance teams, understanding the distinction between on-chain and off-chain data is foundational. On-chain data is information permanently recorded and verified on a blockchain's distributed ledger, such as transaction amounts, wallet addresses, smart contract code, and token transfers. This data is immutable, transparent, and publicly verifiable. In contrast, off-chain data exists outside the blockchain network. This includes Know Your Customer (KYC) documentation, real-world asset titles, traditional bank records, and even price feeds from oracles. The core compliance challenge is creating a reliable, auditable link between these two distinct data realms.

Mapping these data flows begins with identifying the points of intersection. Key touchpoints include deposit/withdrawal gateways (CEX on/off-ramps), oracle networks (like Chainlink or Pyth) that push off-chain data on-chain, and identity attestation protocols (such as Veramo or Spruce ID). For example, a user's verified identity (off-chain KYC) might be linked to their wallet address via a verifiable credential, creating an on-chain attestation. Mapping this flow requires tracking the credential's issuance, its on-chain registration (e.g., as an NFT or in a registry contract), and its subsequent use in compliant DeFi transactions.

Technical implementation involves querying both data layers. For on-chain data, use blockchain indexers (The Graph, Covalent) or direct node RPC calls to extract transaction logs and event emissions from relevant smart contracts. For off-chain data, integrate with APIs from compliance providers (Chainalysis, Elliptic), traditional databases, or secure storage solutions (IPFS, Arweave for decentralized off-chain data). A robust mapping system logs the correlation ID linking an on-chain transaction hash to its corresponding off-chain case file or customer record, creating an immutable audit trail.

A critical use case is monitoring cross-chain activity for anti-money laundering (AML). A user may bridge funds from Ethereum to Arbitrum (on-chain event), but the originating fiat deposit and KYC check occurred off-chain at an exchange. Mapping this flow requires connecting the exchange's internal withdrawal transaction ID (off-chain) to the Ethereum bridge contract interaction (on-chain), and then to the final receipt on Arbitrum. Tools like Chainscore's cross-chain APIs are built specifically to trace these complex, multi-chain journeys by aggregating and normalizing data from numerous networks.

Ultimately, effective mapping enables automated compliance reporting. By programmatically correlating data streams, systems can generate Suspicious Activity Reports (SARs), proof-of-reserves attestations, or tax documents. The goal is not just to collect data, but to create a verifiable data pipeline where the provenance and linkage between any on-chain action and its off-chain context can be demonstrated to regulators. This requires careful architecture, focusing on data integrity, secure storage for sensitive off-chain information, and maintaining the cryptographic proofs that bind the two worlds together.

ARCHITECTURE

Data Storage Layer Comparison for Mapping

Comparison of storage solutions for persisting mapped data flows for compliance reporting and analysis.

FeatureOn-Chain Storage (e.g., IPFS, Arweave)Centralized Database (e.g., PostgreSQL)Decentralized Database (e.g., Ceramic, Tableland)

Data Immutability & Audit Trail

Write Cost per 1MB

$2-10 (gas fees)

$0.05-0.20

$0.50-2.00

Read Latency

2-15 seconds

< 100 ms

200-500 ms

Censorship Resistance

Schema Flexibility

Native Data Composability

Compliance Data Retention Period

Permanent

Defined by policy

Permanent

Regulatory Data Portability

High (public verifiable)

Medium (requires export)

High (standardized APIs)

step-1-frontend-tracing
DATA COLLECTION

Step 1: Trace Data from User Interaction (Frontend)

The first step in mapping data flows for compliance is capturing the initial user interaction. This involves instrumenting your dApp's frontend to log key events before any transaction is signed.

User interaction tracing begins at the wallet connection. When a user clicks "Connect Wallet," your frontend should capture the wallet address, the wallet provider (e.g., MetaMask, WalletConnect), and a timestamp. This establishes the user's on-chain identity for the session. For compliance, you must also log the user's IP address and geolocation data at this point, which requires a backend service call. This creates a foundational link between an anonymous wallet address and verifiable off-chain interaction data.

Next, trace every significant UI action that precedes a blockchain transaction. This includes form submissions, button clicks to initiate swaps or transfers, and parameter selections like token amounts and slippage tolerance. For example, when a user initiates a swap on a DEX interface, log the input token, output token, amount, selected route, and the estimated gas fee displayed. These details are crucial for reconstructing user intent and proving that the interface presented accurate information prior to the on-chain event.

Implement this tracing using a structured logging service like Segment, Amplitude, or a custom backend endpoint. Avoid logging sensitive data like private keys or mnemonics. The goal is to create an immutable audit trail of the user's journey. Use a consistent session ID to correlate all frontend events with the subsequent on-chain transaction hash. This correlation is the critical bridge between off-chain intent and on-chain execution for regulatory reporting and internal monitoring.

step-2-smart-contract-analysis
COMPLIANCE AUDIT FRAMEWORK

Step 2: Analyze Smart Contract Data Handling

This step focuses on identifying and categorizing all data interactions within a smart contract to assess compliance risks.

Smart contract compliance hinges on understanding data provenance. You must map every data flow, distinguishing between on-chain data (immutable, public ledger entries) and off-chain data (external inputs via oracles or user signatures). On-chain data includes token balances, transaction history, and governance votes stored in contract state. Off-chain data encompasses price feeds from Chainlink, random numbers from API3, or KYC verification results signed by a trusted provider. Misclassifying these flows is a critical audit failure.

To map these flows, systematically trace all function calls and state variables. Identify data sources: Is the value from msg.sender, a storage variable, or an oracle like ChainlinkDataFeed.latestAnswer()? Then track data sinks: Where is this value written? Common sinks are state updates, event emissions, or cross-contract calls. For example, a lending protocol's liquidate() function uses an off-chain price (source) to calculate an on-chain health factor (calculation) and then updates the loan's collateral state (sink). Tools like Slither or manual inspection of function logic are essential here.

A key risk area is the validation and sanitization of off-chain inputs. An oracle price must be checked for freshness (staleness), validity (circuit breaker), and manipulation (multiple sources). Consider this minimal check for a Chainlink price feed:

solidity
(
    uint80 roundId,
    int256 answer,
    uint256 startedAt,
    uint256 updatedAt,
    uint80 answeredInRound
) = priceFeed.latestRoundData();
require(answeredInRound >= roundId, "Stale price");
require(answer > 0, "Invalid price");
require(block.timestamp - updatedAt <= priceFeedMaxDelay, "Price too old");

Missing these checks can lead to incorrect liquidation or faulty settlement.

Finally, document the data lifecycle for compliance reporting. For regulated assets, you must prove the audit trail: which entity provided off-chain data, when an on-chain state changed, and who authorized it. This often requires analyzing event logs. A transfer of a security token should emit a rich event containing not just from and to addresses, but also a regulatoryReferenceId. Mapping these flows creates the evidence needed to demonstrate adherence to rules like the Travel Rule or specific jurisdictional requirements.

step-3-off-chain-systems
DATA INTEGRATION

Step 3: Map Off-Chain Systems and Oracles

This step details how to identify and document the critical off-chain data sources that feed into your smart contracts, a foundational requirement for compliance reporting and risk assessment.

A compliance-ready system requires a complete data lineage. This means mapping every external data point your protocol consumes, from its origin to its on-chain storage. Start by auditing your smart contracts for all oracle and off-chain dependencies. Common sources include price feeds from Chainlink or Pyth, KYC/AML status from providers like Chainalysis or Elliptic, real-world asset data, and randomness from services like Chainlink VRF. For each dependency, document the oracle address, the data type (e.g., int256 price, bool isSanctioned), update frequency, and the on-chain function that receives it.

The security and regulatory standing of your chosen oracles are paramount. Assess each provider's historical reliability, decentralization (number of nodes/data sources), and governance model. For compliance, you must verify if the oracle provider itself adheres to relevant regulations, especially for handling sensitive financial or identity data. A breach or regulatory action against your oracle is a direct risk to your protocol. Document this due diligence, noting the oracle's attestations or audits, such as a SOC 2 Type II report for data handlers.

Create a data flow diagram for each major process. For example, a lending protocol's liquidation process might flow: 1) Chainlink ETH/USD price feed updates on-chain, 2) A keeper bot monitors this and a user's health factor, 3) Upon breach, the keeper calls liquidate() with the oracle price as an input. Mapping this exposes critical junctures: the oracle's update latency could affect liquidation fairness, and the keeper's off-chain logic must be accounted for in your system's overall compliance model.

For developers, integrating an oracle typically involves an interface contract. Below is a simplified example of mapping a price feed call, noting the key data points for your documentation.

solidity
// Example: Documenting a Chainlink Price Feed Integration
import "@chainlink/contracts/src/v0.8/interfaces/AggregatorV3Interface.sol";

contract MyProtocol {
    // Oracle Mapping Data Point:
    // - Provider: Chainlink
    // - Address: 0x5f4eC3Df9cbd43714FE2740f5E3616155c5b8419 (Mainnet ETH/USD)
    // - Data Type: int256 (price with 8 decimals)
    // - Update Frequency: ~1 block (Heartbeat of ~1 second)
    AggregatorV3Interface internal priceFeed;

    function getLatestPrice() public view returns (int) {
        (,int price,,,) = priceFeed.latestRoundData();
        return price; // e.g., 350000000000 for $3500
    }
}

Finally, establish monitoring for these data flows. Use off-chain services like Chainlink Automation or custom indexers to log every oracle update and its consumption. Track metrics like time-stamp freshness, deviation thresholds, and failed updates. This monitoring data is not only crucial for operational alerts but forms the evidential backbone for compliance audits, proving that your protocol operated on accurate, timely data throughout its history. Tools like The Graph for querying event logs or Dune Analytics for dashboarding can be instrumental here.

DATA FLOW CATEGORIES

Compliance Risk Assessment Matrix

Risk levels and control requirements for different types of on-chain and off-chain data interactions in a compliance workflow.

Data Flow TypeRisk LevelPrimary Compliance ConcernRequired ControlExample

Direct On-Chain Transactions

HIGH

Sanctions screening, AML

Real-time transaction monitoring (e.g., Chainalysis, TRM)

User sends USDC to an exchange

Off-Chain KYC Data to On-Chain Identity

HIGH

Data privacy (GDPR, CCPA), identity linkage

Zero-knowledge proofs, encrypted attestations

Linking verified identity to a wallet via Verite credential

Cross-Chain Bridge Transfers

MEDIUM

Source of funds obfuscation, jurisdictional arbitrage

Bridge-level AML checks, path analysis

Moving ETH from Ethereum to Avalanche via a bridge

Oracle Price Feeds for Compliance Logic

MEDIUM

Data manipulation, oracle failure

Multi-source oracle validation, circuit breakers

Using Chainlink price to trigger a loan liquidation

Off-Chain Transaction Reporting (e.g., Form 1099)

LOW

Reporting accuracy, data integrity

Secure API integration, audit trails

Exporting annual transaction history to a tax provider

Public On-Chain Data for Risk Scoring

LOW

False positives, model bias

Transparent scoring methodology, manual review override

Using wallet history from Etherscan for a risk score

step-4-documentation-output
COMPLIANCE WORKFLOW

Step 4: Create the Data Flow Map and Documentation

A data flow map is a visual and textual artifact that traces the lifecycle of sensitive information, such as user KYC data or transaction details, across your application's on-chain and off-chain components. This step is critical for regulatory audits and internal security reviews.

Begin by cataloging all data inputs. For a DeFi protocol, this includes on-chain data like wallet addresses, transaction hashes, and token transfer amounts from sources like smart contract events. It also includes off-chain data such as user-submitted KYC documents, IP addresses from your frontend, and API keys for oracle services. Tools like The Graph for querying indexed blockchain data or your application's backend logs are essential for this inventory phase.

Next, document each data processing step and storage location. Create a diagram or table that answers: Where is the data generated? Which system components (e.g., user's browser, your API server, a cloud database, a smart contract) process it? Where is it stored, and for how long? For example, a user's email might flow from a frontend form to a users table in your PostgreSQL database, while their wallet address is also emitted in an event by a Solidity Registration contract and stored permanently on-chain.

A crucial part of the map is identifying data handoff points between systems, as these are common failure points for compliance. Document the protocols used: Is data sent via a secure HTTPS API call, written to a public blockchain, or synchronized via a decentralized storage network like IPFS or Arweave? For each handoff, note the data format (JSON, calldata, encrypted file) and any validation or transformation applied, such as hashing PII before on-chain storage.

Your documentation must explicitly address data subject rights under regulations like GDPR or CCPA. Map how you would execute a user data deletion request. Can you delete off-chain records from your database? For on-chain data, you must document that certain information, like transaction hashes, is immutable and explain the procedural steps your compliance team would follow, such as annotating associated off-chain records to disregard the linked address.

Finally, integrate this map into your development and operational lifecycle. The documentation should be a living document, version-controlled alongside your code. Update it for every new feature that touches user data. This map becomes the single source of truth for answering auditor questions, conducting privacy impact assessments, and ensuring your team understands the full scope of your data governance responsibilities.

DATA MAPPING

Frequently Asked Questions (FAQ)

Common questions about tracing and correlating data between blockchain ledgers and traditional systems for regulatory and operational compliance.

On-chain data is immutable, public, and stored directly on the blockchain ledger (e.g., transaction hashes, wallet addresses, token transfers on Ethereum). Off-chain data is mutable, private, and stored in traditional databases (e.g., user KYC documents, internal transaction memos, counterparty legal names).

The core compliance challenge is creating a cryptographic link between these two datasets. This is typically done by recording a hash of the off-chain data (like a PDF) in an on-chain transaction or a verifiable credential. Tools like Chainlink Functions or The Graph can be used to query and verify this linkage programmatically, creating an auditable trail that satisfies regulators requiring proof of origin and integrity for off-chain records.

conclusion
IMPLEMENTATION ROADMAP

Conclusion and Next Steps

This guide has outlined the technical process for mapping data flows to meet regulatory requirements. The next steps involve operationalizing this framework.

Successfully mapping on-chain and off-chain data flows is not a one-time audit but an ongoing operational process. The framework you've built—identifying data sources, establishing lineage, and implementing monitoring—must be integrated into your compliance and development lifecycle. For smart contract protocols, this means incorporating data mapping checks into your CI/CD pipeline using tools like Slither or Foundry for static analysis. For custodial services, it requires real-time alerting systems that trigger when a transaction pattern deviates from the mapped flow, such as a withdrawal to an unverified off-ramp.

The most critical next step is to test your data flow maps against real-world scenarios. Conduct controlled simulations of user actions—deposits, trades, withdrawals—and trace the data through your entire stack. Use this to validate your assumptions about where Personally Identifiable Information (PII) is stored and how transaction non-repudiation is achieved. For example, simulate a regulatory inquiry: given a user's wallet address, can you reliably produce all associated KYC records, transaction history, and IP logs from your off-chain databases within a mandated timeframe?

Finally, consider the tools and partnerships that can scale this effort. Leverage specialized blockchain analytics platforms like Chainalysis or TRM Labs to enrich on-chain data with risk scores and cluster labels. Utilize privacy-preserving compliance protocols such as Aztec or Tornado Cash Nova (in a regulated manner) to understand how zero-knowledge proofs affect data visibility. The goal is to move from manual mapping to an automated, policy-driven compliance engine that can adapt to new chains, new regulations like the EU's MiCA, and novel transaction types without a complete system overhaul.