[−][src]Crate stellar_base
Stellar Base
The stellar-base
crate provides low level Stellar types.
- Create and sign transactions
- Encode and decode Stellar objects from XDR
If you are looking for a way to interact with Horizon, take a
look at stellar-horizon
.
Creating a KeyPair
A Stellar KeyPair contains a Secretkey and a PublicKey. You can use the PublicKey to identify the Stellar account, and the SecretKey to sign transactions.
use stellar_base::crypto::KeyPair; let random_kp = KeyPair::random()?; println!("Account Id = {}", random_kp.public_key().account_id());
Creating and signing a Transaction
You can use this crate to create Stellar transactions and serialize them to XDR.
use stellar_base::amount::Amount; use stellar_base::asset::Asset; use stellar_base::crypto::{KeyPair, PublicKey}; use stellar_base::memo::Memo; use stellar_base::network::Network; use stellar_base::operations::Operation; use stellar_base::transaction::{Transaction, MIN_BASE_FEE}; use stellar_base::xdr::XDRSerialize; use std::str::FromStr; let source_kp = KeyPair::random()?; let destination = PublicKey::from_account_id("GATTMQEODSDX45WZK2JFIYETXWYCU5GRJ5I3Z7P2UDYD6YFVONDM4CX4")?; let payment_amount = Amount::from_str("13.12")?; let payment = Operation::new_payment() .with_destination(destination.clone()) .with_amount(payment_amount)? .with_asset(Asset::new_native()) .build()?; let mut tx = Transaction::builder(source_kp.public_key().clone(), 1234, MIN_BASE_FEE) .with_memo(Memo::new_id(7483792)) .add_operation(payment) .into_transaction()?; tx.sign(&source_kp, &Network::new_test()); let xdr = tx.into_envelope().xdr_base64()?; println!("Xdr = {}", xdr);
Re-exports
pub use self::asset::Asset; |
pub use self::memo::Memo; |
pub use self::network::Network; |
pub use self::operations::Operation; |
pub use self::transaction::Transaction; |
Modules
account | Account data and flags. |
amount | Represent monetary values and prices. |
asset | Assets on the network. |
crypto | Cryptographic functions. |
error | Error and Result definitions. |
memo | Transaction memo. |
network | Stellar Network. |
operations | Operations that mutate the ledger state. |
signature | Transaction signatures. |
time_bounds | Represent when a transaction is valid. |
transaction | Transaction that changes the ledger state. |
xdr | Traits for XDR serialization and deserialization. |
Structs
KeyPair | The secret and public key pair of the account. |
PublicKey | The public key of the account. |