Expand description
0x Swap API Client
A Rust client for interacting with the 0x Swap API.
§Example
use waterpump_evm_zerox_client::{ZeroExSwapClient, PriceRequest};
use alloy_primitives::Address;
let client = ZeroExSwapClient::new("your-api-key".to_string());
// Get a price quote
let request = PriceRequest {
chain_id: 1,
buy_token: Address::from_str("0xdac17f958d2ee523a2206206994597c13d831ec7")?,
sell_token: Address::from_str("0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48")?,
sell_amount: "100000000".to_string(),
taker: None,
tx_origin: None,
recipient: None,
swap_fee_recipient: None,
swap_fee_bps: None,
swap_fee_token: None,
trade_surplus_recipient: None,
trade_surplus_max_bps: None,
gas_price: None,
slippage_bps: None,
excluded_sources: None,
sell_entire_balance: None,
enable_plasma: None,
};
let price = client.get_price_allowance_holder(request).await?;
println!("Buy amount: {}", price.buy_amount);
// Get supported chains
let chains = client.get_chains().await?;
for chain in chains.chains() {
println!("{}: {}", chain.chain_name, chain.chain_id);
}Re-exports§
pub use client::ZeroExSwapClient;pub use error::Result;pub use error::ZeroExApiError;pub use swapper::is_native_token;pub use swapper::QuoteResult;pub use swapper::SwapOptions;pub use swapper::SwapResult;pub use swapper::ZeroExSwapper;pub use swapper::NATIVE_TOKEN_ADDRESS;pub use traits::IZeroExSwapper;pub use types::AllowanceIssue;pub use types::AllowanceType;pub use types::BalanceIssue;pub use types::ChainId;pub use types::ChainInfo;pub use types::ChainsResponse;pub use types::FeeDetail;pub use types::Fees;pub use types::Fill;pub use types::Issues;pub use types::Permit2Info;pub use types::PriceRequest;pub use types::PriceResponse;pub use types::QuoteRequest;pub use types::QuoteResponse;pub use types::Route;pub use types::TokenInfo;pub use types::TokenMetadata;pub use types::TokenTaxInfo;pub use types::Transaction;