Electrum has a powerful command line. This page will show you a few basic principles.


Using the inline help

To see the list of Electrum commands, type:



electrum-smart help



To see the documentation for a command, type:



electrum-smart help <command>





Magic words

The arguments passed to commands may be one of the following magic words: ! ? : and -.

  • The exclamation mark ! is a shortcut that means ‘the maximum amount available’.

    Example:



    electrum-smart payto SdyTJU4Mn1nLrY3yPCfe62tRZy2fsPexfx !



    Note that the transaction fee will be computed and deducted from the amount.

  • A question mark ? means that you want the parameter to be prompted.

    Example:



    electrum-smart signmessage SdyTJU4Mn1nLrY3yPCfe62tRZy2fsPexfx ?



  • Use a colon : if you want the prompted parameter to be hidden (not echoed in your terminal).



    electrum-smart importprivkey :



    Note that you will be prompted twice in this example, first for the private key, then for your wallet password.

  • A parameter replaced by a dash - will be read from standard input (in a pipe)



    cat LICENCE | electrum-smart signmessage SdyTJU4Mn1nLrY3yPCfe62tRZy2fsPexfx -





Aliases

You can use DNS aliases in place of bitcoin addresses, in most commands.



electrum-smart payto smartie.shop !





Formatting outputs using jq

Command outputs are either simple strings or json structured data. A very useful utility is the ‘jq’ program. Install it with:



sudo apt-get install jq



The following examples use it.



Examples


Sign and verify message

We may use a variable to store the signature, and verify it:



sig=$(cat LICENCE| electrum-smart signmessage SdyTJU4Mn1nLrY3yPCfe62tRZy2fsPexfx -)



And:



cat LICENCE | electrum-smart verifymessage SdyTJU4Mn1nLrY3yPCfe62tRZy2fsPexfx $sig -





Show the values of your unspents

The ‘listunspent’ command returns a list of dict objects, with various fields. Suppose we want to extract the ‘value’ field of each record. This can be achieved with the jq command:



electrum-smart listunspent | jq 'map(.value)'





Select only incoming transactions from history

Incoming transactions have a positive ‘value’ field



electrum-smart history | jq '.[] | select(.value>0)'





Filter transactions by date

The following command selects transactions that were timestamped after a given date:



after=$(date -d '09/01/2018' +"%s")

electrum-smart history | jq --arg after $after '.[] | select(.timestamp>($after|tonumber))'



Similarly, we may export transactions for a given time period:



before=$(date -d '09/01/2018' +"%s")

after=$(date -d '09/01/2018' +"%s")

electrum-smart history | jq --arg before $before --arg after $after '.[] | select(.timestamp&gt;($after|tonumber) and .timestamp&lt;($before|tonumber))'





Encrypt and decrypt messages

First we need the public key of a wallet address:



pk=$(electrum-smart getpubkeys SdyTJU4Mn1nLrY3yPCfe62tRZy2fsPexfx| jq -r '.[0]')



Encrypt:



cat | electrum-smart encrypt $pk -



Decrypt:



electrum-smart decrypt $pk ?



Note: this command will prompt for the encrypted message, then for the wallet password



Export private keys and sweep coins

The following command will export the private keys of all wallet addresses that hold some bitcoins:



electrum-smart listaddresses --funded | electrum-smart getprivatekeys -



This will return a list of lists of private keys. In most cases, you want to get a simple list. This can be done by adding a jq filer, as follows:



electrum-smart listaddresses --funded | electrum-smart getprivatekeys - | jq 'map(.[0])'



Finally, let us use this list of private keys as input to the sweep command:



electrum-smart listaddresses --funded | electrum-smart getprivatekeys - | jq 'map(.[0])' | electrum-smart sweep - [destination