Advanced functions

SmartCash Electrum is based on Electrum, a Bitcoin wallet. Most functions are identical, which means it is not necessary to reproduce the entirety of the Electrum documentation here. The following sections describe some frequently used advanced functions. For further details on other advanced functions in Electrum for both Bitcoin and SmartCash, please click the links below.

Smartnodes in SmartCash Electrum

SmartCash Electrum supports smartnode creation through an interface called the Smartnode Manager.

Smartnode Manager

The Smartnode Manager can be accessed via Smartnodes tab. This manager displays the status of your smartnode(s). A wallet with no Smartnodes will begin with a default smartnode for which you can fill in the necessary information.

The manager displays the following data about each smartnode you have set up:

  • The alias (name) of the smartnode.
  • The Address.
  • The protocol version that your smartnode supports.
  • The status of the smartnode (e.g. whether it has been activated).
  • The Payee.

Smartnode setup

A smartnode requires a “smartnode” key, which is known to both SmartCash Electrum and your smartnode. Your smartnode will use this key to sign messages, and the SmartCash network will know that you authorized it to. A smartnode key can either be one of your SmartCash Electrum keys, or an imported key.

IP address and Alias

Certain information about your smartnode is required. The IP address and port that your smartnode uses must be supplied. Also, the Alias that your smartnode. This information is filled in automatically if you import a “smartnode.conf” file.

../../_images/mn-view.png

Entering IP and Alias information

Collateral

To start a smartnode, you must have a 100000 SMART payment available in your wallet. You can scan your wallet for 100000 SMART payments in the Create Smartnode tab of the Smartnode Manager.

After scanning, a list of available 100000 SMART collateral payments will be displayed. Selecting one of them will cause the selected smartnode’s data to be filled in, though these changes won’t be saved until you click the Save button in the lower-right corner of the tab.

../../_images/mn-collateral.png

Entering IP and alias

Activating your smartnode

After selecting a collateral payment and specifying a delegate key, you can activate your smartnode. Do this by clicking Activate Smartnode in the Activate Smartnode tab of the Smartnode Manager. If the Activate Smartnode button cannot be clicked, look at the message in the Status bar. It will show you why your smartnode cannot be activated.

Activation will require your password if your wallet is encrypted, because a message must be signed. After waiting for SmartCash Electrum to sign and broadcast your smartnode announcement, you will be presented with a message detailing the result. The status of your smartnode will be updated in the table and the View Smartnode tab.

../../_images/mn-enabling.png

Entering IP and protocol information

Importing smartnode.conf

You can import a smartnode.conf file using the Smartnode.conf tab of the Smartnode Manager. This is the recommended way of setting up Smartnodes, as it allows you to configure Smartnodes for SmartCash Core and SmartCash Electrum in the same way. Importing a smartnode.conf file will automatically set up one or more smartnode configurations in the Smartnode Manager.

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 separate machines and potentially controlled by separate 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.

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.

../../_images/faq-multisig-create.png

Selecting x of y signatures for a multi-signature wallet

After generating and confirming your recovery seed, you will be shown the xpub address for this wallet.

../../_images/faq-multisig-xpub.png

xpub key of the first wallet

After generating a seed (keep it safely!) you will need to provide the master public key of the other wallet. Of course when you create the other wallet, you put the master public key of the first wallet.

../../_images/faq-multisig-share-xpub.png

Entering xpub from the second wallet in the first wallet

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.

Receiving

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

Sending

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.

The transaction now has to be sent to the second wallet. Several options are available for this:

  • You can transfer the file on a USB stick

    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)

  • You can use QR codes

    A button showing a QR code icon is also available. Clicking this button will display a QR code containing the transaction, which can be scanned into the second wallet (Tools > Load Transaction > From QR Code)

With both of the above methods, you can now add the second signature to the transaction (using the Sign button). It will then be broadcast to the network.

Sweep a paper wallet

You may have received a paper wallet as a gift from another SmartCash user, or previously stored one in a safe deposit box. Funds are swept from a paper wallet into a live wallet by importing its private key, which is a long sequence of characters starting with the number “7” or the capital letter “X”. The example below displays a private key (WIF format).

../../_images/sweep-secret.png

Public address and associated private key produced by SmartCash Paper Wallet Generator

Funds from paper wallets are swept into an SmartCash Electrum Wallet by creating a transaction using the private key and sending it to a new address from your wallet. This is necessary because it is not possible to add new public or private keys to an existing deterministic series of addresses derived from a seed phrase.

Begin by selecting the Wallet > Private Keys > Sweep menu item. The Sweep private keys dialog will appear, where you can paste your private key(s). An unused address controlled by your SmartCash Electrum wallet appears in the lower field, and can be changed by clicking the Address button. Once you have pasted your private key, click the Sweep button.

../../_images/sweep-privkey.png

Entering the private key

SmartCash Electrum then prepares a transaction using the private key you just imported to derive the public address for the transaction input and the address from your wallet as the output, and signs the message. Click Broadcast to enter the transaction on the blockchain. The balance will then appear in your wallet under the specified address. The address you swept is left with zero balance.

Command line

SmartCash Electrum has a powerful command line available when running under Linux or macOS. This section will show you a few basic principles.

Using the inline help

To see the list of SmartCash Electrum commands, type:

electrum help

To see the documentation for a command, type:

electrum help <command>

Magic words

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

The exclamation mark ! is a shortcut that means ‘the maximum amount available’. Note that the transaction fee will be computed and deducted from the amount. Example:

electrum payto Sbgq1f1hZvtU6RZVixVhc4ER61KEkey5t5 !

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

electrum signmessage Sbgq1f1hZvtU6RZVixVhc4ER61KEkey5t5 ?

Use a colon : if you want the prompted parameter to be hidden (not echoed in your terminal). Note that you will be prompted twice in this example, first for the private key, then for your wallet password:

electrum importprivkey :

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

cat LICENCE | electrum signmessage Sbgq1f1hZvtU6RZVixVhc4ER61KEkey5t5 -

Aliases

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

electrum payto ecdsa.net !

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.

Sign and verify message

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

sig=$(cat LICENCE| electrum signmessage Sbgq1f1hZvtU6RZVixVhc4ER61KEkey5t5 -)

And:

cat LICENCE | electrum verifymessage Sbgq1f1hZvtU6RZVixVhc4ER61KEkey5t5 $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:

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 Sbgq1f1hZvtU6RZVixVhc4ER61KEkey5t5| 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 SmartCash:

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 - [destination address]

Using cold storage with the command line

This section will show you how to sign a transaction with an offline SmartCash Electrum wallet using the command line.

Create an unsigned transaction

With your online (watching-only) wallet, create an unsigned transaction:

electrum payto Sbgq1f1hZvtU6RZVixVhc4ER61KEkey5t5 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:

cat unsigned.txn | electrum deserialize -

Sign the transaction

The serialization format of SmartCash Electrum contains the master public key needed and key derivation used by the offline wallet to sign the transaction. 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’.

Broadcast the transaction

Send your transaction to the SmartCash network, using broadcast:

cat signed.txn | electrum broadcast -

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

How to accept SmartCash on a website using SmartCash Electrum

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

Requirements

  • A webserver serving static HTML
  • A SSL certificate (signed by a CA)
  • Electrum version >= 2.6

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 SmartCash Electrum as a daemon:

electrum daemon start

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

Configure a requests directory

This directory must be served by your webserver (eg Apache):

electrum setconfig requests_dir /var/www/r/

By default, SmartCash 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/']"

Create a signed payment request

electrum addrequest 3.14 -m "this is a test"
{
   "URI": "smartcash:Sbgq1f1hZvtU6RZVixVhc4ER61KEkey5t5?amount=3.14&r=https://electrum.org/r/7c2666541a",
   "address": "Sbgq1f1hZvtU6RZVixVhc4ER61KEkey5t5",
   "amount": 314000000,
   "amount (SMART)": "3.14",
   "exp": 3600,
   "id": "7c2666541a",
   "index_url": "https://electrum.org/r/index.html?id=7c2666541a",
   "memo": "this is a test",
   "request_url": "https://electrum.org/r/7c2666541a",
   "status": "Pending",
   "time": 1450175741
}

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.

Open the payment request page in your browser

Let us open index_url in a web browser.

../../_images/payrequest.png

Payment request page in a web browser

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

../../_images/payreq_window.png

Wallet awaiting payment

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

Add web sockets support

Get SimpleWebSocketServer from here:

git clone https://github.com/ecdsa/simple-websocket-server.git

Set websocket_server and websocket_port in your config:

electrum setconfig websocket_server <FQDN of your server>
electrum setconfig websocket_port 9999

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. Please notice that higher ports might be blocked on some client’s firewalls, so it is more safe for example to reverse proxy websockets transmission using standard 443 port on an additional subdomain.

JSONRPC interface

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

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