Skip to main content

Creating Wallets

How to create wallets using the CLI or programmatically

Although wallets are commonly created through the MultiversX Web Wallet or the MultiversX Ledger App, one can also use the CLI or the SDK.

Generate a new mnemonic

Using mxjs-wallet, a mnemonic phrase (24 words) can be generated as follows:

mxjs-wallet new-mnemonic --mnemonic-file=mnemonicOfAlice.txt

Programmatically using sdk-core, the same can be achieved through:

import { Mnemonic } from "@multiversx/sdk-core/mnemonic";

let mnemonic = Mnemonic.generate();
let words = mnemonic.getWords();
console.log(words);

Deriving a JSON key-file (from mnemonic)

Using mxjs-wallet, a JSON key-file can be obtained as follows:

mxjs-wallet derive-key --mnemonic-file=mnemonicOfAlice.txt \
--account-index=0 \
--key-file=keyOfAlice.json --password-file=passwordOfAlice.txt

Programmatically using sdk-core, the same can be achieved through:

const mnemonic = Mnemonic.generate();
const password = "insert a password here";
const addressIndex = 0;

const secretKey = mnemonic.deriveKey(addressIndex);
const userWallet = UserWallet.fromSecretKey({ secretKey, password });
const jsonFileContent = userWallet.toJSON();

fs.writeFileSync("myKeyFile.json", JSON.stringify(jsonFileContent));