[][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)
    .to_transaction()?;

tx.sign(&source_kp, &Network::new_test());
let xdr = tx.into_envelope().xdr_base64()?;
println!("Xdr = {}", xdr);

Modules

account
amount
asset
crypto
error
memo
network
operations
signature
time_bounds
transaction
xdr