Bitcoin Forum
May 02, 2024, 09:58:48 PM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: Electrum daemon/console: Get address from path (or private key)  (Read 108 times)
NotATether (OP)
Legendary
*
Offline Offline

Activity: 1596
Merit: 6723


bitcoincleanup.com / bitmixlist.org


View Profile WWW
November 23, 2021, 01:42:01 PM
Merited by pooya87 (1), ABCbits (1)
 #1

Greetings fellow bitcoiners.

I need a way to query the Electrum daemon to return the address corresponding to a path, or a private key (because I can already obtain the private key corresponding to the path). Preferably I would like this to be done by an Electrum command so I can just make a single RPC call. But I didn't find any commands that perform this functionality.

This is all being done programmatically on a headless server so using the GUI wallet is not an option.

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

Posts: 1714687128

View Profile Personal Message (Offline)

Ignore
1714687128
Reply with quote  #2

1714687128
Report to moderator
1714687128
Hero Member
*
Offline Offline

Posts: 1714687128

View Profile Personal Message (Offline)

Ignore
1714687128
Reply with quote  #2

1714687128
Report to moderator
1714687128
Hero Member
*
Offline Offline

Posts: 1714687128

View Profile Personal Message (Offline)

Ignore
1714687128
Reply with quote  #2

1714687128
Report to moderator
"The nature of Bitcoin is such that once version 0.1 was released, the core design was set in stone for the rest of its lifetime." -- Satoshi
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction.
1714687128
Hero Member
*
Offline Offline

Posts: 1714687128

View Profile Personal Message (Offline)

Ignore
1714687128
Reply with quote  #2

1714687128
Report to moderator
1714687128
Hero Member
*
Offline Offline

Posts: 1714687128

View Profile Personal Message (Offline)

Ignore
1714687128
Reply with quote  #2

1714687128
Report to moderator
1714687128
Hero Member
*
Offline Offline

Posts: 1714687128

View Profile Personal Message (Offline)

Ignore
1714687128
Reply with quote  #2

1714687128
Report to moderator
o_e_l_e_o
In memoriam
Legendary
*
Offline Offline

Activity: 2268
Merit: 18509


View Profile
November 23, 2021, 06:07:16 PM
Merited by pooya87 (2), ABCbits (2), NotATether (2)
 #2

Code:
bitcoin.address_from_private_key("yourprivkeyhere")

This should do what you are looking for. You can prefix your private key with the usual Electrum prefixes (p2pkh:, p2wpkh-p2sh:, p2wpkh:) to generate a specific address type if needed. Private keys should be in WIF.
NotATether (OP)
Legendary
*
Offline Offline

Activity: 1596
Merit: 6723


bitcoincleanup.com / bitmixlist.org


View Profile WWW
November 23, 2021, 06:30:03 PM
Last edit: November 23, 2021, 06:44:54 PM by NotATether
Merited by o_e_l_e_o (4), ABCbits (1)
 #3

Code:
bitcoin.address_from_private_key("yourprivkeyhere")

This should do what you are looking for. You can prefix your private key with the usual Electrum prefixes (p2pkh:, p2wpkh-p2sh:, p2wpkh:) to generate a specific address type if needed. Private keys should be in WIF.

Is this something I run in a Python console? I'm building something with it using another language, where Python will not be available so I would like to at least be able to call this over CURL. (Maybe a mini-server that just runs this statement will do?)

Maybe I can just clone the master branch and add an Electrum command that runs this myself? (And maybe even merge it later). Seems like the most logical option right now.


On a related note, now I have a different problem, that's how do I specify the "wallet_path" (or "electrum_path" and other config_options arguments through a CURL request? On the command line I could just do -w /path and it specifies the wallet path. But I'm not quite sure how I am supposed to specify this in this (example) request:

Code:
# inside "params" maybe? But it's an empty list.
curl --data-binary '{"jsonrpc":"2.0","id":"curltext","method":"getbalance","params":[]}' http://username:password@127.0.0.1:7777

# and this one is with maps/objects/dicts (you get the idea)

curl --data-binary '{"jsonrpc":"2.0","id":"curltext","method":"listaddresses","params":{"funded":true}}' http://username:password@127.0.0.1:7777

.
.BLACKJACK ♠ FUN.
█████████
██████████████
████████████
█████████████████
████████████████▄▄
░█████████████▀░▀▀
██████████████████
░██████████████
████████████████
░██████████████
████████████
███████████████░██
██████████
CRYPTO CASINO &
SPORTS BETTING
▄▄███████▄▄
▄███████████████▄
███████████████████
█████████████████████
███████████████████████
█████████████████████████
█████████████████████████
█████████████████████████
███████████████████████
█████████████████████
███████████████████
▀███████████████▀
█████████
.
o_e_l_e_o
In memoriam
Legendary
*
Offline Offline

Activity: 2268
Merit: 18509


View Profile
November 24, 2021, 10:48:47 AM
Merited by Accardo (1)
 #4

Is this something I run in a Python console?
That's correct. I know this command works in the GUI console - I've not tested it personally in python (and I'm not at a machine in which I could test it personally for the time being), but I see no reason it wouldn't behave in the same way.

On a related note, now I have a different problem, that's how do I specify the "wallet_path" (or "electrum_path" and other config_options arguments through a CURL request? On the command line I could just do -w /path and it specifies the wallet path. But I'm not quite sure how I am supposed to specify this in this (example) request:
I'm not 100% sure about this, but try the following:

Code:
curl --data-binary '{"jsonrpc":"2.0","id":"curltext","method":"getbalance","params":{"config_options":{"subcommand":"load_wallet", "wallet_path":"/path/to/wallet", "password":"pass"}}}' http://username:password@127.0.0.1:7777
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!