Skip to content

Instantly share code, notes, and snippets.

@tur-nr
Last active July 30, 2021 23:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tur-nr/fd7b76d7bd172a020b14fbe36aff99b3 to your computer and use it in GitHub Desktop.
Save tur-nr/fd7b76d7bd172a020b14fbe36aff99b3 to your computer and use it in GitHub Desktop.
Ethereum Vanity Address

Ethereum Vanity Address

Usage

Step 1 (installation)

$ npm install

Step 2 (prefx/suffix)

Change your prefix/suffix. Keep them 4 chars long so that wallets and dapps will display it like so: 0x1234...abcd.

// ./vanity.js

const PREFIX = '0000';
const SUFFIX = '0000';

Step 3 (close everything)

No seriously quit as many applications as you can, this is kinda intense on the CPU. Or you can change the THREAD_COUNT.

Step 4 (generate)

$ npm run start

Kudos

https://github.com/bokub/vanity-eth

{
"name": "vanity-address",
"main": "vanity.js",
"private": true,
"scripts": {
"start": "node vanity.js"
},
"dependencies": {
"keccak": "^3.0.1",
"randombytes": "^2.0.6",
"secp256k1": "^3.8.0"
}
}
const { Worker, isMainThread, parentPort } = require('worker_threads');
const { cpus } = require('os');
const THREAD_COUNT = cpus().length;
const PREFIX = '0000';
const SUFFIX = '0000';
if (isMainThread) {
console.log(' - threads: %s', THREAD_COUNT);
console.log(' - prefix: ', PREFIX);
console.log(' - suffix: ', SUFFIX);
process.stdout.write(' - generated: 0');
let i = 0;
const to = setInterval(() => {
process.stdout.clearLine();
process.stdout.cursorTo(0);
process.stdout.write(' - generated: ' + Number(i).toLocaleString());
}, 1000);
const workers = [];
for (let t = 0; t < THREAD_COUNT; t++) {
const worker = new Worker(__filename);
worker.on('message', (event) => {
if (!event) {
i++;
return;
}
clearInterval(to);
process.stdout.write('\n');
console.log(' - private: ', event.privateKey);
console.log(' - address: ', event.address);
});
worker.on('exit', () => {
process.exit();
});
workers.push(workers);
}
} else {
const secp256k1 = require('secp256k1');
const keccak = require('keccak');
const randomBytes = require('randombytes');
do {
const rand = randomBytes(32);
const privateKey = rand.toString('hex');
const publicKey = secp256k1.publicKeyCreate(rand, false).slice(1);
const address = keccak('keccak256').update(publicKey).digest().slice(-20).toString('hex');
const prefix = address.slice(0, PREFIX.length);
const suffix = address.slice(-1 * SUFFIX.length);
if (prefix == PREFIX && suffix == SUFFIX) {
return parentPort.postMessage({
privateKey,
address: '0x' + address,
});
}
parentPort.postMessage(null);
} while (1);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment