Quick Start
Create and validate an ALX Block with the published JavaScript package.
The example computes deterministic identities and validates the resulting Block locally. No account, API key, smart contract, blockchain, IPFS node, or network connection is required after the package is installed.
Install the Package
In a Node.js 20 or later project, install the package from npm:
npm i @alx-protocol/sdk
The package is @alx-protocol/sdk, the JavaScript implementation of the protocol. The same protocol is published for Python as alx-protocol on PyPI and for Rust as alx-protocol on crates.io; all three produce the same identities from the same input.
Create and Validate a Block
Create quick-start.mjs in the project:
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);
Run the script:
node quick-start.mjs
A successful execution prints a lowercase 0x-prefixed Block hash and true. The empty parent array creates a root Block with no declared parent relationships.
What Happened
The protocol package:
- Canonicalized the JSON content.
- Computed
contentHash. - Normalized the parent set.
- Computed
blockHash. - Recomputed and compared both deterministic identities during validation.
Any conforming implementation can repeat this workflow and produce equivalent results from equivalent protocol inputs.