💻
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. Getting Started

3. Load a Groth16 prover for each platform

Previous2. Build a persistent store for artifact downloadsNext4. Add networks and RPC providers

Last updated 10 months ago

Once the RAILGUN Engine is initialized, you will set a Groth16 Prover.

NOTE: A Prover is only necessary for applications that intend to generate proofs, which are necessary to send private transactions (private transfers, private cross-contract calls, and unshielding). Shield-only applications can safely skip this step.

There is a distinct Groth16 prover for node/browser (snarkjs) and a different prover for mobile (native prover). Both provers generate Groth16 snarks using different assembly processes that are compatible with different platforms.

  1. Node.js and browser uses a web assembly implementation: .

  2. Mobile apps use a C++ implementation: .

Example: Minified SnarkJS (browser)

  1. Get from the Wallet SDK repo.

  2. Load script in your app's index.html: <script src="./snarkjs.min.js"></script>

// main.ts
...
import {
  ...
  getProver,
  Groth16
} from '@railgun-community/wallet';

// App launch
try {
  initializeEngine(); // Defined in Step 1
  ...
  // Note: SnarkJS library does not have proper typings.
  const groth16 = (global as unknown as { snarkjs: { groth16: SnarkJSGroth16 } })
        .snarkjs.groth16;
        
  getProver().setSnarkJSGroth16(groth16);
} catch (err) {
  // Handle err
}

Example: SnarkJS NPM (node.js)

Install with yarn add snarkjs

// main.js
...
import {
  ...
  getProver,
  Groth16
} from '@railgun-community/wallet';
import { groth16 } from 'snarkjs';

// App launch
try {
  initializeEngine(); // Defined in Step 1
  ...
  // Note: SnarkJS library does not have proper typings.
  getProver().setSnarkJSGroth16(groth16 as SnarkJSGroth16);
} catch (err) {
  // Handle err
}

Example: Native Prover (mobile)

Install with yarn add @railgun-community/native-prover

// main.js
...
import {
  ...
  getProver
} from '@railgun-community/wallet';
import { nativeProve, CIRCUITS } from '@railgun-community/native-prover';

// App launch
try {
  initializeEngine(); // Defined in Step 1
  ...
  getProver().setNativeProverGroth16(nativeProve, CIRCUITS);
} catch (err) {
  // Handle err
}
snarkjs
@railgun-community/native-prover
snarkjs.min.js file