💻
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

RAILGUN Wallets

PreviousPrivate WalletsNextView-Only Wallets

Last updated 1 year ago

RAILGUN Wallets are created using an and mnemonic. They will be encrypted and stored into the LevelDOWN database, which you initialized in section.

Wallets must be generated using a 12- or 24- word mnemonic. In order to add a RAILGUN wallet to the local database, you can either import using a previously generated mnemonic or create a new mnemonic using ethers.js.

Example: Generate mnemonic using

import { Mnemonic, randomBytes } from 'ethers';

const mnemonic = Mnemonic.fromEntropy(randomBytes(16)).phrase.trim();

You may provide an optional creationBlockNumberMap which contains the block numbers for each chain when the wallet was created. This mapping will optimize private balance scans, especially for newly created wallets.

Example: Create local RAILGUN Wallet from mnemonic

import { createRailgunWallet } from '@railgun-community/wallet';
import { NetworkName } from '@railgun-community/shared-models';

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

const mnemonic = ...; // Either provided by user or generated with ethers.js

// Block numbers for each chain when wallet was first created.
// If unknown, provide undefined.
const creationBlockNumberMap: MapType<number> = {
    [NetworkName.Ethereum]: 15725700,
    [NetworkName.Polygon]: 3421400,
}

const railgunWalletInfo = await createRailgunWallet(
    encryptionKey, 
    mnemonic, 
    creationBlockNumberMap,
);
const id = railgunWalletInfo.id; // Store this value.

// railgunWalletInfo contains other useful information, like the wallet's RAILGUN address, i.e. '0zk987...654'

After Railgun Wallets are loaded into the local DB for the first time using createRailgunWallet, You will want to store the field railgunWallet.id and reuse the encryptionKey in order to load it again. On subsequent launches of your dApp, instead of calling createRailgunWallet again, you must use the loadWalletByID function to instantly reload the Railgun Wallet. The railgunWallet.id field will additionally be used to reference the wallet when scanning balances, requesting transaction history, or creating new transactions.

Example: Load stored RAILGUN Wallet from ID

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

const encryptionKey = ...; // See `Encryption Keys` section
const id = ...; // Previously stored when local RAILGUN wallet was created
const railgunWalletInfo = await loadWalletByID(encryptionKey, id);
encryption key
Step 1 of the Getting Started
ethers.js