How to create a new Eth paper wallet?

OnTokens
4 min readOct 22, 2022

--

Wat is a wallet? kekw

A paper wallet is a piece of paper with your keys printed out on it. When you choose to print your keys, they are generally removed from your digital wallet and the network. No one can hack your paper wallet or retrieve your keys unless they physically take the paper on which you have them stored.

What is ECDSA?

Asymmetric cryptography is one of the most important computer science inventions of the previous century. It also lies at the heart of all blockchain technology. In this post we’ll take a deeper look at how Ethereum uses the Elliptic Curve Digital Signature Algorithm (ECDSA) to validate the origin and integrity of messages.

Encryption techniques like ECDSA are also essential in securely extending existing blockchains. We’ve seen this in my past post analyzing decentralized exchanges where a DEX uses signatures in it’s offchain communication. As the blockchain ecosystem matures I expect we will see more Layer-2 and Layer-3 extensions of the existing low level blockchain infrastructure.

Private Keys and Public Keys

In Ethereum like any other blockchain system there is a private and a public key. These keys are generated when you create a new blockchain “account”. Keeping the private key secure is essential because any copy of it allows access to the ledger. Hardware wallets to securely store the private key have become an essential best practice.

The notion of an account is a bit of a misnomer, because in strict technical terms there are only keys and a ledger of funds that correspond with those keys. An Ethereum or Bitcoin address is essentially a hashed version of the public key.

ECDSA

Elliptic Curve Cryptography (ECC) and ECDSA are a specific flavor of asymmetric cryptography. They are widely used in blockchain technology because of three reasons:

  • Their computational performance is economical compared to a lot of other algorithms
  • The keys that are generated are relatively short
  • Bitcoin started it, so most new blockchain projects have copied it

ECDSA uses the algebraic structure of elliptic curves over finite fields. Without getting into the mathematics of it, they require a set of constants to define this curve. The constants used by most blockchains are set in the secp256k1 standard.

Example shape of an Elliptic Curve

Before blockchain, this elliptic curve standard was not common at all. In fact, most mainstream hardware vendors don’t support hardware encryption for this curve. It is rumored that secp256k1 was picked because it has the least likelihood of having kleptographic backdoors implanted by the NSA.

What 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

Our first step here will be to check if node.js is installed on the system. To do so, copy-paste the following in your terminal/cmd:

node -v

If not installed, you can download the LTS version of NodeJS from the official website.

If node.js is properly installed, let’s add the ethers.js library using npm (Node Package Manager, a part of node.js).

$ npm i ethers

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(“KEEP IT SECRET.. KEEP IT SAFE:”, privateKey);

var wallet = new ethers.Wallet(privateKey);
console.log(“Address: “ + wallet.address);

Explanation of the code above

Line 1–2: Importing ethers library and crypto module that comes with node.js

Line 4: Generating a random 32 bytes hexadecimal string using the crypto object and storing it in the id variable.

Line 4: Adding ‘0x’ prefix to the string in id and storing the new string in a variable called privateKey.

Line 6: Printing our private key with a warning.

Line 8: Creating a new wallet using the privateKey and storing it in the wallet variable.

Line 9: Printing the address of the newly created wallet with a message “Address:”

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.

KEEP IT SECRET.. KEEP IT SAFE:

Private key: 0xbe28edd400e2a9ecdca66d8c78b9f6f849e37cdb8652a042c7623988

Public key: 0x4139B7421A11E1627434c1A5c0415Ad64073AB3b

You can then check your cold wallet from etherscan without even connecting it:

https://etherscan.io/address/0x4139B7421A11E1627434c1A5c0415Ad64073AB3f

--

--

OnTokens
OnTokens

Written by OnTokens

We empower people with Web3 technology and push the frontiers of technological possibilities. 🧪

No responses yet