Electrum Documentation

Add to my manuals
51 Pages

advertisement

Electrum Documentation | Manualzz

Electrum Documentation

Release 2.5

Thomas Voegtlin

December 26, 2015

Contents

1 GUI and beginners

3

1.1

Frequently Asked Questions

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

3

1.2

Invoices

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

8

1.3

Two Factor Authentication

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

8

1.4

Multisig Wallets

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

11

1.5

Cold Storage

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

15

2 Command line and merchants

23

2.1

Command Line

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

23

2.2

Using cold storage with the command line

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

25

2.3

How to accept Bitcoin on a website using Electrum

. . . . . . . . . . . . . . . . . . . . . . . . . . .

26

3 For developers

33

3.1

The Python Console

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

33

3.2

Simple Payment Verification

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

34

3.3

Electrum seed phrases

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

34

3.4

Electrum protocol specification

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

35

3.5

Serialization of unsigned or partially signed transactions

. . . . . . . . . . . . . . . . . . . . . . . .

40

3.6

Build Electrum on Mac OS X

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

41

4 External Links

47

i

ii

Electrum is a lightweight Bitcoin wallet.

Electrum Documentation, Release 2.5

Contents 1

Electrum Documentation, Release 2.5

2 Contents

CHAPTER

1

GUI and beginners

1.1 Frequently Asked Questions

1.1.1 How does Electrum work?

Electrum’s focus is speed, with low resource usage and simplifying Bitcoin. Startup times are instant because it operates in conjunction with high-performance servers that handle the most complicated parts of the Bitcoin system.

1.1.2 Does Electrum trust servers?

Not really; the Electrum client never sends private keys to the servers. In addition, it verifies the information reported by servers, using a technique called

Simple Payment Verification

1.1.3 What is the Seed?

The seed is a random phrase that is used to generate your private keys.

Example: constant forest adore false green weave stop guy fur freeze giggle clock

Your wallet can be entirely recovered from its seed. For this, select the “restore wallet” option in the startup.

1.1.4 How secure is the seed?

The seed created by Electrum has 128 bits of entropy. This means that it provides the same level of security as a

Bitcoin private key (of length 256 bits). Indeed, an elliptic curve key of length n provides n/2 bits of security.

1.1.5 How can I send the maximum available in my wallet?

Type an exclamation mark (!) in the Amount field. The fee will be automatically adjusted for that amount.

3

Electrum Documentation, Release 2.5

1.1.6 How can I send Bitcoins without paying a transaction fee?

You can create a transaction with zero fee in the GUI, by following these steps:

• Activate the option ‘set fees manually’

• Enter 0 in the fee field

• Enter the amount in the amount field

Note that transactions without fees might not be relayed by the Electrum server, or by the Bitcoin Network.

1.1.7 What does it mean to “Freeze” an address in Electrum?

When you freeze an address, the funds in that address will not be used for sending bitcoins. You can not send Bitcoins if you don’t have enough funds in the non-frozen addresses.

1.1.8 What encryption is used for wallets?

Electrum uses AES-256-CBC to encrypt the seed and private keys in the wallet.

1.1.9 I have forgotten my password but still have my seed. Is there any way I can recover my password?

No, you cannot recover your password. However, you can still recover your money: restore your wallet from its seed, and choose a new password.

1.1.10 Why can I open the wallet without entering my password?

Only the seed and private keys are encrypted, and not the entire wallet file. The private keys are decrypted only briefly, when you need to sign a transaction; for this you need to enter your password. This is done in order to minimize the amount of time during which sensitive information is unencrypted in your computer’s memory.

1.1.11 Does Electrum support cold wallets?

Yes. see

Cold Storage

1.1.12 Can I import private keys from other Bitcoin clients?

In Electrum 2.0, you cannot import private keys in a wallet that has a seed. You should sweep them instead.

If you want to import private keys and not sweep them you need to create a special wallet that does not have a seed.

For this, create a new wallet, select “restore”, and instead of typing your seed, type a list of private keys, or a list of addresses if you want to create a watching-only wallet.

4 Chapter 1. GUI and beginners

Electrum Documentation, Release 2.5

You will need to back up this wallet, because it cannot be recovered from seed.

1.1.13 Can I sweep private keys from other Bitcoin clients?

Sweeping private keys means to send all the bitcoins they control to an existing address in your wallet. The private keys you sweep do not become a part of your wallet. Instead, all the bitcoins they control are sent to an address that has been deterministically generated from your wallet seed.

To sweep private keys go to Wallet menu -> Private Keys -> Sweep. Enter the private keys in the appropriate field.

Leave the ‘Address’ field unchanged. That is the destination address and it’ll be from your existing electrum wallet.

1.1.14 Where is my wallet file located?

The default wallet file is called default_wallet which is created when you first run the application and located under the /wallets folder.

On Windows:

• Show hidden files

• Go to UsersYourUserNameAppDataRoamingLocalElectrum

On Mac:

• Open Finder

1.1. Frequently Asked Questions 5

Electrum Documentation, Release 2.5

• Go to folder (shift+cmd+G) and type ~/.electrum

On Linux:

• Home Folder

• Go -> Location and type ~/.electrum

1.1.15 Can I do bulk payments with Electrum?

You can create a transaction with several outputs. In the GUI, type each address and amount on a line, separated by a comma.

Amounts are in the current unit set in the client. The total is shown in the GUI.

You can also import a CSV file in the ‘Pay to’ field, by clicking on the folder icon.

1.1.16 Can Electrum create and sign raw transactions?

Electrum lets you create and sign raw transactions right from the user interface using a form.

1.1.17 Electrum freezes when I try to send bitcoins

This might happen if you are trying to spend a large number of transactions outputs (for example, if you have collected hundreds of donations from a Bitcoin faucet). When you send Bitcoins, Electrum looks for unspent coins that are in your wallet, in order to create a new transaction. Unspent coins can have different values, much like physical coins and bills.

6 Chapter 1. GUI and beginners

Electrum Documentation, Release 2.5

If this happens, you should consolidate your transaction inputs, by sending smaller amounts of bitcoins to one of your wallet addresses; this would be the equivalent of exchanging a stack of nickels for a dollar bill.

1.1.18 Is there a way to get a BTC/USD exchange ticker in Electrum?

Yes, go to Tools->Plugins and enable ‘exchange rates’

1.1.19 What is the gap limit?

The gap limit is the maximum number of consecutive unused addresses in your deterministic sequence of addresses.

Electrum uses it in order to stop looking for addresses. In Electrum 2.0, it is set to 20 by default, so the client will get all addresses until 20 unused addresses are found.

1.1.20 How can I pre-generate new addresses?

Electrum will generate new addresses as you use them, until it hits the

gap limit

If you need to pre-generate more addresses, you can do so by typing wallet.create_new_address() in the console. This command will generate one new address. Note that the address will be shown with a red background in the address tab, to indicate that it is beyond the gap limit. The red color will remain until the gap is filled.

WARNING: Addresses beyond the gap limit will not automatically be recovered from seed. To recover them will require either increasing the client’s gap limit or generating new addresses until the used addresses are found.

If you wish to generate more than one address, you may use a ‘for’ loop. For example, if you wanted to generate 50 addresses, you could do this:

for

x

in

range ( 0 , 50 ):

print

wallet .

create_new_address()

1.1.21 How to upgrade Electrum?

Warning: always save your wallet seed on paper before doing an upgrade.

To upgrade Electrum, just install the most recent version. The way to do this will depend on your OS.

Note that your wallet files are stored separately from the software, so you can safely remove the old version of the software if your OS does not do it for you.

Some Electrum upgrades will modify the format of your wallet files.

For this reason, it is not recommended to downgrade Electrum to an older version, once you have opened your wallet file with the new version. The older version will not always be able to read the new wallet file.

The following issues should be considered when upgrading Electrum 1.x wallets to Electrum 2.x:

• Electrum 2.x will need to regenerate all of your addresses during the upgrade process. Please allow it time to complete, and expect it to take a little longer than usual for Electrum to be ready.

• The contents of your wallet file will be replaced with an Electrum 2 wallet. This means Electrum 1.x will no longer be able to use your wallet once the upgrade is complete.

• The ‘Addresses’ tab will not show any addresses the first time you launch Electrum 2. This is expected behaviour.

Restart Electrum 2 after the upgrade is complete and your addresses will be available.

1.1. Frequently Asked Questions 7

Electrum Documentation, Release 2.5

• Offline copies of Electrum will not show the addresses at all because it cannot synchronize with the network. You can force an offline generation of a few addresses by typing the following into the Console: wallet.synchronize().

When it’s complete, restart Electrum and your addresses will once again be available.

1.2 Invoices

Invoices are Payment Requests signed by their requestor.

When you click on a bitcoin: link, a URL is passed to electrum: electrum "bitcoin:1KLxqw4MA5NkG6YP1N4S14akDFCP1vQrKu?amount=1.0&r=https%3A%2F%2Fbitpay.com%2Fi%2FXxaGtEpRSqckRnhsjZwtrA"

This opens the send tab with the payment request:

The green color in the “Pay To” field means that the payment request was signed by bitpay.com’s certificate, and that

Electrum verified the chain of signatures.

Note that the “send” tab contains a list of invoices and their status.

1.3 Two Factor Authentication

Electrum offers two-factor authenticated wallets, with a remote server acting to co-sign transactions, adding another level of security in the event of your computer being compromised.

The remote server in question is a service offered by TrustedCoin. Here is a guide on how it works.

8 Chapter 1. GUI and beginners

1.3.1 Creating a Wallet

Electrum Documentation, Release 2.5

1.3. Two Factor Authentication 9

Electrum Documentation, Release 2.5

1.3.2 Restoring from seed

Even if TrustedCoin is compromised or taken offline, your coins are secure as long as you still have the seed of your wallet. Your seed contains two master private keys in a 2-of-3 security scheme. In addition, the third master public key can be derived from your seed, ensuring that your wallet addresses can be restored. In order to restore your wallet from seed, select “wallet with two factor authentication”, as this tells Electrum to use this special variety of seed for restoring your wallet.

10 Chapter 1. GUI and beginners

Electrum Documentation, Release 2.5

Note: The “restore” option should be used only if you no longer want to use TrustedCoin, or if there is a problem with the service. Once you have restored your wallet in this way, two of three factors are on your machine, negating the special protection of this type of wallet.

1.4 Multisig Wallets

This tutorial shows how to create a 2 of 2 multisig wallet. A 2 of 2 multisig consists of 2 separate wallets (usually on seperate machines and potentially controlled by seperate people) that have to be used in conjunction in order to access the funds. Both wallets have the same set of Addresses.

• A common use-case for this is if you want to collaboratively control funds: maybe you and your friend run a company together and certain funds should only be spendable if you both agree.

• Another one is security: One of the wallets can be on your main machine, while the other one is on a offline machine. That way you make it very hard for an attacker or malware to steal your coins.

1.4.1 Create a pair of 2-of-2 wallets

Each cosigner needs to do this: In the menu select File->New, then select “Multi-signature wallet”. On the next screen, select 2 of 2.

1.4. Multisig Wallets 11

Electrum Documentation, Release 2.5

After generating a seed (keep it safely!) you will need to provide the master public key of the other wallet.

12 Chapter 1. GUI and beginners

Electrum Documentation, Release 2.5

Put the master public key of the other wallet into the lower box. Of course when you create the other wallet, you put the master public key of this one.

You will need to do this in parallel for the two wallets. Note that you can press cancel during this step, and reopen the file later.

1.4.2 Receiving

Check that both wallets generate the same set of Addresses. You can now send to these Addresses (note they start with a “3”) with any wallet that can send to P2SH Addresses.

1.4.3 Spending

To spend coins from a 2-of-2 wallet, two cosigners need to sign a transaction collaboratively.

To accomplish this, create a transaction using one of the wallets (by filling out the form on the “send” tab)

After signing, a window is shown with the transaction details.

1.4. Multisig Wallets 13

Electrum Documentation, Release 2.5

The transaction has to be sent to the second wallet.

For this you have multiple options:

• you can transfer the file on a usb stick

• you can use QR codes

• you can use a remote server, with the CosignerPool plugin.

Transfer a file

You can save the partially signed transaction to a file (using the “save” button), transfer that to the machine where the second wallet is running (via usb stick, for example) and load it there (using Tools -> Load transaction -> from file)

Use QR-Code

There’s also a button showing a qr-code icon. Clicking that will display a qr-code containing the transaction that can be scanned into the second wallet (Tools -> Load Transaction -> From QR Code)

Use the Cosigner Pool Plugin

For this to work the Plugin “Cosigner Pool” needs to be enabled (Tools -> Plugins) with both wallets.

14 Chapter 1. GUI and beginners

Electrum Documentation, Release 2.5

Once the plugin is enabled, you will see a button labeled “Send to cosigner”. Clicking it sends the partially signed transaction to a central server. Note that the transaction is encrypted with your cosigner’s master public key.

When the cosigner wallet is started, it will get a notification that a partially signed transaction is available:

The transaction is encrypted with the cosigner’s master public key; the password is needed to decrypt it.

With all of the above methods, you can now add the seconds signature the the transaction (using the “sign” button). It will then be broadcast to the network.

1.5 Cold Storage

This document shows how to create an offline wallet that holds your Bitcoins and a watching-only online wallet that is used to view its history and to create transactions that have to be signed with the offline wallet before being broadcast on the online one.

1.5.1 Create an offline wallet

Create a wallet on an offline machine, as per the usual process (file -> new) etc.

After creating the wallet, go to Wallet -> Master Public Keys.

1.5. Cold Storage 15

Electrum Documentation, Release 2.5

The Master Public Key of your wallet is the string shown in this popup window. Transfer that key to your online machine somehow.

1.5.2 Create a watching-only version of your wallet

On your online machine, open up Electrum and select File -> New/Restore. Enter a name for the wallet and select

“Restore a wallet or import keys”.

16 Chapter 1. GUI and beginners

Electrum Documentation, Release 2.5

Paste your master public key in the box.

1.5. Cold Storage 17

Electrum Documentation, Release 2.5

Click Next to complete the creation of your wallet. When you’re done, you should see a popup informing you that you are opening a watching-only wallet.

Then you should see the transaction history of your cold wallet.

1.5.3 Create an unsigned transaction

Go to the “send” tab on your online watching-only wallet, input the transaction data and press “Send...”. A window opens up, informing you that a transaction fee will be added. Continue.

18 Chapter 1. GUI and beginners

Electrum Documentation, Release 2.5

In the window that opens up, press “save” and save the transaction file somewhere on your computer. Close the window and transfer the transaction file to your offline machine (e.g. with a usb stick).

1.5.4 Get your transaction signed

On your offline wallet, select Tools -> Load transaction -> From file in the menu and select the transaction file created in the previous step.

1.5. Cold Storage 19

Electrum Documentation, Release 2.5

Press “sign”. Once the transaction is signed, the Transaction ID appears in its designated field.

20 Chapter 1. GUI and beginners

Electrum Documentation, Release 2.5

Press save, store the file somewhere on your computer, and transfer it back to your online machine.

1.5.5 Broadcast your transaction

On your online machine, select Tools -> Load transaction -> From File from the menu. Select the signed transaction file. In the window that opens up, press “broadcast”. The transaction will be broadcasted over the Bitcoin network.

1.5. Cold Storage 21

Electrum Documentation, Release 2.5

22 Chapter 1. GUI and beginners

CHAPTER

2

Command line and merchants

2.1 Command Line

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

2.1.1 Using the inline help

To see the list of Electrum commands, type: electrum help

To see the documentation for a command, type: electrum help < command >

2.1.2 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 payto 1JuiT4dM65d8vBt8qUYamnDmAMJ4MjjxRE !

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 signmessage 1JuiT4dM65d8vBt8qUYamnDmAMJ4MjjxRE ?

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

electrum 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 signmessage 1JuiT4dM65d8vBt8qUYamnDmAMJ4MjjxRE -

23

Electrum Documentation, Release 2.5

2.1.3 Aliases

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

electrum payto ecdsa.net !

2.1.4 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.

2.1.5 Examples

Sign and verify message

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

$(

cat LICENCE| electrum signmessage 1JuiT4dM65d8vBt8qUYamnDmAMJ4MjjxRE -

)

And: cat LICENCE | electrum verifymessage 1JuiT4dM65d8vBt8qUYamnDmAMJ4MjjxRE $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 listunspent | jq 'map(.value)'

Select only incoming transactions from history

Incoming transactions have a positive ‘value’ field electrum history | jq '.[] | select(.value>0)'

Filter transactions by date

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

$(

date -d '07/01/2015' + "%s"

)

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

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

24 Chapter 2. Command line and merchants

Electrum Documentation, Release 2.5

before =

$(

date -d '08/01/2015' + "%s"

)

after =

$(

date -d '07/01/2015' + "%s"

)

electrum 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 getpubkeys 1JuiT4dM65d8vBt8qUYamnDmAMJ4MjjxRE| jq -r '.[0]'

)

Encrypt: cat | electrum encrypt $pk -

Decrypt: electrum 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 listaddresses --funded | electrum 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 listaddresses --funded | electrum getprivatekeys - | jq 'map(.[0])'

Finally, let us use this list of private keys as input to the sweep command: electrum listaddresses --funded | electrum getprivatekeys - | jq 'map(.[0])' | electrum sweep - 1uCMeviLYzwWh1P2gEh3R4X34ArzVUR1R

2.2 Using cold storage with the command line

This page will show you how to sign a transaction with an offline Electrum wallet, using the Command line.

2.2.1 Create an unsigned transaction

With your online (watching-only) wallet, create an unsigned transaction:</p> electrum payto 1Cpf9zb5Rm5Z5qmmGezn6ERxFWvwuZ6UCx 0.1 --unsigned > unsigned.txn

The unsigned transaction is stored in a file named ‘unsigned.txn’. Note that the –unsigned option is not needed if you use a watching-only wallet.

You may view it using:

2.2. Using cold storage with the command line 25

Electrum Documentation, Release 2.5

cat unsigned.txn | electrum deserialize -

2.2.2 Sign the transaction

The serialization format of Electrum contains the master public key needed and key derivation, used by the offline wallet to sign the transaction.</p>

Thus we only need to pass the serialized transaction to the offline wallet: cat unsigned.txn | electrum signtransaction - > signed.txn

The command will ask for your password, and save the signed transaction in ‘signed.txn’</p>

2.2.3 Broadcast the transaction

Send your transaction to the Bitcoin network, using broadcast: cat signed.txn | electrum broadcast -

If successful, the command will return the ID of the transaction.

2.3 How to accept Bitcoin on a website using Electrum

This tutorial will show you how to accept Bitcoin on a website with SSL signed payment requests. It is updated for

Electrum 2.6.

2.3.1 Requirements

• A webserver serving static HTML

• A SSL certificate (signed by a CA)

• Electrum version >= 2.6

2.3.2 Create a wallet

Create a wallet on your web server: electrum create

You can also use a watching only wallet (restored from xpub), if you want to keep private keys off the server.

Once your wallet is created, start Electrum as a daemon: electrum daemon start

26 Chapter 2. Command line and merchants

Electrum Documentation, Release 2.5

2.3.3 Add your SSL certificate to your configuration

You should have a private key and a public certificate for your domain.

Create a file that contains only the private key:

-----BEGIN PRIVATE KEY----your private key

-----BEGIN END KEY-----

Set the path to your the private key file with setconfig: electrum setconfig ssl_privkey /path/to/ssl.key

Create another file, file that contains your certificate, and the list of certificates it depends on, up to the root CA. Your certificate must be at the top of the list, and the root CA at the end.

-----BEGIN CERTIFICATE----your cert

-----END CERTIFICATE-----

-----BEGIN CERTIFICATE----intermediate cert

-----END CERTIFICATE-----

-----BEGIN CERTIFICATE----root cert

-----END CERTIFICATE-----

Set the ssl_chain path with setconfig: electrum setconfig ssl_chain /path/to/ssl.chain

2.3.4 Configure a requests directory

This directory must be served by your webserver (eg Apache) electrum setconfig requests_dir /var/www/r/

By default, electrum will display local URLs, starting with ‘file://‘ In order to display public URLs, we need to set another configuration variable, url_rewrite. For example: electrum setconfig url_rewrite "['file:///var/www/','https://electrum.org/']"

2.3.5 Create a signed payment request

electrum addrequest 3.14 -m "this is a test"

{

"URI" : "bitcoin:1MP49h5fbfLXiFpomsXeqJHGHUfNf3mCo4?amount=3.14&r=https://electrum.org/r/7c2888541a" ,

"address" : "1MP49h5fbfLXiFpomsXeqJHGHUfNf3mCo4" ,

"amount" : 314000000,

"amount (BTC)" : "3.14" ,

"exp" : 3600,

"id" : "7c2888541a" ,

"index_url" : "https://electrum.org/r/index.html?id=7c2888541a" ,

"memo" : "this is a test" ,

"request_url" : "https://electrum.org/r/7c2888541a" ,

"status" : "Pending" ,

"time" : 1450175741

}

2.3. How to accept Bitcoin on a website using Electrum 27

Electrum Documentation, Release 2.5

This command returns a json object with two URLs:

• request_url is the URL of the signed BIP70 request.

• index_url is the URL of a webpage displaying the request.

Note that request_url and index_url use the domain name we defined in url_rewrite.

You can view the current list of requests using the ‘listrequests’ command.

2.3.6 Open the payment request page in your browser

Let us open index_url in a web browser.

28 Chapter 2. Command line and merchants

Electrum Documentation, Release 2.5

The page shows the payment request. You can open the bitcoin: URI with a wallet, or scan the QR code. The bottom line displays the time remaining until the request expires.

2.3. How to accept Bitcoin on a website using Electrum 29

Electrum Documentation, Release 2.5

This page can already used to receive payments. However, it will not detect that a request has been paid; for that we need to configure websockets

2.3.7 Add web sockets support

Get SimpleWebSocketServer from here: git clone https://github.com/ecdsa/simple-websocket-server.git

Set websocket_server in your config: electrum setconfig websocket_server <FQDN of your server>

And restart the daemon: electrum daemon stop electrum daemon start

Now, the page is fully interactive: it will update itself when the payment is received.

2.3.8 JSONRPC interface

Commands to the Electrum daemon can be sent using JSONRPC. This is useful if you want to use electrum in a PHP script.

30 Chapter 2. Command line and merchants

Electrum Documentation, Release 2.5

Note that the daemon uses a random port number by default. In order to use a stable port number, you need to set the

‘rpcport’ configuration variable (and to restart the daemon): electrum setconfig rpcport 7777

With this setting, we can perform queries using curl or PHP. Example: curl --data-binary '{"id":"curltext","method":"getbalance","params":[]}' http://127.0.0.1:7777

Query with named parameters: curl --data-binary '{"id":"curltext","method":"listaddresses","params":{"funded":true}}' http://127.0.0.1:7777

Create a payment request: curl --data-binary '{"id":"curltext","method":"addrequest","params":{"amount":"3.14","memo":"test"}}' http://127.0.0.1:7777

2.3. How to accept Bitcoin on a website using Electrum 31

Electrum Documentation, Release 2.5

32 Chapter 2. Command line and merchants

CHAPTER

3

For developers

3.1 The Python Console

Most Electrum commands are available not only using the command-line, but also in the GUI Python console.

The results are Python objects, even though they are sometimes rendered as JSON for clarity.

Let us call listunspent(), to see the list of unspent outputs in the wallet:

>> listunspent()

[

{

"address" : "12cmY5RHRgx8KkUKASDcDYRotget9FNso3" ,

"index" : 0 ,

"raw_output_script" : "76a91411bbdc6e3a27c44644d83f783ca7df3bdc2778e688ac" ,

"tx_hash" : "e7029df9ac8735b04e8e957d0ce73987b5c9c5e920ec4a445130cdeca654f096" ,

"value" : 0.01

},

{

"address" : "1GavSCND6TB7HuCnJSTEbHEmCctNGeJwXF" ,

"index" : 0 ,

"raw_output_script" : "76a914aaf437e25805f288141bfcdc27887ee5492bd13188ac" ,

"tx_hash" : "b30edf57ca2a31560b5b6e8dfe567734eb9f7d3259bb334653276efe520735df" ,

"value" : 9.04735316

]

}

Note that the result is rendered as JSON. However, if we save it to a Python variable, it is rendered as a Python object:

>> u = listunspent()

>> u

[{ 'tx_hash' : u'e7029df9ac8735b04e8e957d0ce73987b5c9c5e920ec4a445130cdeca654f096' , 'index' : 0 , 'raw_output_script' : '76a91411bbdc6e3a27c44644d83f783ca7df3bdc2778e688ac' , 'value' : 0.01

, 'address' : '12cmY5RHRgx8KkUKASDcDYRotget9FNso3' }, { 'tx_hash' : u'b30edf57ca2a31560b5b6e8dfe567734eb9f7d3259bb334653276efe520735df' , 'index' : 0 , 'raw_output_script' : '76a914aaf437e25805f288141bfcdc27887ee5492bd13188ac' , 'value' : 9.04735316

, 'address' : '1GavSCND6TB7HuCnJSTEbHEmCctNGeJwXF' }]

This makes it possible to combine Electrum commands with Python. For example, let us pick only the addresses in the previous result:

>> map (

lambda

x:x .

get( 'address' ), listunspent())

[

"12cmY5RHRgx8KkUKASDcDYRotget9FNso3" ,

]

"1GavSCND6TB7HuCnJSTEbHEmCctNGeJwXF"

Here we combine two commands, listunspent and dumpprivkeys, in order to dump the private keys of all adresses that have unspent outputs:

33

Electrum Documentation, Release 2.5

>> dumpprivkeys( map (

lambda

x:x .

get( 'address' ), listunspent()) )

{

"12cmY5RHRgx8KkUKASDcDYRotget9FNso3" : "***************************************************" ,

}

"1GavSCND6TB7HuCnJSTEbHEmCctNGeJwXF" : "***************************************************"

Note that dumpprivkey will ask for your password if your wallet is encrypted. The GUI methods can be accessed through the gui variable. For example, you can display a QR code from a string using gui.show_qrcode. Example: gui .

show_qrcode(dumpprivkey(listunspent()[ 0 ][ 'address' ]))

3.2 Simple Payment Verification

Simple Payment Verification (SPV) is a technique described in Satoshi Nakamoto’s paper. SPV allows a lightweight client to verify that a transaction is included in the Bitcoin blockchain, without downloading the entire blockchain.

The SPV client only needs download the block headers, which are much smaller than the full blocks. To verify that a transaction is in a block, a SPV client requests a proof of inclusion, in the form of a Merkle branch.

SPV clients offer more security than web wallets, because they do not need to trust the servers with the information they send.

Reference: Bitcoin: A peer-to-peer Electronic Cash System

3.3 Electrum seed phrases

Note: Electrum is not compatible with BIP39.

Electrum uses a seed phrase made of natural language words in order to derive wallet private keys.

In order to derive the keys in a way that does not depend on the wordlist, Electrum uses a hash of the UTF8 normalized seed phrase. That part is similar to BIP39. However, the checksum mechanism is different. BIP39 requires a predetermined wordlist in order to compute the checksum. In contrast, Electrum uses another hash of the seed phrase.

That hash is used both as a checksum and as a version number.

3.3.1 Seed phrase normalization

normalized_seedphrase = mnemonic.prepare_seed(seed_phrase)

Note that the normalization function removes diacritics and also spaces between asian CJK characters (this differs from bip39).

3.3.2 Checksum and version number

The following hash is used: s = hmac_sha_512(“Seed version”, normalized_seedphrase)

The first bits of s (prefix) must be in a list of accepted prefixes.

The length of the prefix is given by the first 4 bits of the prefix: length = 8 + 4*n

34 Chapter 3. For developers

Electrum Documentation, Release 2.5

3.3.3 List of reserved prefixes

• 0x01 -> standard wallet (single account)

• 0x101 -> two-factor authentication wallet (long seed used to derive two master keys)

3.3.4 Entropy loss

The seed generation requires to find a seed that has a legal version prefix. That constraint results in a loss of entropy.

This loss is compensated by adding extra bits of entropy during the seed generation.

3.3.5 Length of the seed phrase

In order to generate a seedphrase with 128 bits of entropy and 8 bits of prefix, a wordlist of 2048 words will typically use 13 words.

It is possible to fall back to 12 words seedphrases by making the wordlist longer (about 2600 words are needed)

3.4 Electrum protocol specification

Stratum is a universal bitcoin communication protocol used mainly by bitcoin client Electrum and miners.

3.4.1 Format

Stratum protocol is based on JSON-RPC 2.0

(although it doesn’t include “jsonrpc” information in every message).

Each message has to end with a line end character (n).

Request

Typical request looks like this:

{

"id"

: 0 ,

"method"

: "some.stratum.method" ,

"params"

: [] }

• id begins at 0 and every message has its unique id number

• list and description of possible methods is below

• params is an array, e.g.: [ “1myfirstaddress”, “1mysecondaddress”, “1andonemoreaddress” ]

Response

Responses are similar:

{

"id"

: 0 ,

"result"

: "616be06545e5dd7daec52338858b6674d29ee6234ff1d50120f060f79630543c" }

• id is copied from the request message (this way client can pair each response to one of his requests)

• result can be:

– null

– a string (as shown above)

3.4. Electrum protocol specification 35

Electrum Documentation, Release 2.5

– a hash, e.g.:

{

"nonce"

: 1122273605 ,

"timestamp"

: 1407651121 ,

"version"

: 2 ,

"bits"

: 406305378 }

– an array of hashes, e.g.:

[ { "tx_hash:

"b87bc42725143f37558a0b41a664786d9e991ba89d43a53844ed7b3752545d4f",

"height": 314847 }, { "tx_hash":

"616be06545e5dd7daec52338858b6674d29ee6234ff1d50120f060f79630543c",

"height": 314853 } ]

3.4.2 Methods

server.version

This is usually the first client’s message, plus it’s sent every minute as a keep-alive message. Client sends its own version and version of the protocol it supports. Server responds with its supported version of the protocol (higher number at server-side is usually compatible).

request:

{

"id"

: 0 ,

"method"

: "server.version" ,

"params"

: [ "1.9.5" , "0.6" ] } response:

{

"id"

: 0 ,

"result"

: "0.8" }

server.banner

request:

{

"id"

: 1 ,

"method"

: "server.banner" ,

"params"

: [] }

server.donation_address

server.peers.subscribe

Client can this way ask for a list of other active servers. Servers are connected to an IRC channel (#electrum at freenode.net) where they can see each other. Each server announces its version, history pruning limit of every address

(“p100”, “p10000” etc.–the number means how many transactions the server may keep for every single address) and supported protocols (“t” = tcp@50001 , “h” = http@8081 , “s” = tcp/tls@50002 , “g” = https@8082 ; non-standard port would be announced this way: “t3300” for tcp on port 3300).

Note: At the time of writing there isn’t a true subscription implementation of this method, but servers only send one-time response. They don’t send notifications yet.

request:

{ "id": 3, "method":

"server.peers.subscribe", "params": [] }<br/> response:

36 Chapter 3. For developers

Electrum Documentation, Release 2.5

{

"id"

: 3 ,

"result"

: [ [ "83.212.111.114" ,

"electrum.stepkrav.pw" , [ "v0.9" , "p100" , "t" , "h" , "s" ,

"g" ] ], [ "23.94.27.149" , "ultra-feather.net" , [ "v0.9" ,

"p10000" , "t" , "h" , "s" , "g" ] ], [ "88.198.241.196" ,

"electrum.be" , [ "v0.9" , "p10000" , "t" , "h" , "s" , "g" ] ] ]

}

blockchain.numblocks.subscribe

A request to send to the client notifications about new blocks height. Responds with the current block height.

request:

{

"id"

: 5 ,

"method"

:

"blockchain.numblocks.subscribe" ,

"params"

: [] } response:

{

"id"

: 5 ,

"result"

: 316024 } message:

{

"id"

:

null

,

"method"

:

"blockchain.numblocks.subscribe" ,

"params"

: 316024 }

blockchain.headers.subscribe

A request to send to the client notifications about new blocks in form of parsed blockheaders.

request:

{

"id"

: 5 ,

"method"

:

"blockchain.headers.subscribe" ,

"params"

: [] } response:

{

"id"

: 5 ,

"result"

: {

"nonce"

:

3355909169 ,

"prev_block_hash"

:

"00000000000000002b3ef284c2c754ab6e6abc40a0e31a974f966d8a2b4d5206" ,

"timestamp"

: 1408252887 ,

"merkle_root"

:

"6d979a3d8d0f8757ed96adcd4781b9707cc192824e398679833abcb2afdf8d73" ,

"block_height"

: 316023 ,

"utxo_root"

:

"4220a1a3ed99d2621c397c742e81c95be054c81078d7eeb34736e2cdd7506a03" ,

"version"

: 2 ,

"bits"

: 406305378 } } message:

{

"id"

:

null

,

"method"

:

"blockchain.headers.subscribe" ,

"params"

: [ {

"nonce"

:

881881510 ,

"prev_block_hash"

:

"00000000000000001ba892b1717690900ae476857120a78fb50825f8b67a42d4" ,

"timestamp"

: 1408255430 ,

"merkle_root"

:

"8e92bdbf1c5c581b5942fc290c6c52c586f091b279ea79d4e21460e138023839" ,

"block_height"

: 316024 ,

"utxo_root"

:

"060f780c0dd07c4289aaaa2ef24723f73380095b31d60795e1308170ec742ffb" ,

"version"

: 2 ,

"bits"

: 406305378 } ] }

3.4. Electrum protocol specification 37

Electrum Documentation, Release 2.5

blockchain.address.subscribe

A request to send to the client notifications when status (i.e., transaction history) of the given address changes. Status is a hash of the transaction history. If there isn’t any transaction for the address yet, the status is null.

request:

{

"id"

: 6 ,

"method"

: "blockchain.address.subscribe" ,

"params"

: [ "1NS17iag9jJgTHD1VXjvLCEnZuQ3rJDE9L" ] } response:

{

"id"

: 6 ,

"result"

: "b87bc42725143f37558a0b41a664786d9e991ba89d43a53844ed7b3752545d4f" } message:

{

"id"

:

null

,

"method"

: "blockchain.address.subscribe" ,

"params"

: [ "1NS17iag9jJgTHD1VXjvLCEnZuQ3rJDE9L" , "690ce08a148447f482eb3a74d714f30a6d4fe06a918a0893d823fd4aca4df580" ]}

blockchain.address.get_history

request:

{

"id"

: 1 ,

"method"

:

"blockchain.address.get_history" ,

"params"

:

[ "1NS17iag9jJgTHD1VXjvLCEnZuQ3rJDE9L" ] } response:

{

"id"

: 1 ,

"result"

: [{

"tx_hash"

:

"ac9cd2f02ac3423b022e86708b66aa456a7c863b9730f7ce5bc24066031fdced" ,

"height"

: 340235 }, {

"tx_hash"

:

"c4a86b1324f0a1217c80829e9209900bc1862beb23e618f1be4404145baa5ef3" ,

"height"

: 340237 }]}

blockchain.address.get_mempool

blockchain.address.get_balance

request:

{

"id"

: 1 ,

"method"

: "blockchain.address.get_balance" ,

"params"

:[ "1NS17iag9jJgTHD1VXjvLCEnZuQ3rJDE9L" ] } response:

{

"id"

: 1 ,

"result"

: {

"confirmed"

: 533506535 ,

"unconfirmed"

: 27060000 }}

blockchain.address.get_proof

blockchain.address.listunspent

request:

{ "id": 1, "method":

"blockchain.address.listunspent", "params":

["1NS17iag9jJgTHD1VXjvLCEnZuQ3rJDE9L"] }<br/> response:

38 Chapter 3. For developers

Electrum Documentation, Release 2.5

{

"id"

: 1 ,

"result"

: [{

"tx_hash"

:

"561534ec392fa8eebf5779b233232f7f7df5fd5179c3c640d84378ee6274686b" ,

"tx_pos"

: 0 ,

"value"

: 24990000 ,

"height"

: 340242 },

{

"tx_hash"

: "620238ab90af02713f3aef314f68c1d695bbc2e9652b38c31c025d58ec3ba968" ,

"tx_pos"

: 1 ,

"value"

: 19890000 ,

"height"

: 340242 }]}

blockchain.utxo.get_address

blockchain.block.get_header

blockchain.block.get_chunk

blockchain.transaction.broadcast

Submits raw transaction (serialized, hex-encoded) to the network. Returns transaction id, or an error if the transaction is invalid for any reason.

request:

{ "id": 1, "method":

"blockchain.transaction.broadcast", "params":

"0100000002f327e86da3e66bd20e1129b1fb36d07056f0b9a117199e759396526b8f3a20780000000000fffffffff0ede03d75050f20801d50358829ae02c058e8677d2cc74df51f738285013c260000000000ffffffff02f028d6dc010000001976a914ffb035781c3c69e076d48b60c3d38592e7ce06a788ac00ca9a3b000000001976a914fa5139067622fd7e1e722a05c17c2bb7d5fd6df088ac00000000" }<br/> response:

{

"id"

: 1 ,

"result"

: "561534ec392fa8eebf5779b233232f7f7df5fd5179c3c640d84378ee6274686b" }

blockchain.transaction.get_merkle

blockchain.transaction.get_merkle [$txid, $txHeight]

blockchain.transaction.get

Method for obtaining raw transaction (hex-encoded) for given txid. If the transaction doesn’t exist, an error is returned.

request:

{

"id"

: 17 ,

"method"

: "blockchain.transaction.get" ,

"params"

: [

"0e3e2357e806b6cdb1f70b54c3a3a17b6714ee1f0e68bebb44a74b1efd512098"

] } response:

{

"id"

: 17 ,

"result"

: "01000000010000000000000000000000000000000000000000000000000000000000000000ffffffff0704ffff001d0104ffffffff0100f2052a0100000043410496b538e853519c726a2c91e61ec11600ae1390813a627c66fb8be7947be63c52da7589379515d4e0a604f8141781e62294721166bf621e73a82cbf2342c858eeac00000000" } error:

{

"id"

: 17 ,

"error"

: "{ u'message': u'No information available about transaction', u'code': -5 }" }

blockchain.estimatefee

Estimates the transaction fee per kilobyte that needs to be paid for a transaction to be included within a certain number of blocks. Parameter: How many blocks the transaction may wait before being included

If the node doesn’t have enough information to make an estimate, the value -1 will be returned

3.4. Electrum protocol specification 39

Electrum Documentation, Release 2.5

request:

{

"id"

: 17 ,

"method"

: "blockchain.estimatefee" ,

"params"

: 6 } response:

{

"id"

: 17 ,

"result"

: 0.00026809

}

3.4.3 External links

• https://docs.google.com/a/palatinus.cz/document/d/17zHy1SUlhgtCMbypO8cHgpWH73V5iUQKk_0rWvMqSNs/edit?hl=en_US ” original Slush’s specification of Stratum protocol

• http://mining.bitcoin.cz/stratum-mining specification of Stratum mining extension

3.5 Serialization of unsigned or partially signed transactions

Electrum 2.0 uses an extended serialization format for transactions. The purpose of this format is to send unsigned and partially signed transactions to cosigners or to cold storage.

This is achieved by extending the ‘pubkey’ field of a transaction input.

3.5.1 Extended public keys

The first byte of the pubkey indicates if it is an extended pubkey:

• 0x02, 0x03, 0x04: legal Bitcoin public key (compressed or not).

• 0xFF, 0xFE, 0xFD: extended public key.

Extended public keys are of 3 types:

• 0xFF: bip32 xpub and derivation

• 0xFE: legacy electrum derivation: master public key + derivation

• 0xFD: unknown pubkey, but we know the Bitcoin address.

3.5.2 Public key

This is the legit Bitcoin serialization of public keys.

0x02 or 0x03 compressed public key (32 bytes)

0x04 uncompressed public key (64 bytes)

3.5.3 BIP32 derivation

0xFF xpub (78 bytes) bip32 derivation (2*k bytes)

3.5.4 Legacy Electrum Derivation

0xFE mpk (64 bytes) derivation (4 bytes)

40 Chapter 3. For developers

Electrum Documentation, Release 2.5

3.5.5 Bitcoin address

Used if we don’t know the public key, but we know the address (or the hash 160 of the output script). The cosigner should know the public key.

0xFD hash_160_of_script (20 bytes)

3.6 Build Electrum on Mac OS X

<li class=”toclevel-1 tocsection-1”><a href=”#Compile_Electrum_.28master.29_on_a_fresh_MacOS_X_Yosemite_.2810.10.5.29_install”>1

Compile Electrum (master) on a fresh MacOS X Yosemite (10.10.5) install</a>

<ul>

<li class=”toclevel-2 tocsection-2”><a href=”#Install_Brew_.28http:.2F.2Fbrew.sh.29”>1.1

Install Brew ( http://brew.sh

)</a></li>

<li class=”toclevel-2 tocsection-3”><a href=”#Update_brew”>1.2 Update brew</a></li>

<li class=”toclevel-2 tocsection-4”><a href=”#Install_python_.28and_thus_pip.29_and_pyqt-4”>1.3

Install python (and thus pip) and pyqt-4</a></li>

<li class=”toclevel-2 tocsection-5”><a href=”#Clone_Electrum_from_the_official_git_repository”>1.4

Clone Electrum from the official git repository</a></li>

<li class=”toclevel-2 tocsection-6”><a href=”#Install_the_Electrum_module.28s.29”>1.5

Install the Electrum module(s)</a></li>

<li class=”toclevel-2 tocsection-7”><a href=”#You_may_want_to_add_the_following_modules_as_well”>1.6

You may want to add the following modules as well</a></li>

<li class=”toclevel-2 tocsection-8”><a href=”#Link_all_apps”>1.7 Link all apps</a></li>

<li class=”toclevel-2 tocsection-9”><a href=”#Generate_icons”>1.8 Generate icons</a></li>

<li class=”toclevel-2 tocsection-10”><a href=”#Compile_the_Electrum_application”>1.9

Compile the Electrum application</a></li>

<li class=”toclevel-2 tocsection-11”><a href=”#Build_the_dmg_container”>1.10 Build the dmg container</a></li>

</li>

</ul>

<li class=”toclevel-1 tocsection-12”><a href=”#Things_that_need_to_be_fixed_atm”>2 Things that need to be fixed atm</a> <ul>

<li class=”toclevel-2 tocsection-13”><a href=”#Incorrect_ca_path”>2.1 Incorrect ca_path</a></li>

<li class=”toclevel-2 tocsection-14”><a href=”#Invalid_DEFAULT_CA_BUNDLE_PATH”>2.2 Invalid

DEFAULT_CA_BUNDLE_PATH</a></li>

<li class=”toclevel-2 tocsection-15”><a href=”#Crash_when_clicking_on_the_qrcode_icon_in_the_.E2.80.9CPay_to.E2.80.9D_field_of_the_.E2.80.9CSend.E2.80.9D_tab”>2.3

Crash when clicking on the qrcode icon in the “Pay to” field of the “Send” tab</a></li>

3.6. Build Electrum on Mac OS X 41

Electrum Documentation, Release 2.5

<li class=”toclevel-2 tocsection-16”><a href=”#Plot_History_plugin_doesn.E2.80.99t_work”>2.4

Plot History plugin doesn’t work</a></li>

<li class=”toclevel-2 tocsection-17”><a href=”#Preference_panel_does_not_work”>2.5

Preference panel does not work</a></li>

<li class=”toclevel-2 tocsection-18”><a href=”#.5BErrno_20.5D_Not_a_directory”>2.6 [Errno

20] Not a directory</a></li>

<li class=”toclevel-2 tocsection-19”><a href=”#Audio_MODEM”>2.7 Audio MODEM</a></li>

</li>

</ul>

<li class=”toclevel-1 tocsection-20”><a href=”#Other_patches_.28optionals.29:”>3 Other patches

(optionals):</a> <ul>

<li class=”toclevel-2 tocsection-21”><a href=”#Privacy_headers_url”>3.1 Privacy headers_url</a></li>

<li class=”toclevel-2 tocsection-22”><a href=”#Privacy_DEFAULT_SERVERS”>3.2 Privacy

DEFAULT_SERVERS</a></li>

</ul>

</li>

</ul>

</div>

<h1>Compile Electrum (master) on a fresh MacOS X Yosemite (10.10.5) install[<a href=” http://electrum.orain.org/w/index.php?title=Build_Electrum_on_Mac_OS_X&amp;action=edit&amp;section=1 ” title=”Edit section: Compile Electrum (master) on a fresh MacOS X Yosemite (10.10.5) install”>edit</a>]</h1>

<h2>Install Brew (<a class=”external free” href=” http://brew.sh/ ” rel=”nofollow”>http://brew.sh</a>)[<a href=” http://electrum.orain.org/w/index.php?title=Build_Electrum_on_Mac_OS_X&amp;action=edit&amp;section=2 ” title=”Edit section: Install Brew ( http://brew.sh

)”>edit</a>]</h2>

<pre>ruby -e “$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install )”</pre>

<h2>Update brew[<a href=” http://electrum.orain.org/w/index.php?title=Build_Electrum_on_Mac_OS_X&amp;action=edit&amp;section=3 ” title=”Edit section: Update brew”>edit</a>]</h2>

<pre>brew update</pre>

<h2>Install python (and thus pip) and pyqt-4[<a href=” http://electrum.orain.org/w/index.php?title=Build_Electrum_on_Mac_OS_X&amp;action=edit&amp;section=4 ” title=”Edit section: Install python (and thus pip) and pyqt-4”>edit</a>]</h2>

<pre>brew install python pyqt</pre>

<h2>Clone Electrum from the official git repository[<a href=” http://electrum.orain.org/w/index.php?title=Build_Electrum_on_Mac_OS_X&amp;action=edit&amp;section=5 ” title=”Edit section: Clone Electrum from the official git repository”>edit</a>]</h2>

<pre>git clone https://github.com/spesmilo/electrum.git

cd electrum</pre>

<h2>Install the Electrum module(s)[<a href=” http://electrum.orain.org/w/index.php?title=Build_Electrum_on_Mac_OS_X&amp;action=edit&amp;section=6 ” title=”Edit section: Install the Electrum module(s)”>edit</a>]</h2>

<pre>python setup.py sdist

42 Chapter 3. For developers

Electrum Documentation, Release 2.5

pip install –pre dist/Electrum* tar.gz</pre>

<h2>You may want to add the following modules as well[<a href=” http://electrum.orain.org/w/index.php?title=Build_Electrum_on_Mac_OS_X&amp;action=edit&amp;section=7 ” title=”Edit section: You may want to add the following modules as well”>edit</a>]</h2>

<p>‘#’ are optionals</p>

<pre>brew install gmp zbar # Required for gmpy (pip) and zbar (pip) pip install certifi cffi configparser crypto cryptography dnspython ecdsa gi gmpy html http jsonrpclib mercurial numpy ordereddict packaging pip ply pyOpenSSL pyasn1 pyasn1-modules pycparser pycrypto setuptools setuptools-svn simplejson wincertstore zbar # Some might be optional pip install cython trezor # Trezor support, only these two are needed (no need to have limbs or pyusb)

#brew install homebrew/python/matplotlib # Required for Plot History (do not install via pip or Electrum will not compile) brew install homebrew/python/pillow # Needed for PIL imports as PIL is now depreciated (do not install via pip or Electrum will not compile) # pip install amodem # Audio Modem plugin (does not work for OS X)</pre>

<h2>Link all apps[<a href=” http://electrum.orain.org/w/index.php?title=Build_Electrum_on_Mac_OS_X&amp;action=edit&amp;section=8 ” title=”Edit section: Link all apps”>edit</a>]</h2>

<pre>brew linkapps</pre>

<h2>Generate icons[<a href=” http://electrum.orain.org/w/index.php?title=Build_Electrum_on_Mac_OS_X&amp;action=edit&amp;section=9 ” title=”Edit section: Generate icons”>edit</a>]</h2>

<pre>pyrcc4 icons.qrc -o gui/qt/icons_rc.py</pre>

<h2>Compile the Electrum application[<a href=” http://electrum.orain.org/w/index.php?title=Build_Electrum_on_Mac_OS_X&amp;action=edit&amp;section=10 ” title=”Edit section: Compile the Electrum application”>edit</a>]</h2>

<pre>ARCHFLAGS=”-arch i386 -arch x86_64” sudo python setup-release.py py2app –includes sip</pre>

<h2>Build the dmg container[<a href=” http://electrum.orain.org/w/index.php?title=Build_Electrum_on_Mac_OS_X&amp;action=edit&amp;section=11 ” title=”Edit section: Build the dmg container”>edit</a>]</h2>

<pre>sudo hdiutil create -fs HFS+ -volname “Electrum” -srcfolder dist/Electrum.app dist/electrum-

VERSION-macosx.dmg</pre>

<hr/>

<h1>Things that need to be fixed atm[<a href=” http://electrum.orain.org/w/index.php?title=Build_Electrum_on_Mac_OS_X&amp;action=edit&amp;section=12 ” title=”Edit section: Things that need to be fixed atm”>edit</a>]</h1>

<h2>Incorrect ca_path[<a href=” http://electrum.orain.org/w/index.php?title=Build_Electrum_on_Mac_OS_X&amp;action=edit&amp;section=13 ” title=”Edit section: Incorrect ca path”>edit</a>]</h2>

<p>IN paymentrequest.py, line 44:</p>

<pre>ca_path = requests.certs.where()</pre>

<p>FIX: Which can be patched with (temporary and dirty solution):</p>

<pre>#!/bin/sh echo “[...] Patching: cacert.pem” cp -f build/bdist.macosx-

*

/python2.7-standalone/app/collect/certifi/cacert.pem dist/Electrum.app/Contents/Resources/lib/python2.7/

&amp;&amp;chmod 755 dist/Electrum.app/Contents/Resources/lib/python2.7/cacert.pem

&amp;&amp;sed -i.bak

“s/requests.certs.where()/os.path.join(os.path.dirname(__file__), ‘../cacert.pem’)/g” dist/Electrum.app/Contents/Resources/lib/python2.7/lib/paymentrequest.py

&amp;&amp;rm -f

3.6. Build Electrum on Mac OS X 43

Electrum Documentation, Release 2.5

dist/Electrum.app/Contents/Resources/lib/python2.7/lib/paymentrequest.py.bak

&amp;&amp;echo “[OK] Patch applied successfully”</pre>

<p>A proper solution would be to investigate how ca_path is obtained.</p>

<p>It’s the way py2app packages the libs but I don’t know how to change that to have a directory instead of a zip archive.

Similar issue also reported here: <a class=”external free” href=” http://stackoverflow.com/questions/28073033/running-pytest-on-module-inside-sitepackages-zip ” rel=”nofollow”>http://stackoverflow.com/questions/28073033/running-pyteston-module-inside-site-packages-zip</a>

</p>

<h2>Invalid DEFAULT_CA_BUNDLE_PATH[<a href=” http://electrum.orain.org/w/index.php?title=Build_Electrum_on_Mac_OS_X&amp;action=edit&amp;section=14 ” title=”Edit section: Invalid DEFAULT CA BUNDLE PATH”>edit</a>]</h2>

<p>IN electrum.py, line 403:</p>

<pre>assert os.path.exists(requests.utils.DEFAULT_CA_BUNDLE_PATH)</pre>

<p>FIX: Can be fixed by commenting the line (which is a temporary and dirty solution). A correct solution is to dig where the DEFAULT_CA_BUNDLE_PATH is set and correct it.</p>

<pre>#!/bin/sh echo “[...] Patching: DEFAULT_CA_BUNDLE_PATH” sed -i.bak

“s/assert * os.path.exists(requests.utils.DEFAULT_CA_BUNDLE_PATH)/#assert os.path.exists(requests.utils.DEFAULT_CA_BUNDLE_PATH)/g” dist/Electrum.app/Contents/Resources/electrum.py

&amp;&amp;rm -f dist/Electrum.app/Contents/Resources/electrum.py.bak &amp;&amp;echo “[OK] Patch applied successfully”</pre>

<h2>Crash when clicking on the qrcode icon in the “Pay to” field of the “Send” tab[<a href=” http://electrum.orain.org/w/index.php?title=Build_Electrum_on_Mac_OS_X&amp;action=edit&amp;section=15 ” title=”Edit section: Crash when clicking on the qrcode icon in the “Pay to” field of the “Send” tab”>edit</a>]</h2>

<p>FIX: Remove this feature to scan QR-Codes because it does not work on OSX.</p>

<h2>Plot History plugin doesn’t work[<a href=” http://electrum.orain.org/w/index.php?title=Build_Electrum_on_Mac_OS_X&amp;action=edit&amp;section=16 ” title=”Edit section: Plot History plugin doesn’t work”>edit</a>]</h2>

<p>The Plot History plugin does not work properly.</p>

<p>In “Export History”, when clicking on “Preview plot”:</p>

<pre>Jul 21 12:02:00 dev.local electrum[61643] &lt;Notice&gt;: Traceback (most recent call last):

Jul 21 12:02:00 dev.local

electrum[61643] &lt;Notice&gt;: File ”./Electrum.app/Contents/Resources/lib/python2.7/plugins/plot.py”, line 42, in &lt;lambda&gt; Jul 21 12:02:00 dev.local

electrum[61643] &lt;Notice&gt;: b.clicked.connect(lambda: self.do_plot(self.wallet, history)) Jul 21 12:02:00 dev.local electrum[61643] &lt;Notice&gt;: File ”./Electrum.app/Contents/Resources/lib/python2.7/plugins/plot.py”, line 58, in do_plot Jul 21 12:02:00 dev.local electrum[61643] &lt;Notice&gt;: tx_hash, confirmations, value, timestamp = item Jul 21 12:02:00 dev.local electrum[61643] &lt;Notice&gt;: ValueError: too many values to unpack</pre>

<p>FIX:&nbsp;???</p>

<h2>Preference panel does not work[<a href=” http://electrum.orain.org/w/index.php?title=Build_Electrum_on_Mac_OS_X&amp;action=edit&amp;section=17 ” title=”Edit section: Preference panel does not work”>edit</a>]</h2>

<p>The application crashes with “terminated by signal SIGSEGV (Address boundary error)”.</p>

<p>Crash is due to this import (OS X does not seem to support video at all for qrscanner):</p>

44 Chapter 3. For developers

Electrum Documentation, Release 2.5

<pre>from electrum import qrscanner</pre>

<p>FIX:</p>

<pre>#!/bin/sh echo “[...] Patching: Preference pane (qrscanner)” sed -i.bak -n -e ‘/^ def *read_tx_from_qrcode(self):/{‘ -e ‘p’ -e ‘:a’ -e ‘N’ -e ‘/self.show_transaction(tx)/!ba’ -e ‘s/.n/ return #/’ -e ‘}’ -e ‘p’ dist/Electrum.app/Contents/Resources/lib/python2.7/gui/qt/main_window.py &amp;&amp;sed

-i.bak -n -e ‘/^ from *electrum *import *qrscanner/{‘ -e ‘:a’ -e ‘N’ -e ‘/gui_widgets.append((qr_label,

*qr_combo))/!ba’ -e ‘s/.

n/#/’ -e ‘}’ -e ‘p’ dist/Electrum.app/Contents/Resources/lib/python2.7/gui/qt/main_window.py

&amp;&amp;rm -f dist/Electrum.app/Contents/Resources/lib/python2.7/gui/qt/main_window.py.bak

&amp;&amp;echo “[OK] Patch applied successfully”</pre>

<h2>[Errno 20] Not a directory[<a href=” http://electrum.orain.org/w/index.php?title=Build_Electrum_on_Mac_OS_X&amp;action=edit&amp;section=18 ” title=”Edit section: [Errno 20] Not a directory”>edit</a>]</h2>

<p>Plugins Labels and Exchange Rate seem to be impacted with this issue.</p>

<p>This issue is caused by requests.request which returns:</p>

<pre>[Errno 20] Not a directory</pre>

<p>Maybe because requests is not properly installed, I don’t know&nbsp;:(.</p>

<p>FIX:&nbsp;???</p>

<h2>Audio MODEM[<a href=” http://electrum.orain.org/w/index.php?title=Build_Electrum_on_Mac_OS_X&amp;action=edit&amp;section=19 ” title=”Edit section: Audio MODEM”>edit</a>]</h2>

<p>Does not work (activation fails) because MacOS Kernel ‘Darwin’ seems not to be supported</p>

<pre>Jul 21 12:25:18 dev.local electrum[80139] &lt;Notice&gt;: Audio MODEM is available.

Jul 21 12:25:18 dev.local electrum[80139] &lt;Notice&gt;: Traceback (most recent call last): Jul 21 12:25:18 dev.local

electrum[80139] &lt;Notice&gt;: File ”./Electrum.app/Contents/Resources/lib/python2.7/gui/qt/main_window.py”, line 2799, in &lt;lambda&gt; Jul 21 12:25:18 dev.local

electrum[80139] &lt;Notice&gt;: return lambda: do_toggle(cb, name, w) Jul 21 12:25:18 dev.local

electrum[80139] &lt;Notice&gt;:

File ”./Electrum.app/Contents/Resources/lib/python2.7/gui/qt/main_window.py”, line 2789, in do_toggle Jul 21 12:25:18 dev.local

electrum[80139] &lt;Notice&gt;: plugins[name] = p = module.Plugin(self.config, name) Jul 21 12:25:18 dev.local electrum[80139] &lt;Notice&gt;: File ”./Electrum.app/Contents/Resources/lib/python2.7/plugins/audio_modem.py”, line 36, in __init__ Jul 21 12:25:18 dev.local

electrum[80139] &lt;Notice&gt;: }[platform.system()] Jul 21 12:25:18 dev.local electrum[80139] &lt;Notice&gt;:

KeyError: ‘Darwin’</pre>

<hr/>

<h1>Other patches (optionals):[<a href=” http://electrum.orain.org/w/index.php?title=Build_Electrum_on_Mac_OS_X&amp;action=edit&amp;section=20 ” title=”Edit section: Other patches (optionals):”>edit</a>]</h1>

<h2>Privacy headers_url[<a href=” http://electrum.orain.org/w/index.php?title=Build_Electrum_on_Mac_OS_X&amp;action=edit&amp;section=21 ” title=”Edit section: Privacy headers url”>edit</a>]</h2>

<p>Remove headers_url to prevent the client to download the header file from a centralized/untrusted server (no offense):</p>

<pre>#!/bin/sh echo “[...] Patching: headers_url” sed -i.bak “s/self.headers_url = *’.‘/self.headers_url = ‘’/g” dist/Electrum.app/Contents/Resources/lib/python2.7/lib/blockchain.py

&amp;&amp;rm -f dist/Electrum.app/Contents/Resources/lib/python2.7/lib/blockchain.py.bak &amp;&amp;echo

“[OK] Patch applied successfully”</pre>

3.6. Build Electrum on Mac OS X 45

Electrum Documentation, Release 2.5

<h2>Privacy DEFAULT_SERVERS[<a href=” http://electrum.orain.org/w/index.php?title=Build_Electrum_on_Mac_OS_X&amp;action=edit&amp;section=22 ” title=”Edit section: Privacy DEFAULT SERVERS”>edit</a>]</h2>

<p>Remove all (untrusted) DEFAULT_SERVERS:</p>

<pre>#!/bin/sh echo “[...] Patching: DEFAULT_SERVERS” sed -i.bak -n -e ‘/^ DEFAULT_SERVERS *= *{/{‘ -e ‘p’ -e ‘:a’ -e ‘N’ -e ‘/}$/!ba’ -e ‘s/.n//’ e ‘}’ -e ‘p’ dist/Electrum.app/Contents/Resources/lib/python2.7/lib/network.py

&amp;&amp;rm -f dist/Electrum.app/Contents/Resources/lib/python2.7/lib/network.py.bak &amp;&amp;echo “[OK] Patch applied successfully”</pre>

<p>Note: You’ll either need to add some manually to this list or add yours to your Electrum ~/.electrum/config file (“server”: “your server.com:50002:s”,) otherwise the application will not launch if this is the first time you use it. Also make sure to remove the

~/.electrum/recent_servers file (to avoid your client to connect to previous servers).</p>

</div>

46 Chapter 3. For developers

• GOLANG Stratum client library

• Tutorial: How to create a plugin

• Tutorial for setting up a server

CHAPTER

4

External Links

47

advertisement

Was this manual useful for you? Yes No
Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Related manuals