Getting Started with nXCC
Welcome to nXCC! This guide will get you up and running with your first cross-chain worker in just a few steps.
Quick Start
Section titled “Quick Start”Pick the runtime that matches your setup.
-
Run the container with host-only port mappings so the HTTP API and libp2p are reachable:
docker run --rm \--add-host=host.docker.internal:host-gateway \-p 127.0.0.1:6922:6922 \-p 127.0.0.1:9000:9000 \ghcr.io/nxcc-bridge/node:latest -
Access the node at
http://localhost:6922
(HTTP API) while keeping port9000
available for libp2p peers. Remove the leading127.0.0.1:
to expose the node to the network. -
To reach services running on your host (for example an Anvil instance on
127.0.0.1:8545
), connect tohttp://host.docker.internal:8545
-
Install the prerequisites: Rust 1.89+, Cargo, and Node.js 18+.
-
Install Cloudflare’s
workerd
runtime so the binary is onPATH
or referenced viaNXCC_WORKERD_BINARY_PATH
.brew install cloudflare/workers/workerdBASE=https://github.com/cloudflare/workerd/releases/latest/downloadcurl -fsSLo workerd.gz "$BASE/workerd-linux-64.gz"gunzip workerd.gzchmod +x workerdsudo mv workerd /usr/local/bin/BASE=https://github.com/cloudflare/workerd/releases/latest/downloadcurl -fsSLo workerd.gz "$BASE/workerd-linux-arm64.gz"gunzip workerd.gzchmod +x workerdsudo mv workerd /usr/local/bin/Prefer a custom location? Place the binary anywhere and export
NXCC_WORKERD_BINARY_PATH=/path/to/workerd
(orWORKERD_BIN_PATH
) before continuing. -
Start the local node:
git clone https://github.com/nxcc-bridge/nxcc.gitcd nxcc/node./run.sh
The node now serves the HTTP API at http://localhost:6922
and libp2p on 127.0.0.1:9001
.
Your First Worker
Section titled “Your First Worker”Create a simple worker that runs in a secure environment:
# Install the CLInpm install -g @nxcc/cli
# Create a new projectnxcc init my-nxcc-appcd my-nxcc-appnpm install
# Install the CLIpnpm add -g @nxcc/cli
# Create a new projectnxcc init my-nxcc-appcd my-nxcc-apppnpm install
The CLI creates a complete project structure. Let’s look at the generated worker:
import { worker, type WorkerContext } from "@nxcc/sdk";import { Hex, decodeEventLog, formatUnits, parseAbiItem } from "viem";
const transferEvent = parseAbiItem( "event Transfer(address indexed from, address indexed to, uint256 value)",);
export default worker({ async launch(eventPayload: Record<string, unknown>, { userdata }: WorkerContext) { console.log("Worker launched!", eventPayload, userdata); },
async fetch(request: Request, { userdata }: WorkerContext) { return { message: "Hello from nXCC worker!", path: new URL(request.url).pathname, }; },
async handleTransfer(eventPayload: Record<string, unknown>, { userdata }: WorkerContext) { try { const { args: { from, to, value }, } = decodeEventLog({ abi: [transferEvent], topics: eventPayload.topics as [signature: Hex, ...args: Hex[]], data: eventPayload.data as Hex, });
const transactionHash = eventPayload.transaction_hash as Hex; const blockNumber = eventPayload.block_number as number;
console.log(`➡️ Transfer detected in block ${blockNumber}:`); console.log(` From: ${from}`); console.log(` To: ${to}`); console.log(` Amount: ${formatUnits(value, 6)} USDC`); console.log(` Tx: ${transactionHash}`); } catch (error) { console.error("Failed to decode transfer event", error, eventPayload); } },
async tick(eventPayload: Record<string, unknown>, { userdata }: WorkerContext) { const timestamp = new Date().toISOString(); console.log(`Scheduled tick executed at ${timestamp}`);
// Example: Perform periodic tasks like data aggregation, monitoring, etc. const status = { timestamp, message: "Scheduled event fired successfully", eventPayload, userdata, };
console.log("Tick event processed:", status); return status; },});
This scaffold includes handlers for common trigger types:
launch
runs once when the worker is deployed and is perfect for bootstrap logic.fetch
handles HTTP requests and generic invocations routed through the runtime.handleTransfer
shows how to respond to token transfer events with decoded payloads.tick
demonstrates scheduled jobs for periodic background work.
Build and deploy it:
# Build the TypeScript workernpm run build
# Deploy to your local nodenxcc worker deploy --bundle workers/manifest.template.json --rpc-url http://localhost:6922
# Build the TypeScript workerpnpm run build
# Deploy to your local nodenxcc worker deploy --bundle workers/manifest.template.json --rpc-url http://localhost:6922
Your worker is now running!
Core Concepts
Section titled “Core Concepts”Workers: JavaScript/TypeScript code that runs in secure environments and can:
- React to blockchain events across 400+ chains
- Handle HTTP requests
- Access secrets and make API calls
- Send transactions
Secure by Default: All code runs in Trusted Execution Environments (TEEs) with memory encryption and remote attestation.
Multi-Chain Native: Built-in support for Ethereum, Polygon, Arbitrum, and 400+ other EVM chains.
Next Steps
Section titled “Next Steps”Follow our progressive tutorial series:
-
Blockchain Events - Build workers that react to on-chain events across multiple blockchains
-
Identities & Policies - Add secure credential management and access controls
Reference Docs
Section titled “Reference Docs”- Core Concepts - System architecture deep dive
- Worker Runtime - Complete JavaScript API reference
- CLI Reference - All CLI commands and options
Need Help?
Section titled “Need Help?”Ready to build the future of cross-chain applications? Let’s go! 🚀