Skip to main content
Version: IOTA

Getting Started with Rust

You download the source code for the wallet.rs library from the official GitHub repository.

Prerequisites

You will need to install Rust and Cargo to use wallet.rs. You can find installation instructions in the Rust documentation.

We recommend you update Rust to the latest stable version. The nightly version should be fine, but there is a chance some changes are not compatible.

no_std is not currently supported, but we are working on it, and we will provide it as a feature once the new implementation is ready.

Dependencies

cmake and openssl are required to run Rust. To run the build process successfully using Cargo, you may need install additional build tools onto your system.

You can download cmake from the official cmake website. You can install openssl with vcpkg or chocolatey.

choco install openssl
# you may need to set the OPENSSL_ROOT_DIR environment variable
set OPENSSL_ROOT_DIR="C:\Program Files\OpenSSL-Win64"

Use the Library

Add wallet.rs as a Dependency

If you simply want to use the library, you only need to add this lines your Cargo.toml file:

[dependencies]
iota-wallet = { git = "https://github.com/iotaledger/wallet.rs", branch = "production" }

Enable Asynchronous Functionality

The example below requires asynchronous functionality. You can enable it by adding the following line as a dependency:

tokio = { version = "1", features = ["full"] }

Initialize the Library

To use the library, you first need to create an AccountManager, as shown on lines 7 through 10 in the following example.

After you have created your AccountManager you can use it interact with a node, for example the public devnet at https://api.lb-0.h.chrysalis-devnet.iota.cafe.

use iota_wallet::{account_manager::AccountManager, client::ClientOptionsBuilder, signing::SignerType};
use std::path::PathBuf;

#[tokio::main]
async fn main() -> iota_wallet::Result<()> {
let storage_folder: PathBuf = "./my-db".into();
let manager = AccountManager::builder()
.with_storage(&storage_folder, None)?
.finish()
.await?;
manager.set_stronghold_password("password").await?;
// If no mnemonic is provided, then the Stronghold file is the only way for a backup
manager.store_mnemonic(SignerType::Stronghold, None).await?;
let client_options = ClientOptionsBuilder::new()
.with_node("https://api.lb-0.h.chrysalis-devnet.iota.cafe")?
.build()?;
let account = manager
.create_account(client_options)?
.signer_type(SignerType::Stronghold)
.initialise()
.await?;
let address = account.generate_address().await?;
println!("Address: {}", address.address().to_bech32());
Ok(())
}