Leading Bitcoin Wallet

Command Line

Electrum offers a robust command line interface. This guide covers essential concepts for using the CLI, updated for Electrum 4.0 and later versions.

Getting Help

To view all available Electrum commands:

electrum help

For detailed information about a specific command:

electrum help <command>

Using the Electrum Daemon

Electrum commands typically interact with a running daemon. Here’s how to manage the daemon:

electrum daemon -d
electrum getinfo
electrum stop

Some operations require a loaded wallet. To manage wallets:

electrum load_wallet  # this will load the default wallet
electrum load_wallet -w /path/to/wallet/file
electrum list_wallets

After loading a wallet, you can perform wallet-related tasks:

electrum listaddresses

Send a payment:

electrum payto <address> <amount>

For commands that don’t need network access, use the --offline flag:

electrum -o listaddresses
electrum -o payto <address> <amount>
electrum -o -w /path/to/wallet/file listaddresses

Special Command Shortcuts (Magic Words)

Electrum’s command line interface supports several special characters to enhance functionality:

Exclamation Mark (!) Use ! to indicate the maximum available amount in a transaction.

Example:

electrum payto 1JuiT4dM65d8vBt8qUYamnDmAMJ4MjjxRE !

This sends the maximum available funds to the specified address. The transaction fee is automatically calculated and deducted.

Question Mark (?) The ? prompts you to enter a value for a parameter.

Example:

electrum signmessage 1JuiT4dM65d8vBt8qUYamnDmAMJ4MjjxRE ?

You’ll be asked to input the message to sign.

Colon (:) Use : for hidden input, useful for sensitive data like passwords.

Example:

electrum importprivkey :

You’ll be prompted twice: first for the private key, then for your wallet password. The input won’t be displayed on screen.

Dash (-) A dash - reads input from a pipe or standard input.

Example:

cat LICENCE | electrum signmessage 1JuiT4dM65d8vBt8qUYamnDmAMJ4MjjxRE -

This signs the content of the LICENCE file with the specified address.

Aliases

Electrum allows you to use DNS aliases instead of full Bitcoin addresses in many commands. This feature simplifies transactions and improves usability.

You can replace a Bitcoin address with its corresponding DNS alias in most Electrum commands.

Example:

electrum payto ecdsa.net !

Formatting Electrum Outputs with jq

Electrum command outputs are typically simple strings or structured JSON data. To enhance readability and processing of these outputs, you can use the jq utility.

Installing jq: On Debian-based systems (like Ubuntu), install it using:

sudo apt-get install jq

For other operating systems, check your package manager or the jq website for installation instructions.

Examples

Signing and Verifying Messages

Signing a Message

To sign the contents of a file (in this case, ‘LICENCE’) with a specific Bitcoin address:

sig=$(cat LICENCE| electrum signmessage 1JuiT4dM65d8vBt8qUYamnDmAMJ4MjjxRE -)

Verifying a Message

To verify the signature of the same file content:

cat LICENCE | electrum verifymessage 1JuiT4dM65d8vBt8qUYamnDmAMJ4MjjxRE $sig -

Show the values of your unspents

This example demonstrates how to view the values of your unspent outputs using Electrum’s command line interface in combination with jq.

To show the values of your unspent transactions:

electrum listunspent | jq 'map(.value)'

Select only incoming transactions from history

This example shows how to use Electrum’s command line interface with jq to display only incoming transactions from your wallet’s history.

To view only incoming transactions:

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

Filter transactions by date

This guide shows how to use Electrum’s CLI with jq to filter transactions based on specific dates.

Transactions After a Certain Date

after=$(date -d '03/15/2019' +"%s")

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

Transactions Within a Date Range

before=$(date -d '11/22/2018' +"%s")

after=$(date -d '09/07/2017' +"%s")

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

Encrypt and decrypt messages

This guide demonstrates how to use Electrum’s command line interface to encrypt and decrypt messages using public key cryptography.

Getting the Public Key

First, retrieve the public key associated with a wallet address:

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

Encrypting a Message

To encrypt a message:

cat | electrum encrypt $pk -

Decrypting a Message

To decrypt a message:

electrum decrypt $pk ?

This command prompts you to enter an encrypted message, then asks for your wallet password and decrypts the message using your private key.

Export private keys and sweep coins

This guide explains how to export private keys from funded addresses in your Electrum wallet and use them to sweep coins to a new address.

Exporting Private Keys of Funded Addresses:

electrum listaddresses --funded | electrum getprivatekeys -

This will return a list of lists of private keys. In most cases, you want to get a simple list.

For a simplified list of private keys:

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

Sweeping Coins to a New Address:

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

Table of Contents