Skip to content

Commit

Permalink
sdk: add a README
Browse files Browse the repository at this point in the history
  • Loading branch information
bmwill authored and bors-libra committed May 11, 2021
1 parent 1a7e180 commit 1848bab
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 1 deletion.
2 changes: 1 addition & 1 deletion sdk/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name = "diem-sdk"
version = "0.0.1"
authors = ["Diem Association <[email protected]>"]
description = "Diem types"
description = "The Official Diem SDK"
repository = "https://github.com/diem/diem"
homepage = "https://diem.com"
license = "Apache-2.0"
Expand Down
21 changes: 21 additions & 0 deletions sdk/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# diem-sdk

[![diem-sdk on crates.io](https://img.shields.io/crates/v/diem-sdk)](https://crates.io/crates/diem-sdk)
[![Documentation (latest release)](https://docs.rs/diem-sdk/badge.svg)](https://docs.rs/diem-sdk/)
[![Documentation (master)](https://img.shields.io/badge/docs-master-59f)](https://diem.github.io/diem/diem_sdk/)
[![License](https://img.shields.io/badge/license-Apache-green.svg)](https://github.com/diem/diem/blob/main/LICENSE)

The official Rust SDK for Diem.

## Usage

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](https://github.com/diem/diem/blob/master/json-rpc/json-rpc-spec.md) implementation
* `crypto` - Types used for signing and verifying
* `transaction_builder` - Includes helpers for constructing transactions
* `types` - Includes types for Diem on-chain data structures

## License

Diem Core is licensed as [Apache 2.0](https://github.com/diem/diem/blob/main/LICENSE).
49 changes: 49 additions & 0 deletions sdk/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,55 @@
// Copyright (c) The Diem Core Contributors
// SPDX-License-Identifier: Apache-2.0

//! The official Rust SDK for Diem.
//!
//! ## Modules
//!
//! 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](https://github.com/diem/diem/blob/master/json-rpc/json-rpc-spec.md) implementation
//! * `crypto` - Types used for signing and verifying
//! * `transaction_builder` - Includes helpers for constructing transactions
//! * `types` - Includes types for Diem on-chain data structures
//!
//! ## Example
//!
//! Here is a simple example to show how to create two accounts and do a p2p transfer on testnet:
//!
//! ```no_run
//! 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("http://testnet.diem.com/v1");
//! let faucet = FaucetClient::new("http://testnet.diem.com/mint".to_owned(), "http://testnet.diem.com/v1".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
//! faucet.fund(Currency::XUS.as_str(), account_1.authentication_key(), 100).unwrap();
//! faucet.fund(Currency::XUS.as_str(), 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.submit(&transaction).unwrap();
//! 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
//! .balances
//! .iter()
//! .find(|b| b.currency == Currency::XUS)
//! .unwrap();
//! assert_eq!(balance.amount, 60);
//! ```
#[cfg(feature = "client")]
#[cfg_attr(docsrs, doc(cfg(feature = "client")))]
pub mod client {
Expand Down

0 comments on commit 1848bab

Please sign in to comment.