Crate diem_sdk[][src]

Expand description

The official Rust SDK for Diem.


This SDK provides all the necessary components for building on top of the Diem Blockchain. Some of the important modules are:

  • client - Includes a JSON-RPC client implementation
  • crypto - Types used for signing and verifying
  • transaction_builder - Includes helpers for constructing transactions
  • types - Includes types for Diem on-chain data structures


Here is a simple example to show how to create two accounts and do a p2p transfer on testnet:

use diem_sdk::{
    client::{FaucetClient, BlockingClient},
    types::{chain_id::ChainId, LocalAccount},
    transaction_builder::{Currency, TransactionFactory},
use rand_core::OsRng;

let transaction_factory = TransactionFactory::new(ChainId::new(2));
let client = BlockingClient::new("");
let faucet = FaucetClient::new("".to_owned(), "".to_owned());
let mut account_1 = LocalAccount::generate(&mut OsRng);
let mut account_2 = LocalAccount::generate(&mut OsRng);

// Fund and create account 1 and 2, account_1.authentication_key(), 100).unwrap();, account_2.authentication_key(), 50).unwrap();

let transaction = account_1.sign_with_transaction_builder(
    transaction_factory.peer_to_peer(Currency::XUS, account_2.address(), 10)

client.wait_for_signed_transaction(&transaction, None, None).unwrap();

let account_view = client.get_account(account_2.address()).unwrap().into_inner().unwrap();
let balance = account_view
    .find(|b| b.currency == Currency::XUS)
assert_eq!(balance.amount, 60);