Quick Start
Create and validate an ALX Block using the JavaScript SDK. Block creation and validation run locally without an API key or network connection.
Install
Requires Node.js 20, 21, or 22.
npm install @alx-protocol/sdk
Create and Validate a Block
Create quick-start.mjs and run the script with node quick-start.mjs. The .mjs extension runs the script as an ES module, as the SDK requires. The output contains a deterministic Block hash (0x...) followed by true, confirming successful validation. The same content produces the same hash on every machine:
import {createBlock, validateBlock} from '@alx-protocol/sdk';
const block = createBlock(
{type: 'note', text: 'Hello ALX'},
[],
);
const result = validateBlock(block);
console.log(block.blockHash);
console.log(result.ok);
node quick-start.mjs
0xe501e2ad688365e24523f3ceda68958aa53aa13eb63dbda953c3690c119faa0a
true
How ALX Works
The SDK canonicalizes the JSON content, computes contentHash and blockHash, and validates both identities. An empty parent array ([ ]), the second argument to createBlock, creates a root Block with no declared parents. Passing [block.blockHash] instead creates a Block that declares block as its parent; Compose Blocks into a Graph builds a Graph this way.