Uploads user data with automatic encryption and blockchain registration.
Upload parameters including content, filename, schema, and permissions
Promise resolving to upload results with file ID and transaction hash
This is the primary method for uploading user data to the Vana network. It handles the complete workflow including content normalization, schema validation, encryption, storage upload, permission granting, and blockchain registration.
The method automatically:
When using permissions with encryption enabled (default), you must provide the public key for each permission recipient.
// Basic file upload
const result = await vana.data.upload({
content: "My personal data",
filename: "diary.txt"
});
// Upload with schema validation
const result = await vana.data.upload({
content: { name: "John", age: 30 },
filename: "profile.json",
schemaId: 1
});
// Upload with permissions (encrypted - requires publicKey)
const result = await vana.data.upload({
content: "Data for AI analysis",
filename: "analysis.txt",
permissions: [{
grantee: "0x1234...",
operation: "llm_inference",
parameters: { model: "gpt-4" },
publicKey: "0x04..." // Required when encrypt is true (default)
}]
});
// Upload without encryption
const result = await vana.data.upload({
content: "Public data",
filename: "public.txt",
encrypt: false,
permissions: [{
grantee: "0x1234...",
operation: "read",
parameters: {}
}]
});
Uploads user data with automatic encryption and blockchain registration.
Upload parameters including content, filename, schema, and permissions
Promise resolving to upload results with file ID and transaction hash
This is the primary method for uploading user data to the Vana network. It handles the complete workflow including content normalization, schema validation, encryption, storage upload, permission granting, and blockchain registration.
The method automatically:
When using permissions with encryption enabled (default), you must provide the public key for each permission recipient.
// Basic file upload
const result = await vana.data.upload({
content: "My personal data",
filename: "diary.txt"
});
// Upload with schema validation
const result = await vana.data.upload({
content: { name: "John", age: 30 },
filename: "profile.json",
schemaId: 1
});
// Upload with permissions (encrypted - requires publicKey)
const result = await vana.data.upload({
content: "Data for AI analysis",
filename: "analysis.txt",
permissions: [{
grantee: "0x1234...",
operation: "llm_inference",
parameters: { model: "gpt-4" },
publicKey: "0x04..." // Required when encrypt is true (default)
}]
});
// Upload without encryption
const result = await vana.data.upload({
content: "Public data",
filename: "public.txt",
encrypt: false,
permissions: [{
grantee: "0x1234...",
operation: "read",
parameters: {}
}]
});
Uploads user data with automatic encryption and blockchain registration.
Upload parameters including content, filename, schema, and permissions
Promise resolving to upload results with file ID and transaction hash
This is the primary method for uploading user data to the Vana network. It handles the complete workflow including content normalization, schema validation, encryption, storage upload, permission granting, and blockchain registration.
The method automatically:
When using permissions with encryption enabled (default), you must provide the public key for each permission recipient.
// Basic file upload
const result = await vana.data.upload({
content: "My personal data",
filename: "diary.txt"
});
// Upload with schema validation
const result = await vana.data.upload({
content: { name: "John", age: 30 },
filename: "profile.json",
schemaId: 1
});
// Upload with permissions (encrypted - requires publicKey)
const result = await vana.data.upload({
content: "Data for AI analysis",
filename: "analysis.txt",
permissions: [{
grantee: "0x1234...",
operation: "llm_inference",
parameters: { model: "gpt-4" },
publicKey: "0x04..." // Required when encrypt is true (default)
}]
});
// Upload without encryption
const result = await vana.data.upload({
content: "Public data",
filename: "public.txt",
encrypt: false,
permissions: [{
grantee: "0x1234...",
operation: "read",
parameters: {}
}]
});
Decrypts a file owned by the user using their wallet signature.
The user file to decrypt (typically from getUserFiles)
Optional
encryptionSeed: stringOptional custom encryption seed (defaults to Vana standard)
Promise resolving to the decrypted file content as a Blob
This is the high-level convenience method for decrypting user files, serving as the
symmetrical counterpart to the upload
method. It handles the complete decryption
workflow including key generation, URL protocol detection, content fetching, and
decryption.
The method automatically:
For IPFS URLs, the method uses gateway fallback for improved reliability. For standard HTTP URLs, it uses a simple fetch. If you need custom authentication headers or specific gateway configurations, use the low-level primitives directly.
// Basic file decryption
const files = await vana.data.getUserFiles({ owner: userAddress });
const decryptedBlob = await vana.data.decryptFile(files[0]);
// Convert to text
const text = await decryptedBlob.text();
console.log('Decrypted content:', text);
// Convert to JSON
const json = JSON.parse(await decryptedBlob.text());
console.log('Decrypted data:', json);
// With custom encryption seed
const decryptedBlob = await vana.data.decryptFile(
files[0],
"My custom encryption seed"
);
// Save to file (in Node.js)
const buffer = await decryptedBlob.arrayBuffer();
fs.writeFileSync('decrypted-file.txt', Buffer.from(buffer));
Retrieves all data files owned by a specific user address.
The query parameters object
The wallet address of the file owner to query
Optional
subgraphUrl?: stringOptional subgraph URL to override the default endpoint
A Promise that resolves to an array of UserFile objects with metadata
Retrieves a list of permissions granted by a user using the new subgraph entities.
This method queries the Vana subgraph to find permissions directly granted by the user using the new Permission entity. It efficiently handles millions of permissions by:
Object containing the user address and optional subgraph URL
The wallet address of the user to query permissions for
Optional
subgraphUrl?: stringOptional subgraph URL to override the default
Promise resolving to an array of permission objects
Retrieves a list of trusted servers for a user using the new subgraph entities.
This method queries the Vana subgraph to find trusted servers directly associated with the user with support for both subgraph and direct RPC queries.
This method supports multiple query modes:
Query parameters including user address and mode selection
Promise resolving to trusted servers with metadata about the query
// Use subgraph for fast queries
const result = await vana.data.getUserTrustedServers({
user: '0x...',
mode: 'subgraph',
subgraphUrl: 'https://...'
});
// Use direct RPC (no external dependencies)
const result = await vana.data.getUserTrustedServers({
user: '0x...',
mode: 'rpc',
limit: 10
});
// Auto-fallback mode
const result = await vana.data.getUserTrustedServers({
user: '0x...',
mode: 'auto' // tries subgraph first, falls back to RPC
});
Gets the total number of files in the registry from the contract.
Promise resolving to the total file count
Retrieves details for a specific file by its ID.
The file ID to look up
Promise resolving to UserFile object
try {
const file = await vana.data.getFileById(123);
console.log('File details:', {
id: file.id,
url: file.url,
owner: file.ownerAddress,
addedAt: file.addedAtBlock
});
} catch (error) {
console.error('File not found or error retrieving file:', error);
}
This method queries the DataRegistry contract directly to get file details for any file ID, regardless of user ownership. This is useful for file lookup functionality where users can search for specific files by ID.
Uploads an encrypted file to storage and registers it on the blockchain.
The encrypted file blob to upload
Optional
filename: stringOptional filename for the upload
Optional
providerName: stringOptional storage provider to use
Promise resolving to upload result with file ID and storage URL
This method handles the complete flow of:
Uploads an encrypted file to storage and registers it on the blockchain with a schema.
The encrypted file blob to upload
The schema ID to associate with the file
Optional
filename: stringOptional filename for the upload
Optional
providerName: stringOptional storage provider to use
Promise resolving to upload result with file ID and storage URL
This method handles the complete flow of:
Registers a file URL directly on the blockchain with a schema ID.
The URL of the file to register
The schema ID to associate with the file
Promise resolving to the file ID and transaction hash
This method registers an existing file URL on the DataRegistry contract with a schema ID, without uploading any data.
Adds a file with permissions to the DataRegistry contract.
The file URL to register
The address of the file owner
Array of permissions to set for the file
Promise resolving to file ID and transaction hash
This method handles the core logic of registering a file with specific permissions on the DataRegistry contract. It can be used by both direct transactions and relayer services.
Adds a file to the registry with permissions and schema. This combines the functionality of addFileWithPermissions and schema validation.
The URL of the file to register
The address of the file owner
Array of permissions to grant (account and encrypted key)
The schema ID to associate with the file (0 for no schema)
Promise resolving to object with fileId and transactionHash
Adds a new schema to the DataRefinerRegistry.
Schema parameters including name, type, and definition URL
Promise resolving to the new schema ID and transaction hash
Retrieves a schema by its ID.
The schema ID to retrieve
Promise resolving to the schema information
Adds a new refiner to the DataRefinerRegistry.
Refiner parameters including DLP ID, name, schema ID, and instruction URL
Promise resolving to the new refiner ID and transaction hash
Retrieves a refiner by its ID.
The refiner ID to retrieve
Promise resolving to the refiner information
Validates if a schema ID exists in the registry.
The schema ID to validate
Promise resolving to boolean indicating if the schema ID is valid
Gets the total number of refiners in the registry.
Promise resolving to the total refiner count
Updates the schema ID for an existing refiner.
Parameters including refiner ID and new schema ID
Promise resolving to the transaction hash
Uploads an encrypted file and grants permission to a party with a public key.
This method handles the complete workflow:
The file data to encrypt and upload
Array of permissions to grant, each with account address and public key
Optional
filename: stringOptional filename for the upload
Optional
providerName: stringOptional storage provider to use
Promise resolving to upload result with file ID and storage URL
Adds a permission for a party to access an existing file.
This method handles the complete workflow:
The ID of the file to add permissions for
The address of the account to grant permission to
The public key to encrypt the user's encryption key with
Promise resolving to the transaction hash
Gets the encrypted key for a specific account's permission to access a file.
The ID of the file
The account address to get the permission for
Promise resolving to the encrypted key for that account
Decrypts a file that the user has permission to access using their private key.
This method handles the complete workflow for servers or other permitted parties:
The file to decrypt
The private key to decrypt the user's encryption key
Optional
account: `0x${string}`The account address that has permission (defaults to current wallet account)
Promise resolving to the decrypted file data
Simple network-agnostic fetch utility for retrieving file content.
The URL to fetch content from
Promise resolving to the fetched content as a Blob
This is a thin wrapper around the global fetch API that returns the response as a Blob. It provides a consistent interface for fetching encrypted content before decryption. For IPFS URLs, consider using fetchFromIPFS for better reliability.
// Fetch and decrypt a file
const encryptionKey = await generateEncryptionKey(walletClient);
const encryptedBlob = await vana.data.fetch(file.url);
const decryptedBlob = await decryptBlob(encryptedBlob, encryptionKey, platform);
// With custom headers for authentication
const response = await fetch(file.url, {
headers: { 'Authorization': 'Bearer token' }
});
const encryptedBlob = await response.blob();
Specialized IPFS fetcher with gateway fallback mechanism.
The IPFS URL (ipfs://...) or CID to fetch
Optional
options: { gateways?: string[] }Optional configuration
Optional
gateways?: string[]Array of IPFS gateway URLs to try (must end with /)
Promise resolving to the fetched content as a Blob
This method provides robust IPFS content fetching by trying multiple gateways in sequence until one succeeds. It supports both ipfs:// URLs and raw CIDs.
The default gateway list includes public gateways, but you should provide your own gateways for production use to ensure reliability and privacy.
// Fetch from IPFS with custom gateways
const encryptedBlob = await vana.data.fetchFromIPFS(file.url, {
gateways: [
'https://my-private-gateway.com/ipfs/',
'https://dweb.link/ipfs/',
'https://ipfs.io/ipfs/'
]
});
// Decrypt the fetched content
const encryptionKey = await generateEncryptionKey(walletClient);
const decryptedBlob = await decryptBlob(encryptedBlob, encryptionKey, platform);
// With raw CID
const blob = await vana.data.fetchFromIPFS('QmXxx...', {
gateways: ['https://ipfs.io/ipfs/']
});
Validates a data schema against the Vana meta-schema.
The data schema to validate
Assertion that schema is valid (throws if invalid)
Validates data against a JSON Schema from a data schema.
The data to validate
The data schema containing the schema
Void (throws if validation fails)
Fetches and validates a schema from a URL, then returns the parsed data schema.
The URL to fetch the schema from
The validated data schema
// Fetch and validate a schema from IPFS or HTTP
const schema = await vana.data.fetchAndValidateSchema("https://example.com/schema.json");
console.log(schema.name, schema.dialect);
// Use the schema to validate user data
if (schema.dialect === "json") {
vana.data.validateDataAgainstSchema(userData, schema);
}
Retrieves a schema by ID and fetches its definition URL to get the full data schema.
The schema ID to retrieve and validate
The validated data schema
Manages encrypted user data files and their blockchain registration on the Vana network.
Remarks
This controller handles the complete file lifecycle from encrypted upload to blockchain registration and decryption. It provides methods for querying user files, uploading new encrypted content, managing file schemas, and handling permissions for secure data sharing. All operations respect the user's privacy through client-side encryption before any data leaves the user's device.
The controller integrates with multiple storage providers (IPFS, Pinata, Google Drive) and supports both gasless transactions via relayers and direct blockchain interaction. File metadata and access permissions are stored on the Vana blockchain while encrypted file content is stored on decentralized storage networks.
Example
See
[URL_PLACEHOLDER] | Vana Data Registry Documentation for conceptual overview