Production engineering guide for blockchain compliance in Web3 and blockchain systems.
Blockchain compliance is the process of ensuring that blockchain-based systems meet regulatory, legal, and operational requirements across a network. It matters when transactions must be auditable, identities verified, and data immutably recorded under standards like KYC, AML, SOX, GDPR, or MiCA. Compliance is not a one-time setup—it is an ongoing, automated, and traceable part of blockchain operations.
To enforce compliance, systems must define policies that govern how data is structured, validated, and stored. Policies are expressed as rules over events, accounts, transactions, and metadata. A policy can specify that all transfers over 10,000 units must be reviewed by a compliance officer, or that every new wallet must include a verified identity document.
Policies are defined in a standard format: JSON documents stored in a versioned repository, typically managed via Git. Each policy is versioned, signed, and deployed to a configuration system.
{
"policyId": "aml-2024-q2",
"name": "Enhanced AML Screening",
"description": "All transactions above 5000 USD must trigger KYC and risk scoring.",
"version": "1.2",
"rules": [
{
"condition": "transaction.amount > 5000",
"action": "trigger-kyc-review",
"metadata": {
"reviewer": "compliance-team-1",
"priority": "high"
}
},
{
"condition": "account.riskScore > 70",
"action": "add-to-watchlist",
"metadata": {
"reason": "High-risk customer segment"
}
}
],
"validFrom": "2024-07-01T00:00:00Z",
"validTo": "2025-06-30T23:59:59Z",
"author": "[email protected]"
}
These policy files are deployed via GitOps. A commit to policies/main triggers a CI pipeline that validates each policy using a schema checker:
$ npx json-schema-validator --schema policies/schema.json --files policies/**/*.json
A failed validation returns a structured error:
{
"errors": [
{
"path": "policies/aml-2024-q2.json",
"error": "Missing required field: rules[0].condition",
"expected": "string",
"actual": "null"
},
{
"path": "policies/aml-2024-q2.json",
"error": "Invalid action: trigger-kyc-review, expected one of: [review, alert, log, notify]",
"expected": ["review", "alert", "log", "notify"],
"actual": "trigger-kyc-review"
}
]
}
Policies are then published to a central registry. The registry is a simple REST API with a /policies endpoint.
GET /policies?version=1.2&validAt=2024-07-15T12:00:00Z
Response:
{
"policies": [
{
"id": "aml-2024-q2",
"version": "1.2",
"validFrom": "2024-07-01T00:00:00Z",
"validTo": "2025-06-30T23:59:59Z",
"rules": [
{
"condition": "transaction.amount > 5000",
"action": "trigger-kyc-review",
"metadata": { "reviewer": "compliance-team-1", "priority": "high" }
}
]
}
]
}
When a new transaction arrives on the blockchain, the system must evaluate it against active compliance policies. This evaluation is triggered by a blockchain event, such as a Transfer or Deposit event emitted by a smart contract.
The event processor listens to the blockchain via a subscription mechanism, typically using a WebSocket or gRPC stream. Each event is enriched with metadata before policy evaluation.
{
"event": "Transfer",
"blockNumber": 123456,
"transactionHash": "0xabc123...",
"timestamp": "2024-07-15T12:00:00Z",
"data": {
"from": "0x1234567890abcdef1234567890abcdef12345678",
"to": "0x9876543210fedcba9876543210fedcba98765432",
"amount": 12500.50,
"currency": "USDC",
"metadata": {
"source": "onramp",
"originCountry": "US",
"paymentMethod": "ACH"
}
}
}
The compliance engine evaluates the event using the current set of active policies. It queries the policy registry and applies rules in order. A rule with a condition transaction.amount > 5000 uses a simple expression language.
The engine evaluates conditions using a common subset of JavaScript-like expressions:
transaction.amount > 5000account.riskScore >= 70transaction.metadata.originCountry === "US"event.data.metadata.source === "onramp" && event.timestamp < "2024-07-01"Conditions are evaluated in a sandboxed context, with access to:
event — the full event objectaccount — a lookup via event.data.from or event.data.toblock — the block at which the event occurredsystem — global system variables like now, networkId, chainIdEach rule may define one or more actions. Actions are invoked via HTTP, with a payload that includes the event and its context.
For example, trigger-kyc-review calls a service at /api/compliance/kyc-review:
POST /api/compliance/kyc-review
Content-Type: application/json
{
"eventId": "Transfer-123456",
"transactionHash": "0xabc123...",
"amount": 12500.50,
"from": "0x1234567890abcdef1234567890abcdef12345678",
"to": "0x9876543210fedcba9876543210fedcba98765432",
"reviewer": "compliance-team-1",
"priority": "high",
"timestamp": "2024-07-15T12:00:00Z"
}
The service responds with a 202 Accepted and a Location header pointing to the review task.
HTTP/1.1 202 Accepted
Location: /tasks/kyc-review/7a3f2c1b
Content-Type: application/json
{
"taskId": "7a3f2c1b",
"status": "pending",
"assignedTo": "compliance-team-1",
"createdAt": "2024-07-15T12:00:01Z"
}
Compliance actions are recorded in a dedicated audit log. Each action generates an audit entry with a unique identifier, timestamp, and context.
The audit log is a PostgreSQL table:
CREATE TABLE compliance_audit (
id UUID PRIMARY KEY,
event_id TEXT NOT NULL,
policy_id TEXT,
rule_index INTEGER,
action_type TEXT NOT NULL,
result JSONB,
metadata JSONB,
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
executed_at TIMESTAMPTZ,
status TEXT CHECK (status IN ('success', 'failed', 'pending', 'cancelled')),
error TEXT
);
CREATE INDEX idx_compliance_audit_event_id ON compliance_audit(event_id);
CREATE INDEX idx_compliance_audit_policy_id ON compliance_audit(policy_id);
CREATE INDEX idx_compliance_audit_created_at ON compliance_audit(created_at);
When a policy rule executes, it logs an entry:
INSERT INTO compliance_audit (
id,
event_id,
policy_id,
rule_index,
action_type,
result,
metadata,
status,
executed_at
) VALUES (
'a1b2c3d4-e5f6-7890-1234-567890abcdef',
'Transfer-123456',
'aml-2024-q2',
0,
'trigger-kyc-review',
'{"taskId": "7a3f2c1b", "status": "pending"}',
'{"reviewer": "compliance-team-1", "priority": "high"}',
'success',
'2024-07-15T12:00:02Z'
);
The audit log is queried by the compliance dashboard. A common query retrieves all actions triggered in the last 30 days:
SELECT
id,
event_id,
action_type,
result->>'taskId' AS task_id,
status,
created_at,
executed_at
FROM compliance_audit
WHERE created_at >= NOW() - INTERVAL '30 days'
AND action_type = 'trigger-kyc-review'
ORDER BY created_at DESC
LIMIT 100;
A common failure occurs when a policy rule evaluates to false but the action fails. The compliance engine tracks these failures and marks the audit entry with an error.
For instance, if trigger-kyc-review returns a 500 Internal Server Error, the audit log records:
{
"id": "a1b2c3d4-e5f6-7890-1234-567890abcdef",
"event_id": "Transfer-123456",
"policy_id": "aml-2024-q2",
"rule_index": 0,
"action_type": "trigger-kyc-review",
"result": null,
"metadata": { "reviewer": "compliance-team-1", "priority": "high" },
"status": "failed",
"error": "HTTP 500: Internal Server Error: Failed to create task",
"created_at": "2024-07-15T12:00:01Z",
"executed_at": "2024-07-15T12:00:03Z"
}
The system can then trigger alerts via a message queue, such as Kafka or NATS. A consumer listens for failed audit entries and sends notifications.
{
"type": "compliance.failed-action",
"eventId": "Transfer-123456",
"action": "trigger-kyc-review",
"error": "HTTP 500: Internal Server Error: Failed to create task",
"policyId": "aml-2024-q2",
"timestamp": "2024-07-15T12:00:03Z"
}
The system also supports policy rollbacks. When a new policy version is deployed, the old version is kept in a policies/old branch. If a rollout fails, the system can revert to the previous version by updating the active pointer.
A rollback is triggered by a simple HTTP call:
PATCH /policies/active
{
"version": "1.1",
"reason": "Regression in KYC workflow",
"rollbackTo": "1.0"
}
The system validates the new active policy set and updates the registry. A GET /policies/active returns:
{
"currentVersion": "1.1",
"lastUpdated": "2024-07-15T12:05:00Z",
"fallbackTo": "1.0",
"activePolicies": [
{
"id": "aml-2024-q2",
"version": "1.1",
"validFrom": "2024-07-01T00:00:00Z"
}
]
}
Complex compliance requirements are implemented as workflows, composed of multiple policy rules and actions. Workflows are defined as sequences of steps, each step being a rule execution or an external service call.
A workflow is described in a YAML file:
name: "KYC Onboarding Flow"
version: "1.0"
steps:
- id: verify-identity
type: policy
condition: "account.identityVerified === false"
action: "trigger-kyc-review"
metadata:
reviewer: "compliance-team-1"
priority: "high"
next: "check-risk-score"
- id: check-risk-score
type: policy
condition: "account.riskScore > 70"
action: "add-to-watchlist"
metadata:
reason: "High-risk customer segment"
next: "approve-account"
- id: approve-account
type: service
endpoint: "https://accounts.example.com/api/approve"
method: POST
request: |
{
"accountId": "{{ event.data.from }}",
"approvedBy": "compliance-system",
"timestamp": "{{ now }}"
}
response: |
{
"status": "success",
"accountId": "{{ response.accountId }}",
"approvalId": "{{ response.id }}"
}
next: "notify-user"
- id: notify-user
type: service
endpoint: "https://notifications.example.com/api/send"
method: POST
request: |
{
"to": "{{ event.data.from }}",
"subject": "Your account is approved",
"body": "Welcome to the platform. Your KYC has been verified."
}
The workflow engine executes these steps in order. Each step can be paused, retried, or triggered by an event. The engine maintains a state machine per workflow instance.
A workflow instance is stored in a database with a workflow_instances table:
CREATE TABLE workflow_instances (
id UUID PRIMARY KEY,
workflow_name TEXT,
version TEXT,
status TEXT CHECK (status IN ('running', 'completed', 'failed', 'paused')),
current_step TEXT,
context JSONB,
started_at TIMESTAMPTZ,
completed_at TIMESTAMPTZ
);
When a new Transfer event arrives, the engine creates a new instance and begins execution.
Compliance is not just about rules and actions—it is about traceability. Every decision must be recorded and linked to its origin.
The system ensures traceability by embedding metadata in every event and audit entry. Each entry includes the policy version, the effective date, and the source of truth.
For example, a compliance audit entry includes:
policyId — the ID of the active policypolicyVersion — the version used at execution timeeffectiveAt — the timestamp when the policy was activesource — the Git commit SHA that deployed the policyThis allows auditors to reconstruct the compliance state at any point in time.
The system supports time-travel queries. Given a timestamp, the system returns all active policies and their rules as they were at that moment.
GET /policies/active?at=2024-07-10T00:00:00Z
Response:
{
"currentVersion": "1.1",
"lastUpdated": "2024-07-15T12:05:00Z",
"activePolicies": [
{
"id": "aml-2024-q2",
"version": "1.1",
"validFrom": "2024-07-01T00:00:00Z",
"validTo": "2025-06-30T23:59:59Z"
},
{
"id": "kyc-onboarding",
"version": "1.0",
"validFrom": "2024-07-01T00:00:00Z",
"validTo": "2024-12-31T23:59:59Z"
}
],
"source": "commit: a1b2c3d4e5f678901234567890abcdef12345678"
}
This enables forensic analysis: an auditor can ask, “What compliance rules were in effect when transaction #123456 was processed?” and receive a complete answer with policy versions, rule conditions, and action details.
Traceability is further enhanced by linking audit entries to blockchain transactions via event_id. A query can resolve all compliance actions for a given transaction, showing every rule that fired and every service called.
Blockchain compliance is thus a system of rules, events, actions, logs, and workflows—each step clearly defined, each failure explicitly reported, and every decision fully traceable. It is not a set of checks, but a continuous, automated, and auditable process.
This page was rewritten on 18 October 2026. It replaced a templated version that was not specific to its own title. How these pages are written and checked. If anything here is wrong, tell us at [email protected] and we will correct it.
We use cookies for analytics (Google Analytics) and advertising (Google AdSense) to improve your experience and support free content. Privacy Policy