RAILGUN Wallets
RAILGUN Wallets must be generated using a 12- or 24- word mnemonic.
In order to create a new RAILGUN wallet, you may first generate a mnemonic using ethers.js.
import { entropyToMnemonic, randomBytes } from 'ethers/lib/utils';
const mnemonic = entropyToMnemonic(randomBytes(16));
RAILGUN Wallets are created using an encryption key and mnemonic. They will be encrypted and stored into the LevelDOWN database, which you initialized in Start Railgun Engine.
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. import { createRailgunWallet } from '@railgun-community/wallet';
// Current 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;
After first load, Railgun Wallets can be reloaded instantly using function
loadWalletByID
. You will want to store the field railgunWallet.id
and the encryptionKey
in order to load it again. The railgunWallet.id
field will be used to reference the wallet when scanning balances, requesting transaction history, or creating new transactions.import { loadWalletByID } from '@railgun-community/wallet';
const railgunWalletInfo = await loadWalletByID(encryptionKey, id);
Last modified 3mo ago