Here is tweaked code below
its depend on the number of CPU your processor have
if your processor have 5 CPU it will use 4 i.e cpustotal = cpu_count()-1
if you want to use all available cpu you can change it to cpustotal = cpu_count()
from bip_utils import Bip39MnemonicGenerator, Bip39SeedGenerator, Bip39WordsNum, Bip44Changes, Bip49, Bip49Coins, Bip44, Bip44Coins
from multiprocessing import Pool, cpu_count
def generatemenemonic(listofmenmonic):
arq = open('addresses.txt', 'a')
mnemonic = listofmenmonic
seed_bytes = Bip39SeedGenerator(mnemonic).Generate()
bip49_mst_ctx = Bip49.FromSeed(seed_bytes, Bip49Coins.BITCOIN)
bip44_mst_ctx = Bip44.FromSeed(seed_bytes, Bip44Coins.BITCOIN)
bip49_acc_ctx = bip49_mst_ctx.Purpose().Coin().Account(0)
bip49_chg_ctx = bip49_acc_ctx.Change(Bip44Changes.CHAIN_EXT)
bip44_acc_ctx = bip44_mst_ctx.Purpose().Coin().Account(0)
bip44_chg_ctx = bip44_acc_ctx.Change(Bip44Changes.CHAIN_EXT)
bip44_addr_ctx = bip44_chg_ctx.AddressIndex(0)
bip49_addr_ctx = bip49_chg_ctx.AddressIndex(0)
arq.write("%s \n" % bip44_addr_ctx.PublicKey().ToAddress())
arq.write("%s \n" % bip49_addr_ctx.PublicKey().ToAddress())
if __name__ == "__main__":
listofmenmonic = []
with open('x.txt') as f:
for line in f:
mnemonic = line.strip()
listofmenmonic.append(mnemonic)
cpustotal = cpu_count()-1
pool = Pool(cpustotal)
print("Starting Address Generator on " +str(cpustotal)+ " CPU's")
results = pool.map(generatemenemonic, listofmenmonic)
pool.close()
pool.join()
I want to make a note here one seed can have thousands of addresses as well which called Derivation paths address generation
let me add that code as well incase you want something like that
right now below code will get 30 address but you can change this line for i in range(30): to get more change 30 to 1000 may be
from bip_utils import Bip39MnemonicGenerator, Bip39SeedGenerator, Bip39WordsNum, Bip44Changes, Bip49, Bip49Coins, Bip44, Bip44Coins
from multiprocessing import Pool, cpu_count
def generatemenemonic(listofmenmonic):
mnemonic = listofmenmonic
seed_bytes = Bip39SeedGenerator(mnemonic).Generate()
bip49_mst_ctx = Bip49.FromSeed(seed_bytes, Bip49Coins.BITCOIN)
bip44_mst_ctx = Bip44.FromSeed(seed_bytes, Bip44Coins.BITCOIN)
bip49_acc_ctx = bip49_mst_ctx.Purpose().Coin().Account(0)
bip49_chg_ctx = bip49_acc_ctx.Change(Bip44Changes.CHAIN_EXT)
bip44_acc_ctx = bip44_mst_ctx.Purpose().Coin().Account(0)
bip44_chg_ctx = bip44_acc_ctx.Change(Bip44Changes.CHAIN_EXT)
#bip44_addr_ctx = bip44_chg_ctx.AddressIndex(0)
#bip49_addr_ctx = bip49_chg_ctx.AddressIndex(0)
#arq.write("%s \n" % bip44_addr_ctx.PublicKey().ToAddress())
#arq.write("%s \n" % bip49_addr_ctx.PublicKey().ToAddress())
tempaddr = []
for i in range(30):
bip44_addr_ctx = bip44_chg_ctx.AddressIndex(i)
bip49_addr_ctx = bip49_chg_ctx.AddressIndex(i)
bip44addr = bip44_addr_ctx.PublicKey().ToAddress()
bip49addr = bip49_addr_ctx.PublicKey().ToAddress()
tempaddr.append(bip44addr)
tempaddr.append(bip49addr)
with open('addresses.txt', 'a') as f:
for line in tempaddr:
f.write(f"{line}\n")
if __name__ == "__main__":
listofmenmonic = []
with open('x.txt') as f:
for line in f:
mnemonic = line.strip()
listofmenmonic.append(mnemonic)
cpustotal = cpu_count()-1
pool = Pool(cpustotal)
print("Starting Address Generator on " +str(cpustotal)+ " CPU's")
results = pool.map(generatemenemonic, listofmenmonic)
pool.close()
pool.join()
If you want your to get separate files for both bip44 and bip49 then code is below
from bip_utils import Bip39MnemonicGenerator, Bip39SeedGenerator, Bip39WordsNum, Bip44Changes, Bip49, Bip49Coins, Bip44, Bip44Coins
from multiprocessing import Pool, cpu_count
def generatemenemonic(listofmenmonic):
arq = open('addresses_bip44.txt', 'a')
arp = open('addresses_bip49.txt', 'a')
mnemonic = listofmenmonic
seed_bytes = Bip39SeedGenerator(mnemonic).Generate()
bip49_mst_ctx = Bip49.FromSeed(seed_bytes, Bip49Coins.BITCOIN)
bip44_mst_ctx = Bip44.FromSeed(seed_bytes, Bip44Coins.BITCOIN)
bip49_acc_ctx = bip49_mst_ctx.Purpose().Coin().Account(0)
bip49_chg_ctx = bip49_acc_ctx.Change(Bip44Changes.CHAIN_EXT)
bip44_acc_ctx = bip44_mst_ctx.Purpose().Coin().Account(0)
bip44_chg_ctx = bip44_acc_ctx.Change(Bip44Changes.CHAIN_EXT)
bip44_addr_ctx = bip44_chg_ctx.AddressIndex(0)
bip49_addr_ctx = bip49_chg_ctx.AddressIndex(0)
arq.write("%s \n" % bip44_addr_ctx.PublicKey().ToAddress())
arp.write("%s \n" % bip49_addr_ctx.PublicKey().ToAddress())
if __name__ == "__main__":
listofmenmonic = []
with open('x.txt') as f:
for line in f:
mnemonic = line.strip()
listofmenmonic.append(mnemonic)
cpustotal = cpu_count()-1
pool = Pool(cpustotal)
print("Starting Address Generator on " +str(cpustotal)+ " CPU's")
results = pool.map(generatemenemonic, listofmenmonic)
pool.close()
pool.join()
There is one more thing that we can add to code i.e compress and uncompressed addresses ( lemme know if u want to add that)
Also there is a built-in mnemonic lib for python as well if you want to generate random mnemonic
message me for that if you need to learn
cheers !