<p>You can get all the available commands with <code>help()</code>. 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 <a href="https://github.com/spesmilo/electrum/blob/master/electrum/commands.py" rel="nofollow noreferrer">commands.py file</a>. For example, to get the current block height <a href="https://github.com/spesmilo/electrum/blob/master/electrum/commands.py#L212" rel="nofollow noreferrer">you can use <code>getinfo()</code></a></p>

CC BY-SA 4.0
2024-03-20T11:35:07.487Z
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 ?
ewen-goisot
CC BY-SA 4.0
2024-03-21T07:25:41.977Z
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 https://github.com/spesmilo/electrum/blob/3.3.8/electrum/commands.py
Juha Siivikko
CC BY-SA 4.0
2024-03-21T07:48:01.240Z
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 ?
ewen-goisot
CC BY-SA 4.0
2024-03-21T08:16:21.013Z
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 https://developer.bitcoin.org/reference/rpc/getblock.html
Juha Siivikko
CC BY-SA 4.0
2024-03-21T11:08:46.727Z
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.
ewen-goisot
CC BY-SA 4.0
2024-06-03T16:25:07.110Z
Ok, I "accept" your ansrwer, considering it's the only answer, and you at least partially gave me the solution with `getinfo()`. I also saw other useful commands like `get_merkle()`. Other stuff I asked for are probably impossible inside the Electrum's console. Best I've found now for my needs is this script to convert blockchain headers : https://bitcoin.stackexchange.com/questions/66873/do-you-know-any-download-site-for-full-blockchain-header-data-6-in-csv-ascii-f/73987#73987 (outside of the Electrum console, but good enough. May be improved to avoid re-converting everything everytime).
ewen-goisot
CC BY-SA 4.0
2024-03-20T06:53:28.973Z
2024-03-20T06:53:28.973Z
Juha Siivikko
<p>I wanted to use Electrum's python console, but the <a href="https://electrum.readthedocs.io/en/latest/console.html" rel="nofollow noreferrer">documentation</a> just gives a few examples.<br>
Is there a more complete documentation about python commands inside Electrum ?</p>
<p>Main tasks I currently want to do are blockchain reading, it includes :</p>
<ul>
<li>the current block height<br>(it is in the GUI, in &quot;tools&quot; -&gt; &quot;network&quot;, but is there a CLI way to do it ?)</li>
<li>informations about a given block, like POW and Merkle root<br>(I don't know at all if there is a way to get them inside the console)<br>(there is a file named <code>~/.electrum/blockchain_headers</code>, but it's not human-readable).</li>
</ul>
<p>Is there a way to do that ?
(this is my main question)</p>
<p>(I'm currently using Electrum 3.3.8.)</p>

<blockchain><electrum><python><cli>
Can I read blockchain's information from Electrum's python console?
ewen-goisot
# Can I read blockchain's information from Electrum's python console?

(Asked by: username_0 on 2024-03-20)

I wanted to use Electrum's python console, but the [documentation](https://electrum.readthedocs.io/en/latest/console.html) 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.)

**Tags:** blockchain, electrum, python, cli


---

## 1 answers

### Answer by username_1 on 2024-03-20. Score: 1 | Accepted answer

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](https://github.com/spesmilo/electrum/blob/master/electrum/commands.py). For example, to get the current block height [you can use `getinfo()`](https://github.com/spesmilo/electrum/blob/master/electrum/commands.py#L212)

> **Comments:**
> **username_0**: 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 ?  
> **username_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 https://github.com/spesmilo/electrum/blob/3.3.8/electrum/commands.py  
> **username_0**: 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 ?  
> **username_1**: 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 https://developer.bitcoin.org/reference/rpc/getblock.html  
> **username_0**: 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.  
> **username_0**: Ok, I "accept" your ansrwer, considering it's the only answer, and you at least partially gave me the solution with `getinfo()`. I also saw other useful commands like `get_merkle()`. Other stuff I asked for are probably impossible inside the Electrum's console. Best I've found now for my needs is this script to convert blockchain headers : https://bitcoin.stackexchange.com/questions/66873/do-you-know-any-download-site-for-full-blockchain-header-data-6-in-csv-ascii-f/73987#73987 (outside of the Electrum console, but good enough. May be improved to avoid re-converting everything everytime).  

---

