Bitcoin Forum

Bitcoin => Development & Technical Discussion => Topic started by: SebastianJu on August 15, 2015, 06:36:37 PM



Title: Importing many privkeys into bitcoin-qt?
Post by: SebastianJu on August 15, 2015, 06:36:37 PM
I wonder if there is a way to import many privkeys into bitcoin-qt easily without having to copy one line per address. I tried adding a couple commands at one time but doesn't work. The same goes for providing several keys in one line.

Is there a way to use the importprivkey command with several keys at a time or does the console allow to enter multiple commands in one line?

Creating such command would be no problem with calc. Only i don't want to copy so many lines one by one.


Title: Re: Importing many privkeys into bitcoin-qt?
Post by: BitcoinAddicts on August 15, 2015, 07:10:41 PM
I don't think there is a way to import multiple privatekeys to bitcoin qt wallet, you have to import them one by one. to make this process fast you can disable scan of the address when importing the key so it won't take long time to import a single key as usual,
read this post, it may help you
https://bitcointalk.org/index.php?topic=886599.msg9805886#msg9805886


Title: Re: Importing many privkeys into bitcoin-qt?
Post by: dserrano5 on August 15, 2015, 07:16:41 PM
Create a text file such as:

Code:
5abc...privkeyhere 2015-08-15T00:00:00Z
5abc...privkeyhere 2015-08-15T00:00:00Z
5abc...privkeyhere 2015-08-15T00:00:00Z
5abc...privkeyhere 2015-08-15T00:00:00Z

And run:

Code:
importwallet /path/to/file


Title: Re: Importing many privkeys into bitcoin-qt?
Post by: Nikinger on August 15, 2015, 07:17:48 PM
Put all private keys in privkeys.txt, one private key per line.

On Linux:
Code:
touch btcimport.sh
chmod +x btcimport.sh
echo "#/bin/bash" >btcimport.sh
echo "" >>btcimport.sh
for i in `cat privkeys.txt`; do echo "bitcoin-cli importprivkey $i \"\" false" >>btcimport.sh; done
vi btcimport.sh and turn the last "false" to "true" in order to reindex after the last import
Then ./btcimport.sh

On Windows:
Code:
for /f %i in (privkeys.txt) do @(echo bitcoin-cli.exe importprivkey %i "" false >>btcimport.bat)
notepad btcimport.bat and turn the last "false" to "true" in order to reindex after the last import
on prompt, run btcimport.bat

I tested the generation script only - haven't tried to run the importprivkey bash/batch script itsself, it's possible that you have to adapt the script for your system.


Title: Re: Importing many privkeys into bitcoin-qt?
Post by: achow101 on August 15, 2015, 07:18:38 PM
If you have a text file with all of the private keys in them, you can use a shell script to iterate through the file and import each key.


Title: Re: Importing many privkeys into bitcoin-qt?
Post by: SebastianJu on August 18, 2015, 11:47:33 AM
Thank you guys for the tips. :)

Create a text file such as:

Code:
5abc...privkeyhere 2015-08-15T00:00:00Z
5abc...privkeyhere 2015-08-15T00:00:00Z
5abc...privkeyhere 2015-08-15T00:00:00Z
5abc...privkeyhere 2015-08-15T00:00:00Z

And run:

Code:
importwallet /path/to/file

I would have been never got the idea that a wallet.dat file can be created that way. Or is it only a simplified import that works with that command?

Anyway... i will try that first since it looks like the easiest solution.


Title: Re: Importing many privkeys into bitcoin-qt?
Post by: SebastianJu on August 18, 2015, 09:41:39 PM
Create a text file such as:

Code:
5abc...privkeyhere 2015-08-15T00:00:00Z
5abc...privkeyhere 2015-08-15T00:00:00Z
5abc...privkeyhere 2015-08-15T00:00:00Z
5abc...privkeyhere 2015-08-15T00:00:00Z

And run:

Code:
importwallet /path/to/file

This actually worked like a charm. I would have not awaited that you can create a wallet file that way though it worked fine. :)

Thanks again.


Title: Re: Importing many privkeys into bitcoin-qt?
Post by: D3m0nKinGx on August 22, 2016, 09:16:46 AM
Here's a super easy script to import multiple keys into bitcoin-cli

$ touch import.sh
$ nano import.sh

paste this code:

Code:
#!/bin/bash

Filename=”privkeys.txt”

while IFS='' read -r line || [[ -n "$line" ]]; do

    echo "Text read from file: $line"

    bitcoin-cli importprivkey $line true

done < "$Filename"

$ chmod +x import.sh
$ ./import.sh


**make sure the import.sh and privkeys.txt files are in the same location!**