Skip to main content

Creating a Web3 Wallet

In order to start your web3 journey, you need to create your wallet first either using MetaMask or using ethers.js. We will talk about creating wallet using MetaMask first and then we will talk about creating wallet using ethers.js.

Creating wallet using MetaMask

Download MetaMask from here

tip

MetaMask is a Chrome extension so you need to have Chrome installed on your computer.

Download MetaMask

Follow the installation instructions and create your wallet using mnemonic words.

danger

Keep in mind that you need to save your mnemonic words somewhere safe. If you lose your mnemonic words, you will lose your wallet and all the funds in it.

Check your MetaMask wallet

After you create your wallet, you should see something like this:

MetaMask wallet

  • part1: This is your network menu. You can change it to any network you want.
  • part2: This is your Wallet address and you can copy it by clicking on the copy icon.
  • part3: This is your balance in Ether.

Creating wallet using ethers.js

Install node.js

note

You can download any version of the node.js, however, we recommand you use the LTS version.

Download node.js

Install node.js and check the installation

Follow the installation instructions and check the installation by running the following command in your terminal:

node -v

Check node.js installation

tip

Extra: By default, node.js comes with npm, a node package manager, for installing node packages. However, you can install other advanced package managers like yarn or pnpm. We will list commands in three different package managers: npm, yarn, and pnpm. You can choose any package manager you want.

Yarn

Yarn package manager

pnpm

pnpm package manager

Create a node package

$

Create a test folder

mkdir test

Change directory to test

cd test

Create a node package

npm init -y
$

Now you have have the following folder structure:

test/
├─ package.json

Install ethers.js

npm install ethers

Now you have have the following folder structure:

test/
├─ node_modules/
├─ package.json

note that node_modules is the folder where all the packages you install are stored. You should add node_modules to your .gitignore file and never commit it to your repository.

Create a wallet

Create a file called index.ts in your root folder and now you will have the follow folder structure:

test/
├─ node_modules/
├─ package.json
├─ index.ts

Run the following command to install ts-node and typescript:

npm install -D ts-node typescript

-D means install dependencies for development

Copy the following code to index.ts:

import { ethers } from "ethers";
const wallet = ethers.Wallet.createRandom();

console.log("Wallet address", wallet.address);
console.log("Wallet private key", wallet.privateKey);
console.log("Wallet mnemonic", wallet.mnemonic);

Run the following command to create your wallet:

npx ts-node index.ts

You should see something like this:

Wallet address 0xa4800c0C5b00DdB4C66090427b55F80CE9Faa331
Wallet private key 0x0e1e3c870367f2baf62c059b6096c8dfb16a904f10ce6883f464500f7fa187a7
Wallet mnemonic {
phrase: 'lonely motor twice ahead menu soap target coach gospel person table hamster',
path: "m/44'/60'/0'/0/0",
locale: 'en'
}
tip

You can download the complete code for this section here

Run the above example in codesandbox

You can need to open the following code in codesandbox in order to see the output:

Output in CodeSandbox codesandbox