Web3 by Example: Generating New Wallets

The Wallet can sign transactions and messages using a private key as a standard Externally Owned Account (EOA).

Generate a new Wallet with a random private key, generated from cryptographically secure entropy sources. If the current environment does not have a secure entropy source, an error is thrown.

An Ethereum account has an Ethereum address, like an inbox has an email address. You can use this to send funds to an account.

The mnemonic phrases are used to generate a private key. Most modern cryptocurrency wallets implement Bitcoin Improvement Proposal (BIP) 39.

The private key is a secret number that allows Ethereum users to prove ownership of an account or contracts, by producing a digital signature.

Don't share your mnemonic or private key!

wallet.js

const { ethers } = require("ethers");
(async () => {
const wallet = ethers.Wallet.createRandom();
console.log("address", wallet.address);
console.log("mnemonic", wallet.mnemonic);
console.log("privateKey", wallet.privateKey);
})();

output

➜ node wallet.js
address 0x40A11AFfdC868324E1d6420C08C238165532f0a5
mnemonic {
phrase: 'cousin apart apple final first present ozone process boost sugar they drop',
path: "m/44'/60'/0'/0/0",
locale: 'en'
}
privateKey 0x002084b07c85a69f7eb7cb1d63d59cd03e8c9e4678cf37e15a9fc3ec9bf88df3

Next example: Keystores