Script to import multiple priv keys in Electrum

0

DuckDuckGo turns up nothing of interest. How to import multiple priv keys in Electrum from a file using Electrum console or shell script, for all derivable valid BTC addresses? (1,3,bc1)

Eventually I would like to pipe the output of one script directly into an import script.

The file is in format:

BTC Pattern: <pattern>  
BTC Address: <bitcoin address beginning with one>  
BTC Privkey: <bitcoin address beginning with five>
...

user93729

Posted 2019-04-12T23:22:02.047

Reputation: 1

Does this help?

KappaDev 2019-04-12T23:34:57.190

@KappaDev Thank you, I can filter my input file and paste a bunch. Updated question for derivable addresses.user93729 2019-04-12T23:40:10.763

Answers

0

First of all get rid of all that junk. One priv key per line is all you need. So use grep privkey filename|cut -d":" -f2 > clean-file.txt. Then call this python script with that file as an argument:

import sys
from electrum import bitcoin
f = open(sys.argv[1], "r")
for privkey in f:
    privkey=privkey.strip()
    orig_format,secret,compressed=bitcoin.deserialize_privkey( privkey)
    formats = [ bitcoin.serialize_privkey( secret, False, "p2pkh"), bitcoin.serialize_privkey( secret, True, "p2pkh"), bitcoin.serialize_privkey( secret, True, "p2wpkh"), bitcoin.serialize_privkey( secret, True, "p2wpkh-p2sh") ]
    for thing in formats:
        print(thing)

It'll output all the private keys in the various formats.

Abdussamad

Posted 2019-04-12T23:22:02.047

Reputation: 1 850