Skip to main content
Version: IOTA

Examples in Rust

The examples for wallet.rs are located in the library's repository. To get access to them, clone the wallet.rs repository:

git clone -b production https://github.com/iotaledger/wallet.rs.git
cd wallet.rs

You can list all available examples by running the following command:

cargo run --example # lists the available examples

To run an example, you can use the following command, replacing transfer with the desired example:

cargo run --example transfer # execute the `transfer` example

You can find all examples in the examples subfolder of the project.

Backup and Restore

  1. Create an account manager and set a password:
let manager = AccountManager::builder().finish().await.unwrap();

manager.set_stronghold_password("password").await.unwrap();
manager.store_mnemonic(SignerType::Stronghold, None).await.unwrap();
  1. Create your account:
let client_options = ClientOptionsBuilder::new()
.with_node("https://api.lb-0.h.chrysalis-devnet.iota.cafe")?
.build()
.unwrap();
let account_handle = manager
.create_account(client_options)?
.alias("alias")
.initialise()
.await?;
let id = account_handle.id().await;
  1. You can secure your account in a backup file:
// backup the stored accounts to ./backup/${backup_name}
let backup_path = manager.backup("./backup").await?;

  1. You can import the backup later, or in another application using the following snippet:
manager.import_accounts(backup_path, "password").await?;

let imported_account_handle = manager.get_account(&id).await?;

let account = account_handle.read().await;
let imported_account = imported_account_handle.read().await;

That's it! You can now backup and restore your account!

You can see the full code for the example in the wallet.rs repository

Transfer

You use the following example to generate an account and transfer funds.

/examples/transfer.rs
loading...

Events

wallet.rs library is able to listen to several supported event. As soon as the event occurs, a provided callback will be triggered.

You can use the following example to fetch an existing Account and listen to transaction events related to that Account :

examples/event.rs
loading...

Logger

examples/logger.rs
loading...