I used the message_time.rs
code from iotaledger/iota.rs to send a message to the Chrysalis testnet:
use iota::Client;
#[tokio::main]
async fn main() {
// Create a client instance
let iota = Client::builder()
.with_node("https://api.lb-0.testnet.chrysalis2.com")
.unwrap()
.finish()
.await
.unwrap();
let message = iota
.message()
.with_index("Hello")
.with_data("Tangle".to_string().as_bytes().to_vec())
.finish()
.await
.unwrap();
let message_id = message.id().0;
println!("Message ID: {}", message_id);
let _ = iota.retry_until_included(&message_id, None, None).await.unwrap();
let metadata = iota.get_message().metadata(&message_id).await.unwrap();
match metadata.referenced_by_milestone_index {
Some(ms_index) => {
let ms = iota.get_milestone(ms_index).await.unwrap();
println!("Message got referenced by milestone {} at {}", ms_index, ms.timestamp);
}
_ => println!("Message is not referenced by a milestone"),
}
}
If the message is successfully added to the testnet the code returns the message_id
, for eg.
Message ID: a9c7dc2745b0c60f379be01eacbda9e8fdf2019aebaba41710ebd5315a4ecf0c
The data associated with the ID can be viewed via Chrysalis Testnet Explorer by entering the MessageID in the search bar. An example of the data is shown in the next image.
I tried to write a program to get INDEX UTF8
and DATA UTF8
data from the message by using the MESSAGE ID
, but I couldn't figure out from the API Documentation which function/method to use. Can please someone help?