1

I wanted to use Electrum's python console, but the documentation just gives a few examples.
Is there a more complete documentation about python commands inside Electrum ?

Main tasks I currently want to do are blockchain reading, it includes :

  • the current block height
    (it is in the GUI, in "tools" -> "network", but is there a CLI way to do it ?)
  • informations about a given block, like POW and Merkle root
    (I don't know at all if there is a way to get them inside the console)
    (there is a file named ~/.electrum/blockchain_headers, but it's not human-readable).

Is there a way to do that ? (this is my main question)

(I'm currently using Electrum 3.3.8.)

1 Answer 1

1

You can get all the available commands with help(). This is not much of a help as it just lists all the commands without any other documentation. The full list of commands and arguments for those commands can be found in the commands.py file. For example, to get the current block height you can use getinfo()

5
  • Did you try your solution first ? I don't see the getinfo command inside the list I got with help(). And when I type getinfo or getinfo() in the console, I just receive an error message : "Traceback (most recent call last): NameError: name 'getinfo' is not defined". How am I supposed to use the function getinfo() to make it work, please ? Mar 20 at 11:35
  • 1
    Yes I did try it. Looks like getinfo() has been present at least from version 4.0.1 Is there a reason you need to use 3.3.8? It is almost 5 years old. You are right, your version does not have the getinfo command and looking at the code from your version, there is no command that returns the block height github.com/spesmilo/electrum/blob/3.3.8/electrum/commands.py Mar 21 at 7:25
  • ok, thank you. I tried with version 4.5.4, and the getinfo() command is available. I can see the current blockchain's height with this. But how can I see more "advanced" infos from blockchain headers (on any block), like POW or merkle root ? Mar 21 at 7:48
  • Electrum is a wallet and the commands reflect that. The commands are intended for handling the wallet and wallet related tasks, so they have limitations. You might not be able to get all the info you want with Electrum. Would it be possible for you to use Bitcoin Core? It has an RPC command interface (can be called with Python) that can be used from a console just like Electrum. Here is an example of a block related command developer.bitcoin.org/reference/rpc/getblock.html Mar 21 at 8:16
  • The reason why I chose to use Electrum is that I don't want to have to download a complete copy of the blockchain. Now, I want to read as much datas as possible just from the headers. If I just need the POW and Merkle roots (they are very small), it makes no sense for me to download ~200GB of datas. If Electrum downloads the headers, I think it means Electrum "understand" the headers. Mar 21 at 11:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.