Skip to main content

Compose Blocks into a Graph

A Block can reference earlier Blocks through parentHashes. Each parent reference creates a direct edge in the ALX derivation graph, connecting a Block to the parent Blocks declared by the application.

Parent Relationship Purpose

contentHash identifies canonicalized content. blockHash identifies that content together with the normalized parent set. parentHashes record the direct parent Blocks declared during Block creation, preserving the lineage represented by the application.

Create a Child Block

import { createBlock } from '@alx-protocol/sdk';

const source = createBlock({ step: 'source' }, []);

const result = createBlock(
{ step: 'result' },
[source.blockHash],
);

console.log(result.parentHashes);

The new Block stores the source Block's hash in parentHashes. If a Block is created from multiple inputs, include each input's blockHash in the array.

When to Use a Graph

Use parent relationships when your application needs to:

  • Trace how a Block was produced.
  • Find the dependencies of a Block.
  • Verify that every referenced parent exists.
  • Detect cycles or missing links in lineage.