Creating a wallet

How to set up a new wallet.

Background

A wallet enables you to store your account to sign transactions, encrypting your private key with a password.

Prerequisites

Method #01: Using the SDK

If the programming language of the SDK you are using allows client-side development, you will be able to create a wallet.

Open a new file and run the following code snippet to create a new wallet.

const password = new Password('password');

const wallet = SimpleWallet.create('wallet-name', password, NetworkType.MIJIN_TEST);

const account = wallet.open(password);

console.log('Your new account address is:', account.address.pretty(), 'and its private key', account.privateKey);
const password = new nem2_sdk_1.Password('password');
const wallet = nem2_sdk_1.SimpleWallet.create('wallet-name', password, nem2_sdk_1.NetworkType.MIJIN_TEST);
const account = wallet.open(password);
console.log('Your new account address is:', account.address.pretty(), 'and its private key', account.privateKey);
nem2-cli account generate --network MIJIN_TEST --save --url http://localhost:3000 --profile test

If you already have a private key, you can use it to define a new SimpleWallet object.

const password = new Password('password');
const privateKey = process.env.PRIVATE_KEY as string;
const wallet = SimpleWallet.createFromPrivateKey('wallet-name', password, privateKey, NetworkType.MIJIN_TEST);
const account = wallet.open(password);

console.log('Your account address is:', account.address.pretty(), 'and its private key', account.privateKey);
const password = new nem2_sdk_1.Password('password');
const privateKey = process.env.PRIVATE_KEY;
const wallet = nem2_sdk_1.SimpleWallet.createFromPrivateKey('wallet-name', password, privateKey, nem2_sdk_1.NetworkType.MIJIN_TEST);
const account = wallet.open(password);
console.log('Your account address is:', account.address.pretty(), 'and its private key', account.privateKey);

Method #02: Using the CLI

In NEM2-CLI, wallets are named profiles.

Note

Use NEM2-CLI only for testing and development purposes, as the private keys stored are not encrypted.

Create a new wallet with the following command:

nem2-cli account generate --network MIJIN_TEST --save --url http://localhost:3000 --profile test

If you already have a private key, you can store it as a profile.

nem2-cli profile create --private-key your_private_key --network MIJIN_TEST --url http://localhost:3000 --profile test