Crate stellar_base
source ·Expand description
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::{SodiumKeyPair};
let random_kp = SodiumKeyPair::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::{PublicKey, SodiumKeyPair};
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 = SodiumKeyPair::random()?;
let destination = PublicKey::from_account_id("GATTMQEODSDX45WZK2JFIYETXWYCU5GRJ5I3Z7P2UDYD6YFVONDM4CX4")?;
let payment_amount = Amount::from_str("13.12")?;
let payment = Operation::new_payment()
.with_destination(destination)
.with_amount(payment_amount)?
.with_asset(Asset::new_native())
.build()?;
let mut tx = Transaction::builder(source_kp.public_key(), 1234, MIN_BASE_FEE)
.with_memo(Memo::new_id(7483792))
.add_operation(payment)
.into_transaction()?;
tx.sign(&source_kp.as_ref(), &Network::new_test());
let xdr = tx.into_envelope().xdr_base64()?;
println!("Xdr = {}", xdr);
Re-exports
pub use self::asset::Asset;
pub use self::crypto::PublicKey;
pub use self::memo::Memo;
pub use self::network::Network;
pub use self::operation_result::OperationResult;
pub use self::operations::Operation;
pub use self::transaction::Transaction;
pub use self::transaction_result::TransactionResult;
Modules
- Account data and flags.
- Represent monetary values and prices.
- Assets on the network.
- Represent an account claim.
- Cryptographic functions.
- Error and Result definitions.
- Transaction memo.
- Stellar Network.
- Operations that mutate the ledger state.
- Represent when a transaction is valid.
- Transaction that changes the ledger state.
- Traits for XDR serialization and deserialization.