extern crate shuttle_sdk; use std::str::FromStr; use shuttle_sdk::{Amount, KeyPair, Result, Server}; use shuttle_sdk::{Account, Network, OperationBuilder, TransactionBuilder}; const TESTNET_URL: &'static str = "https://horizon-testnet.stellar.org"; fn create_account() -> Result<()> { let keypair = KeyPair::random()?; let public_key = keypair.public_key(); let account_id = public_key.account_id()?; println!("Funding account {}", account_id); let server = Server::new(TESTNET_URL)?; let network = Network::test_network(); // Fund account server.friendbot(&public_key)?.send()?; let new_keypair = KeyPair::random()?; println!("creating {}", &new_keypair.public_key().account_id()?); // Retrieve sequence number let account_details = server.accounts().account_id(&public_key)?.send()?; let mut account = Account::new(public_key.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)?; println!("Submitting tx"); let response = server.submit_transaction(&signed_tx)?.send()?; println!("response = {:?}", response); Ok(()) } fn main() { create_account().unwrap(); }