Skip to content
This repository was archived by the owner on Dec 10, 2025. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ var cluster = require('cluster')
var numCPUs = require('os').cpus().length
var argv = require('yargs')
.usage('Usage: $0 <command> [options]')
.example('$0 -checksum -i B00B5', 'get a wallet where address matches B00B5 in checksum format')
.example('$0 --checksum -i B00B5', 'get a wallet where address matches B00B5 in checksum format')
.example('$0 --contract -i ABC', 'get a wallet where 0 nonce contract address matches the vanity')
.example('$0 --deployer -i ABC', 'get a wallet where 0 nonce contract of 0 nonce contract address matches the vanity')
.example('$0 -n 25 -i ABC', 'get 25 vanity wallets')
.example('$0 -n 1000', 'get 1000 random wallets')
.alias('i', 'input')
Expand All @@ -21,6 +22,8 @@ var argv = require('yargs')
.describe('n', 'number of wallets')
.boolean('contract')
.describe('contract', 'contract address for contract deployment')
.boolean('deployer')
.describe('deployer', 'contract address for contract deployment')
.alias('l', 'log')
.boolean('l')
.describe('l', 'log output to file')
Expand All @@ -34,6 +37,7 @@ if (cluster.isMaster) {
isChecksum: argv.checksum ? true : false,
numWallets: argv.count ? argv.count : 1,
isContract: argv.contract ? true : false,
isDeployer: argv.deployer ? true : false,
log: argv.log ? true : false,
logFname: argv.log ? 'VanityEth-log-' + Date.now() + '.txt' : ''
}
Expand All @@ -52,7 +56,8 @@ if (cluster.isMaster) {
const worker_env = {
input: args.input,
isChecksum: args.isChecksum,
isContract: args.isContract
isContract: args.isContract,
isDeployer: args.isDeployer
}
proc = cluster.fork(worker_env);
proc.on('message', function(message) {
Expand All @@ -70,7 +75,7 @@ if (cluster.isMaster) {
} else {
const worker_env = process.env;
while (true) {
process.send(VanityEth.getVanityWallet(worker_env.input, worker_env.isChecksum == 'true', worker_env.isContract == 'true'))
process.send(VanityEth.getVanityWallet(worker_env.input, worker_env.isChecksum == 'true', worker_env.isContract == 'true', worker_env.isDeployer == 'true'))
}
}
process.stdin.resume();
Expand Down
17 changes: 12 additions & 5 deletions libs/VanityEth.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,15 @@ var isValidHex = function(hex) {
var re = /^[0-9A-F]+$/g;
return re.test(hex);
}
var isValidVanityWallet = function(wallet, input, isChecksum, isContract) {
var isValidVanityWallet = function(wallet, input, isChecksum, isContract, isDeployer) {
var _add = wallet.address;
if (isDeployer) {
var _deployerAdd = getDeterministicContractAddress(_add);
var _contractAdd = getDeterministicContractAddress(_deployerAdd, 1);
_contractAdd = isChecksum ? ethUtils.toChecksumAddress(_contractAdd) : _contractAdd;
wallet.contract = _contractAdd;
return _contractAdd.substr(2, input.length) == input
}
if (isContract) {
var _contractAdd = getDeterministicContractAddress(_add);
_contractAdd = isChecksum ? ethUtils.toChecksumAddress(_contractAdd) : _contractAdd;
Expand All @@ -25,16 +32,16 @@ var isValidVanityWallet = function(wallet, input, isChecksum, isContract) {
_add = isChecksum ? ethUtils.toChecksumAddress(_add) : _add;
return _add.substr(2, input.length) == input;
}
var getVanityWallet = function(input = '', isChecksum = false, isContract = false) {
var getVanityWallet = function(input = '', isChecksum = false, isContract = false, isDeployer = false) {
if (!isValidHex(input)) throw new Error(ERRORS.invalidHex);
input = isChecksum ? input : input.toLowerCase();
var _wallet = getRandomWallet();
while (!isValidVanityWallet(_wallet, input, isChecksum, isContract)) _wallet = getRandomWallet(isChecksum);
while (!isValidVanityWallet(_wallet, input, isChecksum, isContract, isDeployer)) _wallet = getRandomWallet(isChecksum);
if (isChecksum) _wallet.address = ethUtils.toChecksumAddress(_wallet.address);
return _wallet;
}
var getDeterministicContractAddress = function(address) {
return '0x' + ethUtils.sha3(ethUtils.rlp.encode([address, 0])).slice(12).toString('hex');
var getDeterministicContractAddress = function(address, nonce = 0) {
return '0x' + ethUtils.sha3(ethUtils.rlp.encode([address, nonce])).slice(12).toString('hex');
}
module.exports = {
getVanityWallet: getVanityWallet,
Expand Down