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.js

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(
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);

Last updated