Ga naar de hoofdinhoud

How to Generate a New Ethereum Address in JavaScript

Bijgewerkt op
26 november 2025

Leestijd: 4 min.

Overzicht

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.

Vereisten

  • NodeJS is op uw systeem geïnstalleerd.
  • Een teksteditor
  • Terminal, ook wel bekend als de opdrachtregel

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
  • Transacties ondertekenen/verzenden
  • Verbinding maken met gedecentraliseerde applicaties

How an Ethereum address is generated:

Eerst wordt een willekeurige privésleutel van 64 (hex) tekens (256 bits / 32 bytes) gegenereerd. Bijvoorbeeld: 

0xf4a2b939592564feb35ab10a8e04f6f2fe0943579fb3c9c33505298978b74893

 Vervolgens wordt met behulp van het Elliptic Curve Digital Signature Algorithm (ECDSA) een openbare sleutel van 128 (hex) tekens (64 bytes) afgeleid uit de gegenereerde privésleutel. Bijvoorbeeld: 

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

Opmerking: 0x in de code geeft aan dat het getal of de tekenreeks in hexadecimale notatie is geschreven.

Wat is 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

Onze eerste stap is hier om te controleren of Node.js op het systeem is geïnstalleerd. Kopieer en plak hiervoor het volgende in je terminal/cmd:

$ node -v

Als het nog niet is geïnstalleerd, kun je de LTS-versie van NodeJS downloaden vanaf de officiële website.

Als Node.js correct is geïnstalleerd, gaan we de Ethers.js -bibliotheek (versie 6) toevoegen met behulp van npm (Node Package Manager, een onderdeel van Node.js).

$ npm i ethers

Het meest voorkomende probleem bij deze stap is een interne fout in `node-gyp`. Je kunt hier de installatie-instructies voor node-gyp volgen.

Opmerking: Als je het node-gyp-probleem tegenkomt, moet je ervoor zorgen dat je Python-versie overeenkomt met een van de compatibele versies die in de bovenstaande instructies worden vermeld. 

Een ander veelvoorkomend probleem is een verouderde cache; wis je npm-cache door de volgende opdracht in te voeren:

$ 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 ethers = require('ethers');  
var crypto = require('crypto');

var id = crypto.randomBytes(32).toString('hex');
var privateKey = "0x"+id;
console.log("BEWAAR DIT, MAAR DEEL HET NIET:", privateKey);

var wallet = new ethers.Portemonnee(privateKey);
console.log("Adres: " + portemonnee.adres);

Uitleg bij de bovenstaande code

Regel 1-2: De ethers-bibliotheek en de crypto-module die bij Node.js worden geleverd, importeren

Regel 4: Een willekeurige hexadecimale tekenreeks van 32 bytes genereren met behulp van het crypto-object en deze opslaan in de variabele id.

Regel 4: Het voorvoegsel ‘0x’ toevoegen aan de tekenreeks in id en de nieuwe tekenreeks opslaan in een variabele met de naam privateKey.

Regel 6: Onze privésleutel afdrukken met een waarschuwing.

Regel 8: Een nieuwe wallet aanmaken met behulp van de privateKey en deze opslaan in de variabele wallet.

Regel 9: Het adres van de zojuist aangemaakte wallet afdrukken met het bericht „Adres:“

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.

Conclusie

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 :)

Deel deze gids