💻
Developer Guide
  • Wallet SDK
    • Wallet Overview
    • Getting Started
      • 1. Start the RAILGUN Privacy Engine
      • 2. Build a persistent store for artifact downloads
      • 3. Load a Groth16 prover for each platform
      • 4. Add networks and RPC providers
      • 5. Set up a debug logger
    • Private Wallets
      • RAILGUN Wallets
      • View-Only Wallets
      • Encryption Keys
    • Private Balances
      • Balance and Sync Callbacks
      • Updating Balances
      • QuickSync
    • Transactions
      • Shielding
        • Shield ERC-20 tokens
        • Shield base token
        • Shield NFTs
      • Private Transfers
        • Private ERC-20 Transfers
        • Private NFT Transfers
      • Cross-Contract Calls
      • Unshielding
        • Unshield ERC-20 tokens
        • Unshield base token
        • Unshield NFTs
      • UX: Private Transactions
    • Broadcasters
  • Cookbook SDK
    • Cookbook Overview
    • Recipe Guide: Write a zkApp
      • "Step" — A smart contract call
      • "Recipe" — Steps in series
      • "Combo Meal" — 2+ Recipes
    • Use your zkApp privately
  • Engine SDK
    • Engine Overview
  • ZK Account Abstraction
    • Account Abstraction Overview
    • Getting started with the contracts
    • Wallets
    • State Structure
    • Example Primitives
Powered by GitBook
On this page
  1. Wallet SDK
  2. Private Wallets

View-Only Wallets

PreviousRAILGUN WalletsNextEncryption Keys

Last updated 10 months ago

(created with mnemonic) have both spending and viewing keys. View-Only wallets lack the spending key, so they cannot create transactions, but they have access to the wallet viewing key that can access balances and transaction history.

View-Only wallets are created using a shareable viewing key. Only the original wallet owner, who has access to the RAILGUN Wallet (and mnemonic) can generate a shareable key.

Example: Generate shareable key and associated View-Only wallet

import { 
    getWalletShareableViewingKey, 
    createViewOnlyRailgunWallet, 
} from '@railgun-community/wallet';

const encryptionKey = ...; // See `Encryption Keys` section

const railgunWalletID = ...; // Stored after RAILGUN wallet creation

const shareableViewingKey = await getWalletShareableViewingKey(railgunWalletID);

// Current block numbers for each chain when wallet was first created.
// If unknown, provide undefined.
const creationBlockNumberMap: Optional<MapType<number>> = undefined;

const viewOnlyWalletInfo = await createViewOnlyRailgunWallet(
  encryptionKey, 
  shareableViewingKey,
  creationBlockNumberMap,
);
const id = viewOnlyWalletInfo.id;

View-Only wallets may be loaded like RAILGUN Wallets, using loadWalletByID.

Example: Load stored RAILGUN Wallet by its ID

import { loadWalletByID } from '@railgun-community/quickstart';

const encryptionKey = ...; // See `Encryption Keys` section
const id = ...; // Previously stored when local RAILGUN wallet was created
const viewOnlyWalletInfo = await loadWalletByID(
  encryptionKey, 
  id, 
  true, // isViewOnlyWallet
);
RAILGUN Wallets