Vana SDK - v0.1.0
    Preparing search index...

    Class VanaCore

    Provides the core SDK functionality for interacting with the Vana network.

    This environment-agnostic class contains all SDK logic and accepts a platform adapter to handle environment-specific operations. It initializes all controllers and manages shared context between them.

    The class uses TypeScript overloading to enforce storage requirements at compile time. When storage is required for certain operations, the constructor will fail fast at runtime.

    For public usage, use the platform-specific Vana classes that extend this core:

    • Use Vana({config) from the main package import
    // Direct instantiation (typically used internally)
    const core = new VanaCore({
    walletClient: myWalletClient,
    }, platformAdapter);

    Hierarchy (View Summary)

    Index

    Constructors

    • Initializes a new VanaCore client instance with the provided configuration.

      Parameters

      • platform: VanaPlatformAdapter

        The platform adapter for environment-specific operations

      • config: VanaConfig

        The configuration object specifying wallet or chain settings

      Returns VanaCore

      The constructor validates the configuration, initializes storage providers if configured, creates wallet and public clients, and sets up all SDK controllers with shared context.

      IMPORTANT: This constructor will validate storage requirements at runtime to fail fast. Methods that require storage will throw runtime errors if storage is not configured.

      When the configuration is invalid or incomplete

      // Direct instantiation (consider using factory methods instead)
      const vanaCore = new VanaCore(platformAdapter, {
      walletClient: myWalletClient,
      });

    Properties

    Manages gasless data access permissions and trusted server registry.

    Handles user data file operations.

    Manages data schemas and refiners.

    Provides personal server setup and trusted server interactions.

    Offers low-level access to Vana protocol smart contracts.

    Accessors

    • get chainId(): number

      Gets the current chain ID from the wallet client.

      Returns number

      The numeric chain ID of the connected network

      const chainId = vana.chainId;
      console.log(`Connected to chain: ${chainId}`); // e.g., "Connected to chain: 14800"
    • get chainName(): string

      Gets the current chain name from the wallet client.

      Returns string

      The human-readable name of the connected network

      const chainName = vana.chainName;
      console.log(`Connected to: ${chainName}`); // e.g., "Connected to: Moksha Testnet"

    Methods

    • Validates that storage is available for storage-dependent operations. This method enforces the fail-fast principle by checking storage availability at method call time rather than during expensive operations.

      Returns void

      When storage is required but not configured

      // This will throw if storage is not configured
      vana.validateStorageRequired();
      await vana.data.uploadFile(file); // Safe to proceed
    • Checks whether storage is configured without throwing an error.

      Returns boolean

      True if storage is properly configured

      if (vana.hasStorage()) {
      await vana.data.uploadFile(file);
      } else {
      console.warn('Storage not configured - using pre-stored URLs only');
      }
    • Type guard to check if this instance has storage enabled at compile time. Use this when you need TypeScript to understand that storage is available.

      Returns this is VanaCore & StorageRequiredMarker

      True if storage is configured, with type narrowing

      if (vana.isStorageEnabled()) {
      // TypeScript knows storage is available here
      await vana.data.uploadFile(file);
      }
    • Retrieves the user's wallet address from the connected client.

      Returns Promise<`0x${string}`>

      A Promise that resolves to the user's Ethereum address

      const address = await vana.getUserAddress();
      console.log(`User address: ${address}`); // e.g., "User address: 0x742d35..."
    • Retrieves comprehensive runtime configuration information.

      Returns RuntimeConfig

      The current runtime configuration including chain, storage, and relayer settings

      const config = vana.getConfig();
      console.log(`Chain: ${config.chainName} (${config.chainId})`);
      console.log(`Storage providers: ${config.storageProviders.join(", ")}`);
    • Sets the platform adapter for environment-specific operations. This is useful for testing and advanced use cases where you need to override the default platform detection.

      Parameters

      Returns void

      // For testing with a mock adapter
      const mockAdapter = new MockPlatformAdapter();
      vana.setPlatformAdapter(mockAdapter);

      // For advanced use cases with custom adapters
      const customAdapter = new CustomPlatformAdapter();
      vana.setPlatformAdapter(customAdapter);
    • Gets the current platform adapter. This is useful for advanced use cases where you need to access the platform adapter directly.

      Returns VanaPlatformAdapter

      The current platform adapter

      const adapter = vana.getPlatformAdapter();
      const encrypted = await adapter.encrypt(data, key);
    • Encrypts data using the Vana protocol standard encryption. This method automatically uses the correct platform adapter for the current environment.

      Parameters

      • data: string | Blob

        The data to encrypt (string or Blob)

      • key: string

        The key to use as encryption key

      Returns Promise<Blob>

      The encrypted data as Blob

      const encryptionKey = await generateEncryptionKey(walletClient);
      const encrypted = await vana.encryptBlob("sensitive data", encryptionKey);
    • Decrypts data that was encrypted using the Vana protocol. This method automatically uses the correct platform adapter for the current environment.

      Parameters

      • encryptedData: string | Blob

        The encrypted data (string or Blob)

      • walletSignature: string

        The wallet signature to use as decryption key

      Returns Promise<Blob>

      The decrypted data as Blob

      const encryptionKey = await generateEncryptionKey(walletClient);
      const decrypted = await vana.decryptBlob(encryptedData, encryptionKey);
      const text = await decrypted.text();