Crates.io | rs-soroban-client |
lib.rs | rs-soroban-client |
version | 0.1.0 |
source | src |
created_at | 2023-06-24 09:26:05.874191 |
updated_at | 2023-06-24 09:26:05.874191 |
description | A high-level library Rust client library for interacting with Soroban smart contracts on the Stellar blockchain |
homepage | |
repository | https://github.com/rahul-soshte/rs-soroban-client |
max_upload_size | |
id | 898882 |
size | 106,812 |
A Rust client library for interacting with Soroban smart contracts on the Stellar blockchain
The library is composed of 3 components:
This library will enable developers to seamlessly integrate Soroban functionality into their Rust-based applications and services. Most of the groundwork has already been laid by the Stellar team by building the xdr library and rust stellar strkey implementation. This particular library has been the missing piece for soroban and the rust community at large in the stellar ecosystem.
A practical scenario where this library can be used, Suppose someone wants to build a trading bot targeting a DEX built on Soroban itself. This bot executes a large number of trades within a short period, often leveraging market inefficiencies and price discrepancies. A Rust client library for Soroban would provide the person with a performant toolset to build trading algorithms, interact with the Stellar network, and execute trades with minimal latency.
// Submitting a transaction
use soroban_client::Server;
use soroban_client::Networks;
use soroban_client::TransactionBuilder;
use soroban_client::Keypair;
#[tokio::main]
async fn main() {
let server = Server::new("http://localhost:8000/soroban/rpc").unwrap();
let public_key = "..."; // Replace with the actual public key
let secret_string = "..."; // Replace with the actual secret key
let contract_id = "..."; // Replace with the actual contract ID
let account = server.get_account(public_key).await.unwrap();
// Fee hardcoded for this example.
let fee = 100;
let contract = Contract::new(contract_id).unwrap();
let mut transaction = TransactionBuilder::new(&account, fee, Networks::STANDALONE)
.add_operation(
// An operation to call increment on the contract
contract.call("increment").unwrap(),
)
.set_timeout(30)
.build();
// Simulate the transaction to discover the storage footprint, and update the
// transaction to include it. If you already know the storage footprint you
// can use `add_footprint` to add it yourself, skipping this step.
transaction = server.prepare_transaction(transaction).await.unwrap();
// Sign the transaction
let secret_key = Keypair::from_secret(secret_string).unwrap();
transaction.sign(&secret_key);
match server.send_transaction(transaction).await {
Ok(transaction_result) => {
println!("{:?}", transaction_result);
}
Err(err) => {
eprintln!("{:?}", err);
}
}
}
Rahul Soshte (Twitter)