RAILGUN Wallets

RAILGUN Wallets are created using an encryption key and mnemonic. They will be encrypted and stored into the LevelDOWN database, which you initialized in Step 1 of the Getting Started 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 ethers.jsarrow-up-right

import { Mnemonic, randomBytes } from "ethers";

/**
 * Creates a new mnemonic phrase using 16 bytes of entropy.
 *
 * A mnemonic phrase is a human-readable representation of a cryptographic seed,
 * typically used to derive private keys in cryptocurrency wallets.
 *
 * @returns A string containing the mnemonic phrase with trimmed whitespace
 * @example
 * const mnemonic = createMnemonic();
 * // mnemonic = "word1 word2 word3 ... word12"
 */
export const createMnemonic = (): string => {
  const mnemonic = Mnemonic.fromEntropy(randomBytes(16)).phrase.trim();
  return mnemonic;
};

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

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

Last updated