Sign and Send IOTA with a Ledger
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.
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-hidandledger-speculosfeatures of theiota-sdkcrate. - 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.
- Rust: the
- 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
- Ledger device
- Speculos emulator
- Install the IOTA app on the device with Ledger Live.
- Connect the device over USB and unlock it.
- On Linux, install the Ledger udev rules so that a regular user can open the device.
Speculos emulates a device running the IOTA app, so you can develop without hardware.
-
Start the emulator with Docker from a checkout of iota-rust-sdk:
make speculos-start -
Set the
LEDGER_SIMULATORenvironment variable when you run the example, which then connects to the emulator instead of a device. -
Approve the requests in the emulator's web interface at
http://127.0.0.1:5001.
Steps
1. Define the Amount and the Recipient Address
- Rust
- Go
- Python
- Kotlin
- Swift
- C#
- WASM/TS
loading...
loading...
loading...
loading...
loading...
loading...
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.
- Rust
- Go
- Python
- Kotlin
- Swift
- C#
- WASM/TS
loading...
loading...
loading...
loading...
loading...
loading...
The WASM bindings can open neither USB devices nor TCP sockets, so the example implements the transport in JavaScript. This one reaches the emulator from Node.
loading...
loading...
3. Create the Signer
Create a signer for the key at a derivation path. The address of that key is the sender.
- Rust
- Go
- Python
- Kotlin
- Swift
- C#
- WASM/TS
loading...
loading...
loading...
loading...
loading...
loading...
loading...
4. Initialize the Client and Request Faucet Funds
Connect to localnet and request funds from the faucet for the sender address.
- Rust
- Go
- Python
- Kotlin
- Swift
- C#
- WASM/TS
loading...
loading...
loading...
loading...
loading...
loading...
loading...
5. Build the Transaction
- Rust
- Go
- Python
- Kotlin
- Swift
- C#
- WASM/TS
loading...
loading...
loading...
loading...
loading...
loading...
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.
- Rust
- Go
- Python
- Kotlin
- Swift
- C#
- WASM/TS
loading...
loading...
loading...
loading...
loading...
loading...
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:
- Implement
LedgerTransporton top of your link to the device, such as Bluetooth through Ledger's mobile SDKs, or WebHID and WebUSB in the browser. Itsexchangemethod receives an APDU command and returns the device's answer, which ends with the two-byte status word. - Create the
Ledgerfrom that transport withLedger.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
- Rust
- Go
- Python
- Kotlin
- Swift
- C#
- WASM/TS
loading...
loading...
loading...
loading...
loading...
loading...
loading...