Skip to main content
This guide shows how to generate and manage EVM-compatible wallet addresses with ethers.js, in JavaScript or TypeScript. Use it when your dApp or backend has to provision a wallet per user, or when you hand wallet management to a service such as Particle Network.

Prerequisites

  • You can write and run JavaScript in a Node.js environment and install npm packages.
  • ethers.js is a dependency in your project.
  • If you use Particle Network or a similar platform, you have its SDK and know how to authenticate against it.
  • You have a way to store private keys: an environment variable manager, a hardware security module (HSM) or a secret management service.

Instructions

1. Generating a New Wallet Address

Wallet.createRandom() generates a new address and its private key:
wallet.address is the public address. wallet.privateKey is the secret: anyone holding it controls the funds, so it must never be logged in production or sent to the client. createRandom() draws its entropy from a cryptographically secure RNG.

2. Encrypting and Storing Wallets

Encrypt the wallet with a password before you store it:
encrypt returns a JSON Keystore V3 string. Store that string, not the raw key, and keep the password itself in a secret manager such as AWS KMS, GCP KMS or Vault.

3. Restoring an Existing Wallet

Decrypt the stored keystore with the same password:
fromEncryptedJson returns a working Wallet instance you can use to send transactions, sign messages or read the address.

4. Integrating with Particle Network or Other Services

If you manage wallets for many users behind an authentication service such as Particle Network, the pattern is: authenticate the user, create the wallet on registration, store the encrypted keystore against that user, and send transactions with wallet.sendTransaction or wallet.signTransaction. Example integration logic (pseudo-code):
Handle private keys and keystores server side only. Put role-based access control in front of the store, and never send a raw private key to the client.

Summary

Managing EVM wallets with ethers.js comes down to three steps: generate the wallet, encrypt and store the key, restore it when you need to sign. Combine that with a secret manager, and an authentication service if you provision wallets per user.