Passer au contenu principal

How to Generate a New Ethereum Address in JavaScript

Mis à jour le
26 novembre 2025

4 min de lecture

Aperçu

When it comes to programming, there’s hardly anyone who has not used or heard about JavaScript. JavaScript was initially created for client-side scripting but has become a full-featured Object-Oriented and procedural language widely used for client and server applications today. JavaScript’s syntax borrows from Java and C++, and it is based on the ECMAScript specification. With over 1,444,231 libraries and counting, JavaScript today is practically used everywhere, including making dApps (Decentralized Applications) on Ethereum. In this guide, we will cover creating an Ethereum address in JavaScript using Ethers.js.

Prérequis

  • Node.js est installé sur votre système.
  • Un éditeur de texte
  • Terminal, également appelé « ligne de commande »

What is an Ethereum address?

While signing in to any platform on the internet, you need to authenticate using a combination of credentials. Consider an Ethereum address as your username and a corresponding private key as the password. While your Ethereum address is public and can be shared, the private key must always be kept secret. Using this combination lets you interact with the Ethereum blockchain. An Ethereum address is your identity on the blockchain, and it looks like this “0x6E0d01A76C3Cf4288372a29124A26D4353EE51BE”. Having a valid Ethereum address is required for:


  • Receiving/Sending Ethereum currency
  • Signature/Envoi de transactions
  • Connexion aux applications décentralisées

How an Ethereum address is generated:

On commence par générer une clé privée aléatoire de 64 caractères (hexadécimaux) (256 bits / 32 octets). Par exemple : 

0xf4a2b939592564feb35ab10a8e04f6f2fe0943579fb3c9c33505298978b74893

 Une clé publique de 128 caractères (hexadécimaux) (64 octets) est ensuite dérivée de la clé privée générée à l'aide de l'algorithme de signature numérique à courbe elliptique (ECDSA). Par exemple : 

0x04345f1a86ebf24a6dbeff80f6a2a574d46efaa3ad3988de94aa68b695f09db9ddca37439f99548da0a1fe4acf4721a945a599a5d789c18a06b20349e803fdbbe3

The Keccak-256 hash function is then applied to (128 characters / 64 bytes) the public key to obtain a 64 character (32 bytes) hash string. The last 40 characters / 20 bytes of this string prefixed with 0x become the final Ethereum address.  For example:

0xd5e099c71b797516c10ed0f0d895f429c2781142

Remarque: dans la notation binaire, « 0x » indique que le nombre ou la chaîne de caractères est exprimé en hexadécimal.

Qu'est-ce qu'Ethers.js ?

Ethers.js is a lightweight alternative to Web3.js, which is the most commonly used Ethereum library today. Ethers.js is considered by some to be more stable and less buggy than other libraries and has extensive documentation. This library is also very friendly to beginners. Ethers.js is very well maintained and is preferred over Web3.js by many new developers.

You can learn more about Ethers.js and How to connect to Ethereum network with Ethers.js here.

Generating an Ethereum address in JavaScript

Notre première étape consistera à vérifier si Node.js est installé sur le système. Pour cela, copiez-collez la commande suivante dans votre terminal/cmd :

$ node -v

Si NodeJS n'est pas installé, vous pouvez télécharger la version LTS depuis le site officiel.

Si Node.js est correctement installé, ajoutons la bibliothèque Ethers.js (version 6) à l'aide de npm (Node Package Manager, qui fait partie de Node.js).

$ npm i ethers

Le problème le plus courant à cette étape est une erreur interne liée à `node-gyp`. Vous pouvez suivre les instructions d'installation de node-gyp disponibles ici.

Remarque: si vous rencontrez le problème lié à node-gyp, vous devrez vous assurer que la version de Python que vous utilisez correspond à l'une des versions compatibles répertoriées dans les instructions ci-dessus. 

Un autre problème courant est lié à un cache obsolète ; videz votre cache npm en saisissant la commande suivante :

$ npm cache clean

If Ethers.js is successfully installed, let’s proceed with creating an Ethereum address.

Create a file named address.js, which will be a short script to create a random private key and an Ethereum address from that key, copy-paste the following in your address.js file:

var éthers = require('ethers');  
var crypto = require('crypto');

var id = crypto.randomBytes(32).toString('hex');
var clé_privée = "0x"+id;
console.log("ENREGISTRER MAIS NE PAS PARTAGER CECI :", clé_privée);

var wallet = new ethers.Portefeuille(clé privée);
console.log("Adresse : " + wallet.adresse);

Explication du code ci-dessus

Lignes 1-2 : Importation de la bibliothèque « ethers » et du module « crypto » fournis avec Node.js

Ligne 4 : Génération d'une chaîne hexadécimale aléatoire de 32 octets à l'aide de l'objet « crypto » et stockage de celle-ci dans la variable « id ».

Ligne 4 : Ajout du préfixe « 0x » à la chaîne de caractères contenue dans « id » et enregistrement de la nouvelle chaîne dans une variable nommée « privateKey ».

Ligne 6 : Affichage de notre clé privée accompagné d'un avertissement.

Ligne 8 : Création d'un nouveau portefeuille à l'aide de la clé privée et enregistrement de celle-ci dans la variable « wallet ».

Ligne 9 : Affichage de l'adresse du portefeuille nouvellement créé, accompagnée du message « Adresse : »

Save and run your script to generate a new Ethereum address.

$ node address

If your code executes successfully, the output will look similar to the screenshot below. The first line consists of the private key, and the second line consists of your new Ethereum address.

Conclusion

Your Ethereum address is your identity on the Ethereum network. It is required to interact with the network and perform transactions. To continue learning Ethers.js, check out this guide on How to send an Ethereum transaction using Ethers.js. Get more information on Ethers.js from their official documentation. As you saw, generating a new Ethereum address is quickly done with JavaScript and the latest libraries. The development of dApps on the Ethereum blockchain is supported by a variety of tools that are continuously updated and improved by the fast-growing Ethereum community. Look out for more easy-to-follow guides from Quicknode - your provider of affordable and lightning-fast Ethereum nodes. Learn how to get started with Quicknode and set up your own Ethereum endpoint in minutes.

Subscribe to our newsletter for more articles and guides on Ethereum. If you have any feedback, feel free to reach out to us via Twitter. You can always chat with us on our Discord community server, featuring some of the coolest developers you’ll ever meet :)

Partager ce guide