Skip to content
Switch branches/tags

Latest commit


Git stats


Failed to load latest commit information.
Latest commit message
Commit time

How to write scripts for the Electrum wallet

What is the Electrum bitcoin wallet?

Electrum wallet is a bitcoin wallet that helps you receive, store and send bitcoins. It’s a SPV client which means it doesn’t download the whole Blockchain and thus saves you a significant space on your disk.

You’ll need an Electrum wallet and some small amount of bitcoins in it for this tutorial. Download it here:

Electrum console

Electrum has a Python console for everyone who prefers the command line over the graphical interface.

Go to Electrum console and try some commands:

The first one is “the usual suspect”: help()

List of commands: contacts, create, createmultisig, createrawtransaction, daemon, decoderawtransaction, deseed, 
dumpprivkey, dumpprivkeys, freeze, getaddressbalance, getaddresshistory, getaddressunspent, getbalance, getconfig, 
getmpk, getproof, getpubkeys, getrawtransaction, getseed, getservers, getutxoaddress, getversion, help, history, 
importprivkey, listaddresses, listunspent, mksendmanytx, mktx, password, payto, paytomany, restore, sendrawtransaction, 
setconfig, setlabel, signmessage, signrawtransaction, unfreeze, validateaddress, verifymessage

help() command gives you a list of all possible commands that you can execute in the Electrum console. Let’s try another one, getbalance()

>> getbalance()
"confirmed": "0.0076"

getbalance() lets you know how much bitcoins you have in your wallet - how many of them are confirmed and how many not.

Example: Electrum script that sends bitcoins

Let’s try something more complex than just checking your wallet’s balance. Let’s say you want to send different amounts of bitcoins to different addresses. First create a CSV file that contains addresses and amounts of bitcoins, like that:


CSV means “comma separated values” so addresses and amounts are separated with comma. Those of you who use a comma for a decimal mark please use a dot instead (I’m looking at you fellow Europeans) :) Save that CSV file under the name sendlist.csv.

Next create a python script with a name First we need to open our CSV file:

import csv
input_file = csv.DictReader(open("/full/path/to/your/sendlist.csv"))

Make sure that you include the FULL path to your CSV file and not just call sendlist.csv, even if CSV is in the same folder as your python script. This will be important later when we run the script in the Electrum console.

Next we have to store addresses and amounts in the python list as tuples:

outputs = []

for row in input_file:
    tup = (row["address"], float(row["amount"]))

print outputs

With print outputs we can make sure we have the right values stored in our list.

If we don’t it’s good to have a safeguard to cancel the process before the bitcoin transaction is made. So let’s ask a user for approval:

approval = raw_input("Do you approve the transaction? (Y/N)")

If our user approves the transaction run the Electrum command that sends bitcoins to multiple addresses, called paytomany()

if approval == "Y" or approval == "y":
    transaction = paytomany(outputs, 0.0001)
    print transaction
    print("Transaction was not executed.")

paytomany() command takes two arguments: a list of addresses and amounts (outputs) and the mining fee (in this case 0.0001). Mining fee is optional but if you want your transaction to be processed quickly it is good to add it.

So now we have everything ready to run the script! Go to Electrum console and run it with the execfile() command:


Again, it’s important to include the full path to your script in order to run it. When you call the paytomany() command you’ll be asked to enter your password. After the successful transaction you get the transaction ID which you can check at

And that’s it! You can see the whole python script here:

You can also see a list of all the Electrum commands and the attributes they take here:


Electrum scripting tutorial




No releases published


No packages published