Creating ENSRainbow Files
ENSRainbow provides two methods for creating .ensrainbow files from different data sources. This guide helps you choose the right method and provides step-by-step instructions.
Prerequisites
Section titled “Prerequisites”Before creating .ensrainbow files, ensure you have:
-
ENSNode repository cloned:
Terminal window git clone https://github.com/namehash/ensnode.gitcd ensnode -
Dependencies installed:
Terminal window pnpm install -
Working directory: Navigate to the ENSRainbow directory:
Terminal window cd apps/ensrainbow
All commands in this guide assume you’re in the apps/ensrainbow directory unless otherwise specified.
Overview
Section titled “Overview”A .ensrainbow file is ENSRainbow’s binary format for storing label-to-labelhash mappings. It uses Protocol Buffers for efficient serialization and supports streaming for large datasets.
For detailed information about the file format structure, see the Data Model documentation.
Choosing Your Conversion Method
Section titled “Choosing Your Conversion Method”| Method | Input Format | Use Case | Command |
|---|---|---|---|
| SQL Conversion | Gzipped SQL dump (ens_names.sql.gz) | Converting legacy ENS Subgraph data | pnpm run convert |
| CSV Conversion | CSV file (1 or 2 columns) | Custom datasets, test data, external sources | pnpm run convert-csv |
When to Use SQL Conversion
Section titled “When to Use SQL Conversion”- Converting existing ENS Subgraph rainbow tables
- Working with legacy
ens_names.sql.gzfiles - Migrating from previous ENS data formats
When to Use CSV Conversion
Section titled “When to Use CSV Conversion”- Creating test datasets
- Converting data from external sources
- Working with custom label collections
- Building incremental label sets
Method 1: Converting from SQL Dumps
Section titled “Method 1: Converting from SQL Dumps”The convert command processes gzipped SQL dump files from the ENS Subgraph.
Command Syntax
Section titled “Command Syntax”pnpm run convert \ --input-file <path/to/ens_names.sql.gz> \ --output-file <output.ensrainbow> \ --label-set-id <label-set-id> \ --label-set-version <version-number>Required Parameters
Section titled “Required Parameters”--input-file: Path to the gzipped SQL dump file--label-set-id: Identifier for the label set (e.g.,subgraph,discovery-a)--label-set-version: Version number for the label set (non-negative integer)
Optional Parameters
Section titled “Optional Parameters”--output-file: Output file path (defaults torainbow-records.ensrainbow)
Example: Converting ENS Subgraph Data
Section titled “Example: Converting ENS Subgraph Data”# Convert main ENS Subgraph datapnpm run convert \ --input-file ens_names.sql.gz \ --output-file subgraph_0.ensrainbow \ --label-set-id subgraph \ --label-set-version 0Example: Converting Test Data
Section titled “Example: Converting Test Data”# Convert ens-test-env datapnpm run convert \ --input-file test/fixtures/ens_test_env_names.sql.gz \ --output-file ens-test-env_0.ensrainbow \ --label-set-id ens-test-env \ --label-set-version 0How It Works
Section titled “How It Works”- Streams the gzipped SQL file to avoid memory issues
- Parses SQL COPY statements to extract label/labelhash pairs
- Validates each record and skips invalid entries
- Writes protobuf messages with length-delimited encoding
- Creates a header message followed by individual record messages
Method 2: Converting from CSV Files
Section titled “Method 2: Converting from CSV Files”The convert-csv command processes CSV files with flexible column formats.
Command Syntax
Section titled “Command Syntax”pnpm run convert-csv \ --input-file <path/to/data.csv> \ --output-file <output.ensrainbow> \ --label-set-id <label-set-id> \ --label-set-version <version-number> \ [--progress-interval <number>] \ [--existing-db-path <path/to/existing/database>]Required Parameters
Section titled “Required Parameters”--input-file: Path to the CSV file--label-set-id: Identifier for the label set--label-set-version: Version number for the label set
Optional Parameters
Section titled “Optional Parameters”--output-file: Output file path (defaults torainbow-records.ensrainbow)--progress-interval: Progress logging frequency (default: 10000 records)--existing-db-path: Path to existing ENSRainbow database to filter out existing labels
CSV Format Support
Section titled “CSV Format Support”The CSV converter supports two formats:
Single Column Format (Label Only)
Section titled “Single Column Format (Label Only)”ethereumvitalikensThe converter automatically computes labelhashes using the labelhash() function.
Two Column Format (Label + Labelhash)
Section titled “Two Column Format (Label + Labelhash)”ethereum,0x541111248b45b7a8dc3f5579f630e74cb01456ea6ac067d3f4d793245a255155vitalik,0xaf2caa1c2ca1d027f1ac823b529d0a67cd144264b2789fa2ea4d63a67c7103ccens,0x5cee339e13375638553bdf5a6e36ba80fb9f6a4f0783680884d92b558aa471daThe converter validates that provided labelhashes match the computed hash for each label.
Label Filtering
Section titled “Label Filtering”The CSV converter includes built-in filtering capabilities to prevent duplicate labels:
Filtering Existing Labels
Section titled “Filtering Existing Labels”Use --existing-db-path to filter out labels that already exist in an existing ENSRainbow database:
pnpm run convert-csv \ --input-file new-labels.csv \ --output-file incremental_1.ensrainbow \ --label-set-id my-dataset \ --label-set-version 1 \ --existing-db-path data-my-datasetThis will:
- Check each label against the existing database
- Skip labels that already exist (avoiding duplicates)
- Only write new labels to the output file
- Log filtering statistics in the conversion summary
Filtering Duplicate Labels Within CSV
Section titled “Filtering Duplicate Labels Within CSV”The converter automatically filters duplicate labels within the same CSV file, keeping only the first occurrence of each label.
Filtering Statistics
Section titled “Filtering Statistics”The conversion process logs detailed statistics:
=== Conversion Summary ===Total lines processed: 1000Valid records: 850Filtered existing labels: 100Filtered duplicates: 50Duration: 150msExample: Creating Test Dataset
Section titled “Example: Creating Test Dataset”# Create test dataset from CSVpnpm run convert-csv \ --input-file test-labels.csv \ --output-file test-dataset_0.ensrainbow \ --label-set-id test-dataset \ --label-set-version 0Example: Creating Discovery Dataset
Section titled “Example: Creating Discovery Dataset”# Create discovery dataset (initially empty)echo "" > empty.csvpnpm run convert-csv \ --input-file empty.csv \ --output-file discovery-a_0.ensrainbow \ --label-set-id discovery-a \ --label-set-version 0How It Works
Section titled “How It Works”- Detects CSV format automatically (1 or 2 columns)
- Streams CSV parsing using fast-csv for memory efficiency
- Validates column count and data format
- Computes or validates labelhashes as needed
- Filters existing labels if
--existing-db-pathis provided - Filters duplicate labels within the same CSV file
- Writes protobuf messages with the same format as SQL conversion
Common Workflows
Section titled “Common Workflows”Workflow 1: Migrating from ENS Subgraph
Section titled “Workflow 1: Migrating from ENS Subgraph”# 1. Convert SQL dump to .ensrainbowpnpm run convert \ --input-file ens_names.sql.gz \ --output-file subgraph_0.ensrainbow \ --label-set-id subgraph \ --label-set-version 0
# 2. Ingest into LevelDBpnpm run ingest-ensrainbow \ --input-file subgraph_0.ensrainbow \ --data-dir data-subgraph
# 3. Validate the databasepnpm run validate --data-dir data-subgraph
# 4. Start the API serverpnpm run serve --data-dir data-subgraph --port 3223Workflow 2: Creating Test Environment
Section titled “Workflow 2: Creating Test Environment”# 1. Convert test datapnpm run convert \ --input-file test/fixtures/ens_test_env_names.sql.gz \ --output-file ens-test-env_0.ensrainbow \ --label-set-id ens-test-env \ --label-set-version 0
# 2. Ingest test datapnpm run ingest-ensrainbow \ --input-file ens-test-env_0.ensrainbow \ --data-dir data-test-env
# 3. Run with test datapnpm run serve --data-dir data-test-env --port 3223Workflow 3: Building Custom Dataset
Section titled “Workflow 3: Building Custom Dataset”# 1. Create CSV with your labelsecho "mylabel1mylabel2mylabel3" > custom-labels.csv
# 2. Convert to .ensrainbowpnpm run convert-csv \ --input-file custom-labels.csv \ --output-file custom_0.ensrainbow \ --label-set-id custom \ --label-set-version 0
# 3. Ingest and servepnpm run ingest-ensrainbow \ --input-file custom_0.ensrainbow \ --data-dir data-custom
pnpm run serve --data-dir data-custom --port 3223Workflow 4: Creating Incremental Updates
Section titled “Workflow 4: Creating Incremental Updates”# 1. Create initial datasetpnpm run convert-csv \ --input-file initial-labels.csv \ --output-file my-dataset_0.ensrainbow \ --label-set-id my-dataset \ --label-set-version 0
# 2. Ingest initial datapnpm run ingest-ensrainbow \ --input-file my-dataset_0.ensrainbow \ --data-dir data-my-dataset
# 3. Create incremental update (filtering existing labels)pnpm run convert-csv \ --input-file new-labels.csv \ --output-file my-dataset_1.ensrainbow \ --label-set-id my-dataset \ --label-set-version 1 \ --existing-db-path data-my-dataset
# 4. Ingest incremental updatepnpm run ingest-ensrainbow \ --input-file my-dataset_1.ensrainbow \ --data-dir data-my-dataset
# 5. Serve updated datapnpm run serve --data-dir data-my-dataset --port 3223Workflow 5: Using Custom Label Set Server
Section titled “Workflow 5: Using Custom Label Set Server”# 1. Configure custom label set serverexport ENSRAINBOW_LABELSET_SERVER_URL="https://my-label-set-server.com"
# 2. Download from custom server# The script downloads to labelsets/ subdirectory./scripts/download-ensrainbow-files.sh my-dataset 0
# 3. Ingest and serve# Files are downloaded to labelsets/ by the scriptpnpm run ingest-ensrainbow \ --input-file labelsets/my-dataset_0.ensrainbow \ --data-dir data-my-dataset
pnpm run serve --data-dir data-my-dataset --port 3223ENSRainbow download scripts save files to specific subdirectories:
.ensrainbowfiles:labelsets/- Database archives:
databases/{schema_version}/ - Checksums and licenses: Same directory as the downloaded file
File Naming Conventions
Section titled “File Naming Conventions”Follow the naming convention: {label-set-id}_{label-set-version}.ensrainbow
Examples:
subgraph_0.ensrainbow- Main ENS data, version 0subgraph_1.ensrainbow- Main ENS data, version 1 (incremental update)discovery-a_0.ensrainbow- Discovery dataset, version 0ens-test-env_0.ensrainbow- Test environment data, version 0
Next Steps
Section titled “Next Steps”After creating your .ensrainbow file:
- Ingest the data into a ENSRainbow database
- Validate the database to ensure integrity
- Start the API server to serve the data
For complete CLI reference information, see the CLI Reference documentation.
Creating and Publishing Custom .ensrainbow Files
Section titled “Creating and Publishing Custom .ensrainbow Files”If you want to create, publish, and distribute your own .ensrainbow files, follow these steps:
1. Create Your Dataset
Section titled “1. Create Your Dataset”First, prepare your data in either SQL or CSV (recommended) format, then convert it using the appropriate method:
# For CSV datapnpm run convert-csv \ --input-file my-labels.csv \ --output-file my-dataset_0.ensrainbow \ --label-set-id my-dataset \ --label-set-version 0
# For CSV data with filtering (if you have an existing database)pnpm run convert-csv \ --input-file my-labels.csv \ --output-file my-dataset_1.ensrainbow \ --label-set-id my-dataset \ --label-set-version 1 \ --existing-db-path data-my-dataset
# For SQL datapnpm run convert \ --input-file my-data.sql.gz \ --output-file my-dataset_0.ensrainbow \ --label-set-id my-dataset \ --label-set-version 02. Validate Your File
Section titled “2. Validate Your File”Test your .ensrainbow file by ingesting it locally:
# Ingest your custom datasetpnpm run ingest-ensrainbow \ --input-file my-dataset_0.ensrainbow \ --data-dir data-my-dataset
# Validate the databasepnpm run validate --data-dir data-my-dataset
# Test the APIpnpm run serve --data-dir data-my-dataset --port 32233. Publish Your File
Section titled “3. Publish Your File”Option A: Direct File Sharing
Section titled “Option A: Direct File Sharing”- Upload your
.ensrainbowfile to a web server or cloud storage - Provide a direct download URL
- Share checksums for integrity verification
Option B: Package as Database Archive
Section titled “Option B: Package as Database Archive”For better performance, package your data as a pre-built database:
# Ingest your .ensrainbow filepnpm run ingest-ensrainbow \ --input-file my-dataset_0.ensrainbow \ --data-dir data-my-dataset
# Package the databasetar -czvf my-dataset_0.tgz ./data-my-dataset
# Calculate checksumsha256sum my-dataset_0.tgz > my-dataset_0.tgz.sha256sum4. Document Your Label Set
Section titled “4. Document Your Label Set”Create documentation for your custom label set including:
- Label Set ID: The identifier users will specify
- Description: What labels are included and their source
- Version: Current version number
- Download URLs: Where to get the files
- Checksums: For integrity verification
- Usage Examples: How to use your dataset
Example Documentation Format
Section titled “Example Documentation Format”## Custom Label Set: my-dataset
**Label Set ID**: `my-dataset`**Current Version**: `0`**Description**: Custom ENS labels from [source description]
### Download- Database Archive: `https://example.com/my-dataset_0.tgz`- Checksum: `https://example.com/my-dataset_0.tgz.sha256sum`
### Usage```bash# Using with Dockerdocker run -d \ -e DB_SCHEMA_VERSION="3" \ -e LABEL_SET_ID="my-dataset" \ -e LABEL_SET_VERSION="0" \ -p 3223:3223 \ ghcr.io/namehash/ensnode/ensrainbow:latestSetting Up Your Own Label Set Server
Section titled “Setting Up Your Own Label Set Server”A Label Set Server is a storage and hosting service for .ensrainbow files and prebuilt database archives. It’s not the ENSRainbow API server itself, but rather a way to distribute your custom datasets for others to download and use.
1. Choose Your Hosting Platform
Section titled “1. Choose Your Hosting Platform”You can host your label set files on any web server or cloud storage service:
- AWS S3: Industry standard with versioning
- Cloudflare R2: Cost-effective alternative to S3
- Simple HTTP server: For internal/private use
2. Organize Your Files
Section titled “2. Organize Your Files”Structure your label set files following ENSRainbow conventions:
my-label-set-server/├── labelsets/│ ├── my-dataset_0.ensrainbow│ ├── my-dataset_0.ensrainbow.sha256sum│ ├── my-dataset_1.ensrainbow│ └── my-dataset_1.ensrainbow.sha256sum└── databases/ ├── 3/ # Schema version │ ├── my-dataset_0.tgz │ ├── my-dataset_0.tgz.sha256sum │ ├── my-dataset_1.tgz │ └── my-dataset_1.tgz.sha256sum └── 4/ # Future schema version3. Use Existing Download Scripts
Section titled “3. Use Existing Download Scripts”ENSRainbow provides ready-to-use download scripts that users can configure to download from your label set server:
Download .ensrainbow Files
Section titled “Download .ensrainbow Files”# Configure your label set server URLexport ENSRAINBOW_LABELSET_SERVER_URL="https://my-label-set-server.com"
# Download .ensrainbow file using the existing script./scripts/download-ensrainbow-files.sh my-dataset 0Download Prebuilt Database Archives
Section titled “Download Prebuilt Database Archives”# Configure your label set server URLexport ENSRAINBOW_LABELSET_SERVER_URL="https://my-label-set-server.com"
# Download prebuilt database using the existing script./scripts/download-prebuilt-database.sh 3 my-dataset 0Script Features
Section titled “Script Features”The existing scripts automatically handle:
- Checksum verification for data integrity
- Resume downloads if files already exist and are valid
- License file downloads (optional)
- Progress reporting for large files
- Error handling with cleanup of partial downloads
4. Document Your Label Set Server
Section titled “4. Document Your Label Set Server”Create a README or documentation page for your label set server:
# My Label Set Server
This server hosts custom ENS label sets for ENSRainbow.
## Available Label Sets
### my-dataset- **Description**: Custom ENS labels from [source]- **Versions**: 0, 1- **Schema Versions**: 3- **Base URL**: `https://my-label-set-server.com`
### another-dataset- **Description**: Additional labels from [source]- **Versions**: 0- **Schema Versions**: 3- **Base URL**: `https://my-label-set-server.com`Users should have the ENSNode repository cloned and be in the apps/ensrainbow directory.
Option 1: Download .ensrainbow Files
Section titled “Option 1: Download .ensrainbow Files”# Configure your label set serverexport ENSRAINBOW_LABELSET_SERVER_URL="https://my-label-set-server.com"
# Download .ensrainbow file./scripts/download-ensrainbow-files.sh my-dataset 0
# Ingest into ENSRainbowpnpm run ingest-ensrainbow \ --input-file labelsets/my-dataset_0.ensrainbow \ --data-dir data-my-dataset
# Start ENSRainbow serverpnpm run serve --data-dir data-my-dataset --port 3223Option 2: Download Prebuilt Databases (Faster)
Section titled “Option 2: Download Prebuilt Databases (Faster)”# Configure your label set serverexport ENSRAINBOW_LABELSET_SERVER_URL="https://my-label-set-server.com"
# Download prebuilt database./scripts/download-prebuilt-database.sh 3 my-dataset 0
# Extract databasetar -xzf databases/3/my-dataset_0.tgz -C data-my-dataset --strip-components=1
# Start ENSRainbow serverpnpm run serve --data-dir data-my-dataset --port 32235. Version Management
Section titled “5. Version Management”Implement proper versioning for your label sets:
# When releasing a new versionLABEL_SET_ID="my-dataset"NEW_VERSION="1"
# Create new .ensrainbow filepnpm run convert-csv \ --input-file updated-labels.csv \ --output-file ${LABEL_SET_ID}_${NEW_VERSION}.ensrainbow \ --label-set-id ${LABEL_SET_ID} \ --label-set-version ${NEW_VERSION}
# Create prebuilt databasepnpm run ingest-ensrainbow \ --input-file ${LABEL_SET_ID}_${NEW_VERSION}.ensrainbow \ --data-dir data-${LABEL_SET_ID}-${NEW_VERSION}
tar -czvf ${LABEL_SET_ID}_${NEW_VERSION}.tgz ./data-${LABEL_SET_ID}-${NEW_VERSION}
# Calculate checksumssha256sum ${LABEL_SET_ID}_${NEW_VERSION}.ensrainbow > ${LABEL_SET_ID}_${NEW_VERSION}.ensrainbow.sha256sumsha256sum ${LABEL_SET_ID}_${NEW_VERSION}.tgz > ${LABEL_SET_ID}_${NEW_VERSION}.tgz.sha256sum
# Upload to your label set server# (implementation depends on your hosting platform)6. Testing Your Label Set Server
Section titled “6. Testing Your Label Set Server”Before publishing, test that your label set server works correctly:
# Set your test server URLexport ENSRAINBOW_LABELSET_SERVER_URL="https://my-label-set-server.com"
# Test downloading .ensrainbow file./scripts/download-ensrainbow-files.sh my-dataset 0
# Verify checksum was validated# The script will fail if checksums don't match
# Test downloading prebuilt database./scripts/download-prebuilt-database.sh 3 my-dataset 0
# Verify the database workspnpm run ingest-ensrainbow \ --input-file labelsets/my-dataset_0.ensrainbow \ --data-dir test-data
pnpm run validate --data-dir test-dataRunning Your Own ENSRainbow Server
Section titled “Running Your Own ENSRainbow Server”If you want to run your own ENSRainbow API server (separate from the label set server), see the Local Development guide for instructions on setting up and running ENSRainbow locally or in production.
Related Documentation
Section titled “Related Documentation”- Data Model - Understanding the
.ensrainbowfile format - Label Sets & Versioning - Managing label set versions
- CLI Reference - Complete command documentation
- Local Development - Setting up your development environment