# Create Account

The following example shows how to create and account with keyring.

/* eslint-disable @typescript-eslint/require-await */
/* eslint-disable @typescript-eslint/unbound-method */
/* eslint-disable @typescript-eslint/no-var-requires */
// Import Keyring class and utility function
const Keyring = require('@polkadot/keyring').default;
const stringToU8a = require('@polkadot/util/string/toU8a').default;

async function main () {
  // Create account seed for Alice
  const ALICE_SEED = 'Alice'.padEnd(32, ' ');

  // Create an instance of the Keyring
  const keyring = new Keyring();

  // Create pair and add Alice to keyring pair dictionary (with account seed)
  const pairAlice = keyring.addFromSeed(stringToU8a(ALICE_SEED));

  console.log(`Created keyring pair for Alice with address: ${keyring.getPair(pairAlice.address).address}`);
}

main().catch(console.error).finally(() => process.exit());
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21