-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathinterchained-web3-0x-cli.js
386 lines (383 loc) · 14.9 KB
/
interchained-web3-0x-cli.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
/*
+------------------------------------------------------------------------+
| Interchained | Web3 + 0x + Altcoin | Wallet Utility
| Web3 Account Wrapper for ERC20 & BEP20
| Inspired by Viloid ( github.com/vsec7 )
| Developed by Interchained ( github.com/shopglobal )
+------------------------------------------------------------------------+
| Basic Usage:
| ____________
| Get started with the 0x Wallet Utility by typing the amount of wallets
| you would like to generate, then hit enter. To outpute the wallets to
| files simply type 'yes' and hit enter.
+-----------------------------------------------------------------------------------------------------+
| Official Donation Addresses:
| ____________________________
| LTC: MAtV7sbBnmuf2bxVUPgCprpmJ5xX6euBwe
| BTC: 38jiBKevQHp8zhQpZ42bTvK4QpzzqWkA3K
| DOGE: DTTez7ggKPzDcKuUUTns8VzMrKesZUKMCk
| DASH: XcFVDo2k3XRJwQKQQRgMBfhCEDFANawQ3B
| ETH: 0x59d26980a1cdd75e1c3af516b912a6233aa2f5e4
| USDt: 0x59d26980a1cdd75e1c3af516b912a6233aa2f5e4
| XMR: 85PTaJNpkEEeJao2MNk1sRWTQXLUf1FGjZew8oR8R4cRUrXxFrTexa9GwrjmJD4Pyx6UrjgMQnuMoFNmaBKqxs7PPXVe9oX
+------------------------------------------------------------------------+
*/
//
// Global Variables
// Don't change these unless you know what you're doing.
// Most of the Global Variables are altered below in the
// functions, mainly createWallet/getBalance. Those calls
// switch networks according to wallet/account data.
// Altering variables could break something. DYOR first
// before using any of this software on main net
//
// Utils
const ethutils = require('ethereum-mnemonic-privatekey-utils');
const bip39 = require('bip39');
const { Account } = require('eth-lib/lib');
const rl = require('readline-sync');
const fs = require('fs');
// Web3 integrations
// todo: improve mainnet -> testnet handling
const Web3 = require('web3');
// mainnet BSC
//const bep_web3 = new Web3('https://bsc-dataseed1.binance.org:443');
// testnet BSC
const bep_web3 = new Web3('https://data-seed-prebsc-1-s1.binance.org:8545');
// mainnet ETH
//const erc_web3 = new Web3('https://mainnet.infura.io/v3/3cv97f690f783bfe2b094844d0a9c5ae');
// testnet ETH
const erc_web3 = new Web3('https://rinkeby.infura.io/v3/a24f8ja84fea5fb79c3094eb46842d90');
var entropy = 'cat'; // set randomness to.....cat?
const test_address_default = ''; // dummy address generated for testing
const test_address = (test_address_default != undefined && test_address_default != '0xe5d18be87c0d69112cba1fd8571733dbae788377') ? test_address_default : '0xe5d18be87c0d69112cba1fd8571733dbae788377';
var addr_ = test_address; // address default set to test_address which is itself set by test_address_default variable unless left blank, which defaults to ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^. To alter test_address before the app runs adjust variable test_address_default
var address = (addr_ != undefined && addr_ === test_address_default) ? test_address_default : addr_;
const test_private_key = '0x2e07d5d42b1612377f5f7242579bfaf0dec0cb347ce3a487c964c723acf5bf82';
var pk_ = ''; // used to recover certain wallets based on private key, defaults to ^^^^^^^^^ if left blank. To alter pk_ before the app runs, adjust variable "test_private_key"
var privateKey = (pk_ != undefined && pk_ === test_private_key) ? test_private_key : pk_;
const zero = 0;
var balance = zero;
var erc20_balance = zero;
var bep20_balance = zero;
var test_seed = 'decorate photo client buzz work advice tongue record helmet weird virus panda';
var mnemonic_ = test_seed;
var seed = (mnemonic_ != undefined && mnemonic_ === test_seed) ? test_seed : mnemonic_;
var acc_ = '';
var holder = '';
var bep20_holder = '';
var erc20_holder = '';
var bep20_wallet = {};
var erc20_wallet = {};
var bep20Wallet;
var erc20Wallet;
var bep20 = false;
var erc20 = false;
var bsc = 'BSC';
var eth = 'ETH';
var eth_block = 0;
var bsc_block = 0;
var network = (erc20 == false) ? bsc : eth;
var obj = (network != 'ETH') ? 'BSC' : 'ETH';
var web3_erc20 = new Web3(erc_web3);
var web3_bep20 = new Web3(bep_web3);
var web3;
web3_selector = function (obj,callback){
network = obj;
if(network == 'BSC'){
bsc_block++;
// console.log("web3_selector detected: "+ network);
network = 'BSC';
bep20 = true;
erc20 = false;
web3 = web3_bep20;
web3.eth.getBlockNumber().then((result) => {
// console.log("Interacted with Binance Smart Chain on block: ",result);
});
};
if(network != 'BSC') {
eth_block++;
// console.log("web3_selector detected: "+network);
network = 'ETH';
bep20 = false;
erc20 = true;
web3 = web3_erc20;
web3.eth.getBlockNumber().then((result) => {
// console.log("Interacted with Ethereum on block ",result);
});
// todo: you may want to verify this, but I
// believe web3.eth.disconnect() would be
// void due to a collission caused by a race
// between BSC and ETH networks since we
// are calling multiple connections rapidly.
// Maybe relocate web3.eth.disconnect(). Or,
// don't call web3.eth.disconnect() at all
// Here's the code: web3.eth.disconnect();
};
callback(obj,"success");
}
//
// Assign Properties to Tokens for Users
//
// ERC20 Token Address
function ERC20Address(address,privateKey,balance,mnemonic,account) {
this.address_ = Web3.utils.toChecksumAddress(address);
this.privateKey_ = privateKey;
this.balance_ = JSON.stringify(balance,null," ");
this.mnemonic_ = mnemonic;
this.account_ = JSON.stringify(account);
this.pk_ = privateKey;
console.log(this);
}
//
// BEP20 Token Address
//
function BEP20Address(address,privateKey,balance,mnemonic,account){
this.address = Web3.utils.toChecksumAddress(address);
this.privateKey = privateKey;
this.balance = JSON.stringify(balance,null," ");
this.mnemonic = mnemonic;
this.account = JSON.stringify(account);
this.pk_ = privateKey;
console.log(this);
};
//
// (prototype) Universal TokenAddress (UNI-FORM)
//
function TokenAddress(address,privateKey,balance,mnemonic,account){
this.address = Web3.utils.toChecksumAddress(address);
this.privateKey = privateKey;
this.balance = JSON.stringify(balance,null," ");
this.mnemonic = mnemonic;
this.account = JSON.stringify(account);
this.pk_ = privateKey;
console.log(this);
};
//
// (prototype) Universal User (UNI-FORM)
//
function Web3Account(account,bep20Wallet,erc20Wallet){
// detect (default) preferences based on 'account^'
this.account = JSON.stringify(account);
// (prototype)
// todo, test, if account.address is undefined then set account -> bep20Wallet and (default) inherit bep20 properties
//
// if(!account.address){
// account.network = 'BSC';
// account = bep20Wallet;
// account.address = Web3.utils.toChecksumAddress(bep20Wallet.address);
// account.privateKey = bep20Wallet.privateKey;
// account.balance = JSON.stringify(bep20Wallet.balance);
// account.address = bep20Wallet.mnemonic;
// account.account = JSON.stringify(bep20Wallet.account);
// }
// network (default) preference
if (account.network != 'ETH'){
account.network = 'BSC';
} else {
account.network = 'ETH';
};
// (prototype) account details: email, username, password
// todo, add encryption, maybe replace with Webnero code, refactor, or relocate.
this.email= (account.email != ' ') ? account.email : account.username; ' ';
this.username= (account.username != ' ') ? account.username : account.email;
this.pasword= (account.email != ' ') ? account.pasword : ' ';
// (default) account details: address, private key, mnemonic, and balance
this.address = Web3.utils.toChecksumAddress(account.address);
this.privateKey = (account.privateKey != ' ') ? account.privateKey : ' ';
this.pk_ = account.privateKey;
this.balance = JSON.stringify(account.balance,null," ");
this.mnemonic = account.mnemonic;
// (ethereum) account details: address, private key, mnemonic, and balance
this.eth_account = JSON.stringify(erc20Wallet.account);
this.eth_address = Web3.utils.toChecksumAddress(erc20Wallet.address);
this.eth_privateKey = (erc20Wallet.privateKey != ' ') ? erc20Wallet.privateKey : ' ';
this.eth_balance = JSON.stringify(balance,null," ");
// (binance smart chain) account details: address, private key, mnemonic, and balance
this.bsc_account = JSON.stringify(bep20Wallet.account);
this.bsc_address = Web3.utils.toChecksumAddress(bep20Wallet.address);
this.bsc_privateKey = (bep20Wallet.privateKey != ' ') ? bep20Wallet.privateKey : ' ';
this.bsc_balance = JSON.stringify(balance,null," ");
// log this^ User
console.log(this);
};
//
// (prototype) ERC20 && BEP20 getBalance
// combination simultaneous execution on ETH && BSC
// one call -> return balance(s) from both blockchains
//
BEP20Address.prototype.getBalance = async function(erc20_wallet,erc20Wallet,bep20_wallet,bep20Wallet,network){
erc20_wallet = {
address: Web3.utils.toChecksumAddress(bep20Wallet.vaddress),
privateKey: erc20Wallet.privateKey,
balance: JSON.stringify(erc20Wallet.balance),
mnemonic: erc20Wallet.mnemonic,
account: erc20Wallet.account
};
bep20_wallet = {
address: Web3.utils.toChecksumAddress(bep20Wallet.vaddress),
privateKey: bep20Wallet.privateKey,
balance: JSON.stringify(bep20Wallet.balance),
mnemonic: bep20Wallet.mnemonic,
account: bep20Wallet.account
};
// ETH scan ERC20
network = eth;
var erc20_data;
var erc20_balance;
await web3_selector(network,function(err, res){
erc20_balance = JSON.stringify(web3.eth.getBalance(Web3.utils.toChecksumAddress(erc20Wallet.address)));
erc20Wallet.balance = erc20_balance;
erc20_wallet.balance = erc20_balance;
erc20_data = `Balance: ${erc20Wallet.balance}\nAddress : ${erc20Wallet.address}\nPrivateKey: ${erc20Wallet.privateKey}\nMnemonic: ${erc20Wallet.mnemonic}\n`;
});
// BSC scan BEP20
network = bsc;
var bep20_data;
var bep20_balance;
const bep20_erc20_data = '___________________________' + '\n' + bep20_data + '\n' + '___________________________' + '\n' + erc20_data;
await web3_selector(network,function(err, res){
bep20_balance = JSON.stringify(web3.eth.getBalance(Web3.utils.toChecksumAddress(bep20Wallet.address)));
bep20Wallet.balance = bep20_balance;
bep20_wallet.balance = bep20_balance;
bep20_data = `Balance: ${bep20Wallet.balance}\nAddress : ${bep20Wallet.address}\nPrivateKey: ${bep20Wallet.privateKey}\nMnemonic: ${bep20Wallet.mnemonic}\n`;
});
return bep20_erc20_data;
};
//
// ERC20 Wallet Handling
// check ERC20 account
//
ERC20Address.prototype.getBalance = async function(addr_,pk_,mnemonic_,acc_,erc20Wallet,erc20_wallet){
erc20_wallet = {
address: Web3.utils.toChecksumAddress(addr_),
privateKey: pk_,
balance: 0,
mnemonic: mnemonic_,
account: acc_
}
network = eth;
await web3_selector(network,function(err, res){
const erc20_balance = JSON.stringify(web3.eth.getBalance(Web3.utils.toChecksumAddress(addr_)));
erc20_wallet.balance = erc20_balance;
erc20Wallet.balance = erc20_balance;
erc20_wallet = erc20Wallet;
return erc20Wallet;
});
};
//
// BEP20 Wallet Handling
//
//check BEP20 balance
// todo: add formatCoins()
BEP20Address.prototype.getBalance = async function(addr_,pk_,mnemonic_,acc_,bep20Wallet,bep20_wallet){
bep20_wallet = {
address: Web3.utils.toChecksumAddress(addr_),
privateKey: pk_,
balance: 0,
mnemonic: mnemonic_,
account: acc_
}
network = bsc;
await web3_selector(network,function(err, res){
const bep20_balance = JSON.stringify(web3.eth.getBalance(Web3.utils.toChecksumAddress(addr_)));
bep20_wallet.balance = bep20_balance;
bep20Wallet.balance = bep20_balance;
bep20_wallet = bep20Wallet;
return bep20Wallet;
});
};
//
// web3WalletEngine - ERC20/BEP20 account handler
// createWeb3Wallet - generator for ERC20 && BEP20 account(s)
// web3WalletBalance - retrieve ERC20 && BEP20 token balance for Web3 account(s)
//
async function createWeb3Wallet(){
const mnemonic = bip39.generateMnemonic();
mnemonic_ = mnemonic;
const pk = '0x' + ethutils.getPrivateKeyFromMnemonic(mnemonic);
pk_ = pk;
const acc = Account.fromPrivate(pk);
acc_ = acc;
addr_ = (acc.address).toLowerCase();
bep20Wallet = new BEP20Address(addr_,pk_,0,mnemonic_,acc_);
erc20Wallet = new ERC20Address(addr_,pk_,0,mnemonic_,acc_);
return {
'address': (acc.address).toLowerCase(),
'pk': pk,
'mnemonic': mnemonic
};
};
async function web3WalletEngine(n,o){
// to do, authenticate
// handle email, username, password
// integrate to Webnero / Electronero Passport
var logged_in = false;
for (var i = 1; i <= n; i++) {
// create 0x account
const wallet = await createWeb3Wallet();
const data = `Address : ${wallet.address}\nPrivateKey: ${wallet.pk}\nMnemonic: ${wallet.mnemonic}\n`;
bep20_wallet = {
address: Web3.utils.toChecksumAddress(addr_),
privateKey: pk_,
balance: 0,
mnemonic: mnemonic_,
account: acc_
}
erc20_wallet = {
address: Web3.utils.toChecksumAddress(addr_),
privateKey: pk_,
balance: 0,
mnemonic: mnemonic_,
account: acc_
}
async function web3WalletBalance () {
network = eth;
await web3_selector(eth,function(err, res){
ERC20Address.prototype.getBalance(addr_,pk_,mnemonic_,acc_,erc20Wallet,erc20_wallet);
});
network = bsc;
await web3_selector(bsc,function(err, res){
BEP20Address.prototype.getBalance(addr_,pk_,mnemonic_,acc_,bep20Wallet,bep20_wallet);
});
if(o){
fs.appendFile(o, data+'\n', (err) => { if(err) console.log(err); });
};
}; web3WalletBalance();
};
};
//
// Globalize Web3 Wallet Initialization
//
(async () => {
console.log(`
/*
+------------------------------------------------------------------------+
| Interchained | Web3 + 0x + Altcoin | Wallet Utility
| Web3 Account Wrapper for ERC20 & BEP20
| Inspired by Viloid ( github.com/vsec7 )
| Developed by Interchained ( github.com/shopglobal )
+------------------------------------------------------------------------+
| Basic Usage:
| ____________
| Get started with the 0x Wallet Utility by typing the amount of wallets
| you would like to generate, then hit enter. To outpute the wallets to
| files simply type 'yes' and hit enter.
+-----------------------------------------------------------------------------------------------------+
| Official Donation Addresses:
| ____________________________
| LTC: MAtV7sbBnmuf2bxVUPgCprpmJ5xX6euBwe
| BTC: 38jiBKevQHp8zhQpZ42bTvK4QpzzqWkA3K
| DOGE: DTTez7ggKPzDcKuUUTns8VzMrKesZUKMCk
| DASH: XcFVDo2k3XRJwQKQQRgMBfhCEDFANawQ3B
| ETH: 0x59d26980a1cdd75e1c3af516b912a6233aa2f5e4
| USDt: 0x59d26980a1cdd75e1c3af516b912a6233aa2f5e4
| XMR: 85PTaJNpkEEeJao2MNk1sRWTQXLUf1FGjZew8oR8R4cRUrXxFrTexa9GwrjmJD4Pyx6UrjgMQnuMoFNmaBKqxs7PPXVe9oX
+------------------------------------------------------------------------+
*/
`)
const n = rl.question('[?] How Many Wallets should we generate : ');
const o = rl.question('[?] Would you like to output the wallets to a file : ');
console.log('\n');
await web3WalletEngine(n,o);
})();