Skip to content

How to run the examples

gary-rowe edited this page Nov 25, 2014 · 1 revision

This article describes how to run the examples in the project from the command line.

Make sure you have a paper copy of your seed phrase before attempting any of these examples

Some examples will wipe your device (you'll have to confirm on the Trezor before anything happens) and others will attempt to spend from your wallet. Make sure that any funds loaded to a seed phrase used in these examples are kept to a minimum (about $1 worth should be sufficient).

You may want to have a second Bitcoin wallet available to receive the funds

Quick start

After cloning and building the project (mvn clean install), do the following at the command line

cd examples
mvn clean compile exec:java -Dexec.mainClass="org.multibit.hd.hardware.examples.trezor.usb.TrezorV1FeaturesExample"

If you have a V1 production Trezor attached this will perform an initial conversation and provide a summary of the device to the console.

Progressing through the examples

You can now explore the other examples by modifying the above snippet accordingly. To gain confidence in working with the library you should run up the examples in the order shown below and follow the instructions in the console and on the Trezor screen as required.

  1. TrezorV1FeaturesExample - Read some information from your device
  2. TrezorV1WipeDeviceExample - Resets your device back to factory settings
  3. TrezorV1WipeAndCreateWalletExample - Reset device and generate a seed phrase from the device
  4. TrezorV1GetAddressExample - Read the first receiving address from the device (you can send to this)
  5. TrezorV1WatchingWalletExample - Run a basic Bitcoinj wallet and spend 1 millibit to a supplied address
  6. TrezorV1WipeAndLoadAbandonWalletExample - Wipe then load (restore) a seed phrase externally (less secure)

Additional examples that demonstrate other features of the library are:

  1. TrezorV1ChangePinExample - Change your PIN
  2. TrezorV1CipherKeyExample - Ask the device to encrypt a small piece of information (good for an ID)
  3. TrezorV1GetDeterministicHierarchyExample - Provides the master public key to allow monitoring of all receiving addresses
  4. TrezorV1SignMessageExample - Sign some text using the private key associated with a given path
  5. TrezorV1StopExample - Technical example for managing start/stop of the hardware wallet service

Loading your own seed phrase

Here are the detailed instructions for loading your own seed phrase:

  1. Open gedit and edit TrezorV1WipeAndLoadAbandonWalletExample.java
  2. Navigate to line 104 and add in your own seed phrase between the double quotes
  3. Navigate to line 112 to change the Trezor label
  4. Save and quit from gedit
  5. Run the Maven commands above
  6. Follow the instructions from the console and the Trezor

Bear in mind that exposing a real seed phrase outside of paper or Trezor is reducing its security so only do this with seed phrases that don't contain significant amounts of bitcoin.

For an example of a real Bitcoin wallet that uses MultiBit Hardware see MultiBit HD.