IOTA Rust Workshop

Simple examples to help a developer work through interacting with the IOTA network.

Getting started

To start playing with these examples run the following commands:

git clone https://github.com/iota-community/rust-iota-workshop.git
cd rust-iota-workshop

Installing Rust

https://www.rust-lang.org/tools/install

Run first example

All examples can be run from within the root directory (rust-iota-workshop)

Run

cargo run --example [example]

Example

cargo run --example 00_get_node_info

You should receive a message including the statistics of an IOTA node. This means you can explore and run the other examples.

Examples included

Here you can find all the examples:

PRs are welcome on master

Todo List

  • implement ?

introduction

IOTA is the backbone for the Internet of Things. Rust is made for this and the Web, so it fits perfectly togheter.

What is Rust?

Rust is a multi-paradigm programming language focused on performance and safety. It’s developed by Mozilla and backed up with sponsoring by big players like Amazon Web Services (AWS), Google Cloud, and Microsoft Azure. Here is a website with some companies which use Rust in production with different uses cases. These use cases are very diverse, for example, Atlassian use Rust in service for analyzing petabytes of their source code and Cloudflare uses it as a replacement for memory-unsafe languages (particularly C) and is using it in their core edge logic.

What is IOTA?

The first open-source distributed ledger that is being built to power the future of the Internet of Things with feeless microtransactions and data integrity for machines. iota.org

What is this Workshop?

This workshop is for developers, who wants to get started with IOTA and Rust. It containts examples, which can be build and run with Cargo. Cargo is the Rust package manager.

The workshop will cover

  • Connect to the Tangle
  • Send Data
  • Fetch Data
  • Create an IOTA Address
  • Get tokens via the a faucet and check the balance
  • Send Tokens

Setup Developer Environment

You will need to install Rust and a Code Editor.

Install Rust

To install rust on your computer, follow the instructions on official rust website

for macOS, Linux, or another Unix-like OS run in your terminal

curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh

For other platforms, see Installing Rust Guide

Code editor

Choose a code editor. We recommend Visual Studio Code - VSCode.

Open a new Terminal in VSCode an run the first example.

00_get_node_info

Get node information from an IOTA node.

cargo run --example 00_get_node_info

you should see some informations about the connected IOTA node, like this:

Example Output

GetNodeInfoResponse {
    app_name: "HORNET",
    app_version: "0.4.0-rc12",
    jre_available_processors: None,
    jre_free_memory: None,
    jre_max_memory: None,
    jre_total_memory: None,
    jre_version: None,
    latest_milestone: "EC9XOVXNBHUHKVPTJGYMKZVEGDH9GYWPFDCBKVTDWIGAOKLISDDMTFOPXFEOJRMZVZCFYPSYUUBOA9999",
    latest_milestone_index: 1428959,
    latest_solid_subtangle_milestone: "EC9XOVXNBHUHKVPTJGYMKZVEGDH9GYWPFDCBKVTDWIGAOKLISDDMTFOPXFEOJRMZVZCFYPSYUUBOA9999",
    latest_solid_subtangle_milestone_index: 1428959,
    milestone_start_index: 1427599,
    neighbors: 4,
    packets_queue_size: None,
    time: 1590882172000,
    tips: 0,
    transactions_to_request: 0,
}

01_send_data

Send data to an address.

cargo run --example 01_send_data

you will see the bundlehash in the console. Search for it on TheTangle.org in the comnet network.

Example Output

Search in theTangle: https://comnet.thetangle.org/bundle/IZCNJKGNCCTCYYKICTNFWOIBYTSSNJZWGXPBE9VLWQUBJGRKQHGCFEKKLGALJSIQRCVKDIYLQOFFVGOGY

02_fetch_data

Send a transfer to an address.

cargo run --example 02_fetch_data

This fetches the data from the address HEQLOWORLDHELLOWORLDHELLOWORLDHELLOWORLDHELLOWORLDHELLOWORLDHELLOWORLDHELLOWOR99DMNFAQLWHD and show the result in the output.

Example Output

Message:
HELLOWORLD

03_get_new_address

Get an unused address from a connected node.

cargo run --example 03_get_new_address

You will see the address in the console. Go to the einfachIOTA Comnet Facuet and send 1 IOTA to it.

Example Output

Index: 0, Address: LOLCUVZ9MBPBTGJGMRLHNLDGCNAWUCGNRBBKUGKRAUSGRCHYXZPGEBXBPJFTBPYPNMCYNDCFZTFYSCXEB

04_check_balance

Get IOTA balance from an address.

cargo run --example 04_check_balance

This fetches the balance from the address LOLCUVZ9MBPBTGJGMRLHNLDGCNAWUCGNRBBKUGKRAUSGRCHYXZPGEBXBPJFTBPYPNMCYNDCFZTFYSCXEBLDPKQBUJ9 and show the result in the output.

Example Output

Balance: 1

05_send_tokens

cargo run --example 05_send_tokens

This sends 1 IOTA to this address: ADDRESSADDRESSADDRESSADDRESSADDRESSADDRESSADDRESSADDRESSADDRESSADDRESSADDRESSADD9 and show the result in the output.

Example Output

Transfer sent: https://comnet.thetangle.org/bundle/EEGUFAZBHYGCBIBZCINKVJJROUEQZJXTWIALAKAOTDHAWGRXHVBVZ9COWIETWPUGFHDHDUOHSNDEVJAJW