Are you an LLM? Read llms.txt for a summary of the docs, or llms-full.txt for the full context.
Skip to content

Node.js script

This example goes end to end in one file: connect to your project, upload a file to your own bucket, read the index back from the network, download it, and delete its index. Everything below runs on the Demo network with test tokens.

Before you start

Create a project in the dashboard (Your first project) with at least one storage provider, then open the project's SDK tab and copy:

  • the Project ID (cloudId),
  • the Secret key (click Reveal, then copy),
  • the encryption settings shown next to them (curve and algorithm).

You also need an account private key with a little Demo network currency to pay fees for the write, plus a short-lived token for your storage signing service. Keep all runtime secrets in environment variables, never in source control.

Setup

mkdir dataprism-demo && cd dataprism-demo
pnpm init && pnpm add @dataprism/sdk viem

Connect

import { DataPrismClient } from "@dataprism/sdk";
import { DataPrismNetwork, DEMO } from "@dataprism/sdk/network";
import { createWalletClient, hexToBytes, http } from "viem";
import { privateKeyToAccount } from "viem/accounts";
 
const RPC_URL = "https://ethereum-sepolia-rpc.publicnode.com";
const network = new DataPrismNetwork(DEMO, RPC_URL);
 
const account = privateKeyToAccount(process.env.PRIVATE_KEY as `0x${string}`);
const accountClient = createWalletClient({
  account,
  chain: network.chain,
  transport: http(RPC_URL),
});
 
const client = new DataPrismClient(network, { accountClient });

Configure project access

import { DataPrismKey } from "@dataprism/sdk/crypto";
import { CloudStandard } from "@dataprism/sdk/standard";
 
const cloudId = process.env.PROJECT_ID as `0x${string}`; // Project ID (cloudId)
const key = DataPrismKey.fromSecret(
  process.env.SECRET_KEY as `0x${string}`, // Secret key
  { curve: "secp256k1", algorithm: "aes-256-gcm" }, // as shown in the SDK tab
);
const std = new CloudStandard(key);

That is the project handshake: the Project ID says which prism to talk to, and the Secret key decrypts its index. File reads and writes also use an application-generated 32-byte scopeKey. Generate it once when provisioning the prism, store and back it up with the prism secrets in your environment or secret manager, and restore the same value for every later operation. Never generate a replacement key when opening an existing prism.

Upload and download a file

import { FilePipeline } from "@dataprism/sdk/files";
import { initProviders, signedUrlFactories } from "@dataprism/sdk/storage";
 
// The project contains only bucket metadata and customer-controlled signer URLs.
// The signer token is supplied at runtime and is never written to the project.
const storageSignerToken = process.env.STORAGE_SIGNER_TOKEN;
if (!storageSignerToken) throw new Error("STORAGE_SIGNER_TOKEN is required");
 
const scopeKeyHex = process.env.DATAPRISM_SCOPE_KEY;
if (!scopeKeyHex || !/^0x[0-9a-fA-F]{64}$/.test(scopeKeyHex)) {
  throw new Error("DATAPRISM_SCOPE_KEY must be one 0x-prefixed 32-byte value");
}
const scopeKey = hexToBytes(scopeKeyHex as `0x${string}`);
 
const view = std.reader(client.reader, cloudId);
const storage = initProviders(
  await view.providers(),
  signedUrlFactories({
    getSignerHeaders: () => ({
      authorization: `Bearer ${storageSignerToken}`,
    }),
  }),
);
 
const pipeline = new FilePipeline({
  providers: storage,
  standard: std,
  scopeKey,
  execution: client.execution,
  cloudId,
  source: client.reader,
});
 
const bytes = new TextEncoder().encode("hello dataprism");
const { write: upload } = await pipeline.upload("hello.txt", bytes, {
  chunkSize: 65_536,
  dataShards: 1,
  parityShards: 0,
});
await upload?.wait();
 
const index = await view.file("hello.txt");
const restored = await pipeline.download(index);
console.log(new TextDecoder().decode(restored)); // hello dataprism

The file that landed in your bucket is a set of encrypted, hash-named shards. Without your Secret key, it is noise.

Delete the file index

import { appendFile } from "node:fs/promises";
 
const { dataId, shards, write } = await pipeline.delete("hello.txt");
await write.wait();
await appendFile(
  "dataprism-shard-cleanup.jsonl",
  `${JSON.stringify({ dataId, shards })}\n`,
  { encoding: "utf8", mode: 0o600 },
);

delete removes the encrypted file index from the project. It returns the shard locations; keep that cleanup record because the deleted index can no longer supply them. A customer-controlled cleanup process can later check whether the objects are still shared before removing them. See Deletion for physical cleanup and deduplication safety.

Where to go next

  • With several providers configured, raise dataShards and parityShards to spread shards and tolerate provider outages.
  • Prisms can also be created entirely from code, without the dashboard, via PrismManager.
  • The complete, runnable version of this script lives in the repository under examples/node-esm, including a delegated variant that writes through the DataPrism API without paying network fees itself.
Copyright © 2026 DataPrism.