Skip to content

feat(adapter-midnight): Auto-generate Private State ID for improved UX #263

@pasevin

Description

@pasevin

Summary

When loading a Midnight contract, users are currently required to manually input a Private State ID - a field that most users don't understand and shouldn't need to worry about. This creates unnecessary friction in the onboarding flow.

Problem

  • Users ask: "What should I put in the Private State ID field?"
  • The field is an implementation detail that doesn't provide value to end users
  • Manual input increases cognitive load and potential for errors

Proposed Solution

Auto-generate the Private State ID deterministically based on the contract address and wallet address:

// Generate a deterministic ID from contract + wallet
const privateStateId = generateDeterministicId(contractAddress, walletAddress);
// e.g., hash or concatenation like: `${contractAddress}_${walletAddress.slice(-8)}`

Benefits

  1. Reduced cognitive load - Users don't need to understand this implementation detail
  2. Fewer errors - No typos, no accidentally reusing IDs
  3. Smoother onboarding - One less required field
  4. Automatic state restoration - Same user + same contract = same private state (deterministic)

Implementation Notes

  • Remove privateStateId from getContractDefinitionInputs() in the Midnight adapter
  • Generate the ID internally when loading/interacting with contracts
  • The ID should be deterministic so private state is automatically restored across sessions
  • Consider displaying the generated ID in the contract info panel for transparency

Files to Modify

  • packages/adapter-midnight/src/adapter.ts - Remove field from getContractDefinitionInputs()
  • Transaction/contract loading logic - Add deterministic ID generation

Context

This improvement was identified from user feedback asking what to put in the Private State ID field.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestmidnightMidnight Ecosystem Related Issues

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions