Last active
March 22, 2019 09:46
-
-
Save rocammo/47460656f735d7882a35c76acce16c5a to your computer and use it in GitHub Desktop.
Cold-Storage Ethereum Account Generator
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
""" | |
Cold-Storage Ethereum Account Generator | |
@author: rocammo | |
@date: 22 mar. 2019 | |
""" | |
import sys, getopt | |
from datetime import datetime | |
import json | |
from web3 import Web3 | |
def options(argv): | |
acct_n = '' | |
try: | |
opts, args = getopt.getopt(sys.argv[1:],'hg:') | |
except getopt.GetoptError: | |
print("usage: ./account_generator.py -g <number_of_accounts_to_generate>") | |
sys.exit(2) | |
for opt, arg in opts: | |
if opt == '-h': | |
sys.exit("usage: ./main.py -i <inputfile> -o <outputfile>") | |
elif opt == '-g': | |
acct_n = arg | |
return acct_n | |
if __name__ == '__main__': | |
# Parse command-line options and arguments | |
if not len(sys.argv) > 1: | |
sys.exit("usage: ./main.py -g <number_of_accounts_to_generate>") | |
acct_n = int(options(sys.argv[1:])) | |
# Connection to a blockchain endpoint | |
web3 = Web3(Web3.HTTPProvider("http://10.5.2.204:8545")) | |
print("Connection to Blockchain HTTPEndpoint... OK!") | |
print(f'[{datetime.now().strftime("%H:%M:%S")}] eth_blockNumber -> {web3.eth.blockNumber} ... CHECK!') | |
# Accounts generation | |
print(f'\nNumber of accounts: {acct_n}\n') | |
accts = [] | |
for i in range(0, acct_n): | |
acct = web3.eth.account.create('InyCOIN') | |
data = {} | |
data['address'] = acct.address | |
data['privKey'] = (acct.privateKey.hex())[2:] | |
accts.append(data) | |
print(f'Account {(i+1):3d}/{acct_n}... CREATED!') | |
# Json encoding | |
filename = 'accounts.json' | |
with open(filename, 'w') as outfile: | |
json.dump(accts, outfile) | |
print(f'\nAccounts generated successfully! ({filename})\n') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment