Bitcoin Forum
May 06, 2024, 05:51:16 PM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: How to import many priv keys in one query  (Read 216 times)
ArthurY (OP)
Sr. Member
****
Offline Offline

Activity: 840
Merit: 254


I love BTC


View Profile
June 13, 2022, 10:58:32 AM
Merited by Welsh (1)
 #1

Could you help me guys to show me up an example of RPC call how to import many priv keys in a single query
As I understood I should use `importmulti` request. But I do not know which kind of script, address etc should place if I just need to import bulk of keys

For example which request should I run to import such of keys?

5Jza3odChZ1vfzmRSSK6qJZCuGdXYR4RndFHXx1KEWq9AiDkwCj
5JebES9429R4HNFUcX5kFgR7FAoFWxpHZ3XrvAf4bSNNxijzxRB
5J4WYCjKqG7JxY3fjj2ukusd36mXMVas42bTh2nesd6HwaFtwh7



Sophisticated Investor
1715017876
Hero Member
*
Offline Offline

Posts: 1715017876

View Profile Personal Message (Offline)

Ignore
1715017876
Reply with quote  #2

1715017876
Report to moderator
1715017876
Hero Member
*
Offline Offline

Posts: 1715017876

View Profile Personal Message (Offline)

Ignore
1715017876
Reply with quote  #2

1715017876
Report to moderator
1715017876
Hero Member
*
Offline Offline

Posts: 1715017876

View Profile Personal Message (Offline)

Ignore
1715017876
Reply with quote  #2

1715017876
Report to moderator
BitcoinCleanup.com: Learn why Bitcoin isn't bad for the environment
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction.
1715017876
Hero Member
*
Offline Offline

Posts: 1715017876

View Profile Personal Message (Offline)

Ignore
1715017876
Reply with quote  #2

1715017876
Report to moderator
1715017876
Hero Member
*
Offline Offline

Posts: 1715017876

View Profile Personal Message (Offline)

Ignore
1715017876
Reply with quote  #2

1715017876
Report to moderator
1715017876
Hero Member
*
Offline Offline

Posts: 1715017876

View Profile Personal Message (Offline)

Ignore
1715017876
Reply with quote  #2

1715017876
Report to moderator
BlackHatCoiner
Legendary
*
Online Online

Activity: 1512
Merit: 7355


Farewell, Leo


View Profile
June 13, 2022, 12:43:24 PM
Merited by ArthurY (25), LoyceV (4), ABCbits (3), Welsh (2), seoincorporation (2), Pmalek (2), DdmrDdmr (1)
 #2

As I understood I should use `importmulti` request. But I do not know which kind of script, address etc should place if I just need to import bulk of keys
If your private keys start with "5", it means their public key is uncompressed. So, it's P2PKH. So make sure your wallet is not descriptor.

For example which request should I run to import such of keys?
Why don't you loop importprivkey?
Code:
bitcoin-cli importprivkey "private_key" "label" false

With RPC, it'd be:
Code:
curl -u USERNAME:PASSWORD --data-binary '{"jsonrpc": "1.0", "id": "curltest", "method": "importprivkey", "params": ["PRIVATE_KEY", "label_x", false]}' -H 'content-type: text/plain;' http://127.0.0.1:8332/wallet/WALLET_NAME

Create a txt file and insert your private keys there like:
Code: ("foo.txt")
5Jza3odChZ1vfzmRSSK6qJZCuGdXYR4RndFHXx1KEWq9AiDkwCj
5JebES9429R4HNFUcX5kFgR7FAoFWxpHZ3XrvAf4bSNNxijzxRB
5J4WYCjKqG7JxY3fjj2ukusd36mXMVas42bTh2nesd6HwaFtwh7

Now create this bash script. It reads every line of your text file and runs the curl command.
Code: ("test.sh")
#!/bin/bash

for i in `seq 1 3`;
do
    line="`head -$i foo.txt | tail +$i`"
    echo $line;
    curl -u USERNAME:PASSWORD --data-binary '{"jsonrpc": "1.0", "id": "curltest", "method": "importprivkey", "params": ["'$line'", "any_label", false]}' -H 'content-type: text/plain;' http://127.0.0.1:8332/wallet/WALLET_NAME;
done

Replace USERNAME, PASSWORD and WALLET_NAME accordingly. On linux you can run it with:
Code:
bash test.sh




I'd make sure I connect to my Bitcoin server via a secure transfer protocol, because there's sensitive info transferred.

.
.HUGE.
▄██████████▄▄
▄█████████████████▄
▄█████████████████████▄
▄███████████████████████▄
▄█████████████████████████▄
███████▌██▌▐██▐██▐████▄███
████▐██▐████▌██▌██▌██▌██
█████▀███▀███▀▐██▐██▐█████

▀█████████████████████████▀

▀███████████████████████▀

▀█████████████████████▀

▀█████████████████▀

▀██████████▀▀
█▀▀▀▀











█▄▄▄▄
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
.
CASINSPORTSBOOK
▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
▀▀▀▀█











▄▄▄▄█
seoincorporation
Legendary
*
Offline Offline

Activity: 3150
Merit: 2930


Top Crypto Casino


View Profile
June 13, 2022, 05:46:00 PM
Last edit: June 15, 2022, 12:35:29 PM by seoincorporation
Merited by LoyceV (4), Welsh (4), Pmalek (2), BlackHatCoiner (2), ABCbits (1), DdmrDdmr (1)
 #3

Just a little observation on the code, that one will work only for 3 Private keys, we could change this line:

Code:
for i in `seq 1 3`;

for:

Code:
for i in $(cat foo.txt);

or another solution is to change the 3 for a variable:

Code:
z=$(cat foo.txt | wc -l)
for i in `seq 1 $z`;

This way the script will work for any number of Private keys in the file.

█████████████████████████
████▐██▄█████████████████
████▐██████▄▄▄███████████
████▐████▄█████▄▄████████
████▐█████▀▀▀▀▀███▄██████
████▐███▀████████████████
████▐█████████▄█████▌████
████▐██▌█████▀██████▌████
████▐██████████▀████▌████
█████▀███▄█████▄███▀█████
███████▀█████████▀███████
██████████▀███▀██████████
█████████████████████████
.
BC.GAME
▄▄░░░▄▀▀▄████████
▄▄▄
██████████████
█████░░▄▄▄▄████████
▄▄▄▄▄▄▄▄▄██▄██████▄▄▄▄████
▄███▄█▄▄██████████▄████▄████
███████████████████████████▀███
▀████▄██▄██▄░░░░▄████████████
▀▀▀█████▄▄▄███████████▀██
███████████████████▀██
███████████████████▄██
▄███████████████████▄██
█████████████████████▀██
██████████████████████▄
.
..CASINO....SPORTS....RACING..
█░░░░░░█░░░░░░█
▀███▀░░▀███▀░░▀███▀
▀░▀░░░░▀░▀░░░░▀░▀
░░░░░░░░░░░░
▀██████████
░░░░░███░░░░
░░█░░░███▄█░░░
░░██▌░░███░▀░░██▌
░█░██░░███░░░█░██
░█▀▀▀█▌░███░░█▀▀▀█▌
▄█▄░░░██▄███▄█▄░░▄██▄
▄███▄
░░░░▀██▄▀


▄▄████▄▄
▄███▀▀███▄
██████████
▀███▄░▄██▀
▄▄████▄▄░▀█▀▄██▀▄▄████▄▄
▄███▀▀▀████▄▄██▀▄███▀▀███▄
███████▄▄▀▀████▄▄▀▀███████
▀███▄▄███▀░░░▀▀████▄▄▄███▀
▀▀████▀▀████████▀▀████▀▀
NotATether
Legendary
*
Offline Offline

Activity: 1596
Merit: 6728


bitcoincleanup.com / bitmixlist.org


View Profile WWW
June 14, 2022, 05:04:05 AM
 #4

Why don't you loop importprivkey?

Since this executes the RPC server for each private key though, it's going to slow down once you reach a hundred PKs or so, especially if your node is somewhere far away n the public internet (then latency also has to be considered).

Quote
I'd make sure I connect to my Bitcoin server via a secure transfer protocol, because there's sensitive info transferred.

The only option would be calling it via an .onion address on Tor, since even the RPC password is sent unencrypted. It is indeed unsafe to issue any RPC call with plain HTTP because of the unencrypted password.

.
.BLACKJACK ♠ FUN.
█████████
██████████████
████████████
█████████████████
████████████████▄▄
░█████████████▀░▀▀
██████████████████
░██████████████
████████████████
░██████████████
████████████
███████████████░██
██████████
CRYPTO CASINO &
SPORTS BETTING
▄▄███████▄▄
▄███████████████▄
███████████████████
█████████████████████
███████████████████████
█████████████████████████
█████████████████████████
█████████████████████████
███████████████████████
█████████████████████
███████████████████
▀███████████████▀
█████████
.
vjudeu
Hero Member
*****
Offline Offline

Activity: 678
Merit: 1560



View Profile
June 14, 2022, 06:22:21 AM
 #5

Quote
The only option would be calling it via an .onion address on Tor, since even the RPC password is sent unencrypted. It is indeed unsafe to issue any RPC call with plain HTTP because of the unencrypted password.
For me, sending a text file to my server in a secure way, and executing everything on that server was a better option.

█▀▀▀











█▄▄▄
▀▀▀▀▀▀▀▀▀▀▀
e
▄▄▄▄▄▄▄▄▄▄▄
█████████████
████████████▄███
██▐███████▄█████▀
█████████▄████▀
███▐████▄███▀
████▐██████▀
█████▀█████
███████████▄
████████████▄
██▄█████▀█████▄
▄█████████▀█████▀
███████████▀██▀
████▀█████████
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
c.h.
▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
▀▀▀█











▄▄▄█
▄██████▄▄▄
█████████████▄▄
███████████████
███████████████
███████████████
███████████████
███░░█████████
███▌▐█████████
█████████████
███████████▀
██████████▀
████████▀
▀██▀▀
NotATether
Legendary
*
Offline Offline

Activity: 1596
Merit: 6728


bitcoincleanup.com / bitmixlist.org


View Profile WWW
June 16, 2022, 01:18:03 PM
 #6

Quote
The only option would be calling it via an .onion address on Tor, since even the RPC password is sent unencrypted. It is indeed unsafe to issue any RPC call with plain HTTP because of the unencrypted password.
For me, sending a text file to my server in a secure way, and executing everything on that server was a better option.

That works too (if you use SFTP with at least 2048-bit RSA keypairs, which is pretty much the industry standard anyway) particularly if the server is an ephermal box you lease from some vendor, set up for your needs, and then get rid of it when the lease ends - think services like BitVPS.

.
.BLACKJACK ♠ FUN.
█████████
██████████████
████████████
█████████████████
████████████████▄▄
░█████████████▀░▀▀
██████████████████
░██████████████
████████████████
░██████████████
████████████
███████████████░██
██████████
CRYPTO CASINO &
SPORTS BETTING
▄▄███████▄▄
▄███████████████▄
███████████████████
█████████████████████
███████████████████████
█████████████████████████
█████████████████████████
█████████████████████████
███████████████████████
█████████████████████
███████████████████
▀███████████████▀
█████████
.
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!