| Crates.io | autoswap-rs |
| lib.rs | autoswap-rs |
| version | 0.1.0 |
| created_at | 2025-10-15 19:56:04.761626+00 |
| updated_at | 2025-10-15 19:56:04.761626+00 |
| description | AutoSwappr library in Rust |
| homepage | |
| repository | https://github.com/BlockheaderWeb3-Community/autoswap-rust-sdk |
| max_upload_size | |
| id | 1884877 |
| size | 177,878 |
A Rust SDK for interacting with the AutoSwappr contract on Starknet.
Add this to your Cargo.toml:
[dependencies]
autoswappr-sdk = "0.1.0"
tokio = { version = "1", features = ["full"] }
All other dependencies (like starknet, axum, etc.) are automatically included.
0x05582ad635c43b4c14dbfa53cbde0df32266164a0d1b36e5b510e5b34aeb364b
use autoswappr_sdk::{AutoSwappr, constant::{STRK, USDC}};
#[tokio::main]
async fn main() {
// Initialize the SDK
let mut swapper = AutoSwappr::config(
"https://starknet-mainnet.public.blastapi.io".to_string(),
"YOUR_ACCOUNT_ADDRESS".to_string(),
"YOUR_PRIVATE_KEY".to_string(),
"0x05582ad635c43b4c14dbfa53cbde0df32266164a0d1b36e5b510e5b34aeb364b".to_string(),
).unwrap();
// Execute swap (1 STRK to USDC)
let result = swapper.ekubo_manual_swap(*STRK, *USDC, 1).await;
match result {
Ok(response) => println!("Swap successful! Tx: {:?}", response.tx_hash),
Err(error) => println!("Swap failed: {}", error.message),
}
}
AutoSwappr::configConfigure a new AutoSwappr instance.
pub fn config(
rpc_url: String,
account_address: String,
private_key: String,
contract_address: String,
) -> Result<AutoSwappr, Json<ErrorResponse>>
ekubo_manual_swapExecute a manual token swap.
pub async fn ekubo_manual_swap(
&mut self,
token0: Felt,
token1: Felt,
swap_amount: u128,
) -> Result<Json<SuccessResponse>, Json<ErrorResponse>>
Parameters:
token0: Source token addresstoken1: Destination token addressswap_amount: Amount to swap (in token units, not smallest denomination)Returns:
Ok(SuccessResponse): Contains transaction hash on successErr(ErrorResponse): Contains error message on failureuse autoswappr_sdk::constant::{STRK, USDC, ETH};
// STRK token
*STRK
// USDC token
*USDC
// ETH token
*ETH
⚠️ Never expose private keys in your code or version control
use std::env;
let rpc_url = env::var("STARKNET_RPC_URL").expect("STARKNET_RPC_URL not set");
let account_address = env::var("ACCOUNT_ADDRESS").expect("ACCOUNT_ADDRESS not set");
let private_key = env::var("PRIVATE_KEY").expect("PRIVATE_KEY not set");
let mut swapper = AutoSwappr::config(
rpc_url,
account_address,
private_key,
"0x05582ad635c43b4c14dbfa53cbde0df32266164a0d1b36e5b510e5b34aeb364b".to_string(),
).unwrap();
For support and questions, please open an issue on GitHub.
This project is licensed under the MIT License - see the LICENSE file for details.