Quickstart
If you are using secretvaults-ts, please upgrade to at least version 0.1.7
This guide walks you through building a Node.js demo app that uses Nillion's private storage with user-owned collections.
Reference the full Secretvaults-ts docs while you build: SecretVaults TypeScript Docs
What You'll Build
In this quickstart, you'll create a simple but powerful demonstration of private storage:
- Builder Setup: You (as a builder/application) will register for a Nillion API Key
- Create an Owned Collection: Define an owned collection with a specific schema that users can store private data in
- User Data Storage - A user will store their private data in your collection and grant you limited access to it
This showcases Nillion's core value: users own their data, but can selectively share it with applications.
What You'll Learn
- How builders create owned collections for user data
- How users store private data with individual access controls
- How to grant and revoke specific permissions (read/write/execute)
- How the @nillion/secretvaults library handles encryption and share distribution automatically
Prerequisites
1. Get Your API Key and Subscription
As good practice, we recommend to use two distinct keys: one for network access and a separate key for subscription payments. This dual-key architecture separates authentication from payment processing, enhancing security by limiting the scope of each credential.
- Create a Testnet public/private key pair through the UI that we will use for network access
- Fund your account with Testnet NIL
- Subscribe to
nilDBby paying with your subscription wallet - Save your private key (hex format) - you'll need this for authentication
2. System Requirements
Node.js 22+with ES modules supportpnpmpackage manager (you can usenpmoryarnas well)
Project Setup
Create a new Node.js project:
mkdir nillion-secretvaults-demo
cd nillion-secretvaults-demo
pnpm init
Add ES module support to your package.json by adding:
{
"type": "module"
}
Install Dependencies
Install the required Nillion packages:
pnpm add @nillion/secretvaults@latest @nillion/nuc dotenv
Environment Configuration
Create a .env file in your project root:
# .env
BUILDER_PRIVATE_KEY=your-hex-private-key-from-nilpay
# Optional: Override default testnet URLs if needed
# NILCHAIN_URL=http://rpc.testnet.nilchain-rpc-proxy.nilogy.xyz
# NILAUTH_URL=https://nilauth.sandbox.app-cluster.sandbox.nilogy.xyz
# NILDB_NODES=https://nildb-stg-n1.nillion.network,https://nildb-stg-n2.nillion.network,https://nildb-stg-n3.nillion.network