Skip to main content

Sign and Send IOTA with a Ledger

Alpha Software

The IOTA SDK is currently in alpha. APIs, interfaces, and behavior may change without notice between releases. It is not yet recommended for production use.

This how-to demonstrates how to sign an IOTA transfer with a key held on a Ledger hardware wallet, or on the Speculos emulator, and execute it on localnet.

info

This example runs on localnet. Make sure you have a local IOTA node running before executing the code.

Prerequisites​

  • The IOTA SDK installed for your target language, with Ledger support:
    • Rust: the graphql, ledger-hid and ledger-speculos features of the iota-sdk crate.
    • Go, Python, Kotlin, Swift and C#: no additional setup.
    • WASM/TS: no additional setup. The bindings reach the device through a transport you implement, see Use Another Transport.
  • A running local IOTA node
  • A Ledger device or the Speculos emulator, set up as described below

On Linux, building the SDK with USB support needs the libudev development package (libudev-dev on Debian and Ubuntu).

Set Up the Device​

  1. Install the IOTA app on the device with Ledger Live.
  2. Connect the device over USB and unlock it.
  3. On Linux, install the Ledger udev rules so that a regular user can open the device.

Steps​

1. Define the Amount and the Recipient Address​

crates/iota-sdk/examples/ledger_sign_send_iota.rs
loading...

2. Connect to the Ledger and Open the IOTA App​

Connect to the first device attached over USB, or to the emulator when LEDGER_SIMULATOR is set, and open the IOTA app.

crates/iota-sdk/examples/ledger_sign_send_iota.rs
loading...

3. Create the Signer​

Create a signer for the key at a derivation path. The address of that key is the sender.

crates/iota-sdk/examples/ledger_sign_send_iota.rs
loading...

4. Initialize the Client and Request Faucet Funds​

Connect to localnet and request funds from the faucet for the sender address.

crates/iota-sdk/examples/ledger_sign_send_iota.rs
loading...

5. Build the Transaction​

crates/iota-sdk/examples/ledger_sign_send_iota.rs
loading...

6. Sign on the Device and Execute the Transaction​

The transaction builder passes the signer the coins the transaction spends, so the device shows the transfer. Review and approve it on the device.

crates/iota-sdk/examples/ledger_sign_send_iota.rs
loading...

Expected Output​

Sender address: 0x<sender-hex-address>
Review and approve the transaction on the device
Digest: <transaction-digest>
Transaction status: Success

Use Another Transport​

On Android, on iOS and in the browser the SDK cannot open USB devices. To reach a device there:

  1. Implement LedgerTransport on top of your link to the device, such as Bluetooth through Ledger's mobile SDKs, or WebHID and WebUSB in the browser. Its exchange method receives an APDU command and returns the device's answer, which ends with the two-byte status word.
  2. Create the Ledger from that transport with Ledger.fromTransport.

The WASM/TS tab in step 2 shows a transport over a TCP socket.

Sign Transactions the Device Cannot Display​

The IOTA app shows what a transaction does when it can work that out from the transaction and its input objects. To sign a transaction the app cannot interpret, enable blind signing in the settings of the IOTA app on the device.

Full Example​

crates/iota-sdk/examples/ledger_sign_send_iota.rs
loading...