Creating an account

Set up a new NEM account.

Prerequisites

Getting into some code

Creating an account

Run the following code snippet to create an account.

const account = Account.generateNewAccount(NetworkType.MIJIN_TEST);

console.log('Your new account address is:', account.address.pretty(), 'and its private key', account.privateKey);
const account = Account.generateNewAccount(NetworkType.MIJIN_TEST);

console.log('Your new account address is:', account.address.pretty(), 'and its private key', account.privateKey);
nem2-cli account generate --network MIJIN_TEST

The private key uniquely identifies a NEM account and holds all of its power. It is a priority to make sure it is stored safely somewhere offline and not to share it with anyone.

The public key is cryptographically derived from the private key and safe to be shared. In spite of that, it is preferable to share the address, which contains further information such as network and validity check.

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

const privateKey = process.env.PRIVATE_KEY as string;
const account = Account.createFromPrivateKey(privateKey, NetworkType.MIJIN_TEST);

console.log('Your account address is:', account.address.pretty(), 'and its private key', account.privateKey);
const privateKey = process.env.PRIVATE_KEY;
const account = Account.createFromPrivateKey(privateKey, NetworkType.MIJIN_TEST);

console.log('Your account address is:', account.address.pretty(), 'and its private key', account.privateKey);

Creating a wallet

If the programming language of the SDK you are using allows client-side development, you will be able to create a wallet. A wallet enables you to store your account to sign transactions, encrypting your private key with a password.

Run the following code snippet to create an account.

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 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);
nem2-cli account generate --network MIJIN_TEST --save --url http://localhost:3000 --profile test

Do you have a private key? You can create and open a wallet importing a private key.

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 Password('password');
const privateKey = process.env.PRIVATE_KEY;
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);
nem2-cli profile create --private-key your_private_key --network MIJIN_TEST --url http://localhost:3000 --profile test