I have a bitcoin private key and I want to get the bitcoin address from it. What is the command in the command line for electrum to extract this address?
There is no cli command that can do this. You can do it via 3 methods:
In the Electrum GUI go to the view menu > show console and switch to the console tab. On the console tab type this:
bitcoin.address_from_private_key("<privkeyhere>")
Then once you have the address clear the console history or your private key will be saved to disk:
window.console.history = []
Another option is to simply import your private key into a new electrum wallet. File > new/restore, enter a unique filename and click next, choose to import addresses or private keys and then follow on-screen instructions for the rest.
OP has clarified that he wants to do this via bash so a third option is to write a custom python script:
#!/usr/bin/python3 from electrum import bitcoin import sys print(bitcoin.address_from_private_key(sys.argv[1]))
Put the above in a file and
chmod +x
it. Then run it with the private key as an argument. Obviously anyone else who runsps
on the same system at the same time will see your private key so this approach is not recommended.
-
I need to do it via command line because I'm using the electrum command in a bash script. – Patoshi パトシ Feb 3 '19 at 20:09
-
@Patoshiパトシ you could write a custom python script for this but if you pass the priv key to it via bash your priv key will be exposed on the command line. anyone on the same system that runs
ps
at the same time as the command will be able to see your priv key. – Abdussamad Feb 3 '19 at 21:22 -