Crate shuttle_sdk [] [src]

shuttle-sdk

The shuttle-sdk crate provides a way to communicate with a Stellar Horizon Server.

It provides a way to submit requests to the Horizon instance, and to build, sign, and submit transactions to the network.

Example Usage

Create and fund a new account

use shuttle_sdk::{KeyPair, Server};

const TESTNET_URL: &'static str = "https://horizon-testnet.stellar.org";

let keypair = KeyPair::random()?;
let account_id = keypair.public_key();

let server = Server::new(TESTNET_URL)?;
let response = server.friendbot(&account_id)?.send()?;
println!("response = {:?}", response);

Get a list of available assets

use shuttle_sdk::{KeyPair, Server};

const TESTNET_URL: &'static str = "https://horizon-testnet.stellar.org";

let keypair = KeyPair::random()?;
let account_id = keypair.public_key();

let server = Server::new(TESTNET_URL)?;
let response = server.assets().for_code("MOBI").send()?;
println!("response = {:?}", response);

Create and Submit transaction

use std::str::FromStr;
use shuttle_sdk::{Account, KeyPair, Network, Server};
use shuttle_sdk::{Amount, OperationBuilder, TransactionBuilder};

const TESTNET_URL: &'static str = "https://horizon-testnet.stellar.org";

let keypair = KeyPair::random()?;
let account_id = keypair.public_key();
let new_keypair = KeyPair::random()?;

let server = Server::new(TESTNET_URL)?;
let network = Network::test_network();

let account_details = server.accounts().account_id(&account_id)?.send()?;
let mut account = Account::new(account_id.clone(), account_details.sequence);
let tx = TransactionBuilder::new(&mut account)
    .operation(
        OperationBuilder::create_account(
            new_keypair.public_key().clone(),
            Amount::from_str("20.0")?,
        ).build(),
    ).build();
let signed_tx = tx.sign(&keypair, &network)?;
let response = server.submit_transaction(&signed_tx)?.send()?;
println!("response = {:?}", response);

Structs

Account

Account represents a single account in the Stellar network and its sequence number.

Amount

Amount in XLM.

FriendbotRequest

Request to fund a new account.

FriendbotResponse

Response to a FriendbotRequest.

KeyPair

The secret and public key pair of the account.

Network

A Stellar Network.

OperationBuilder

Build an Operation.

PublicKey

The public key of the account.

SecretKey

The secret key of the account.

Server

Handle connection to the Horizon server.

SignedTransaction

A transaction that was signed.

Transaction

A transaction containing operations that change the ledger state.

TransactionBuilder

Transaction builder.

Enums

Error

Error type.

Operation

An operation that mutates the ledger.

Type Definitions

Result

A Result alias where Error is a shuttle_sdk::Error.