Skip to content

Commit 077e184

Browse files
authored
Update README.md
Pulled from jup-ag#1
1 parent b1d82f5 commit 077e184

File tree

1 file changed

+82
-4
lines changed

1 file changed

+82
-4
lines changed

README.md

Lines changed: 82 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,83 @@
1-
# Jupiter api rust example
1+
# jup-swap-api-client
22

3-
We can autogenerate a client with openapi-gen and the openapi schema but the structs cannot be directly consumed as solana sdk or appropirate rust types.
3+
## Introduction
44

5-
The crate `jupiter-swap-api` exposes the API types to allow
5+
The `jup-swap-api-client` is a Rust client library designed to simplify the integration of the Jupiter Swap API, enabling seamless swaps on the Solana blockchain.
66

7-
If you must use solana 1.16 crates, there is a work in progress to relax tokio pinned too low conflicting with many other crates https://github.com/solana-labs/solana/pull/32943
7+
### What is jup.ag?
8+
9+
[jup.ag](https://jup.ag/) is a powerful platform that provides developers with an easy way to access liquidity on the Solana blockchain. It simplifies the process of executing swaps by allowing you to specify the desired token pairs, amount, and slippage. In return, the API will provide you with the serialized transactions required to execute the swap on the Solana blockchain, complete with the necessary signatures.
10+
11+
## Getting Started
12+
13+
To use the `jup-swap-api-client` crate in your Rust project, follow these simple steps:
14+
15+
Add the crate to your `Cargo.toml`:
16+
17+
```toml
18+
[dependencies]
19+
jup-swap-api-client = "0.1.0"
20+
```
21+
22+
## Examples
23+
24+
Here's a simplified example of how to use the `jup-swap-api-client` in your Rust application:
25+
26+
```rust
27+
use jupiter_swap_api_client::{
28+
quote::QuoteRequest, swap::SwapRequest, transaction_config::TransactionConfig,
29+
JupiterSwapApiClient,
30+
};
31+
use solana_sdk::pubkey::Pubkey;
32+
33+
const USDC_MINT: Pubkey = pubkey!("EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v");
34+
const NATIVE_MINT: Pubkey = pubkey!("So11111111111111111111111111111111111111112");
35+
const TEST_WALLET: Pubkey = pubkey!("2AQdpHJ2JpcEgPiATUXjQxA8QmafFegfQwSLWSprPicm");
36+
37+
#[tokio::main]
38+
async fn main() {
39+
let jupiter_swap_api_client = JupiterSwapApiClient::new("https://quote-api.jup.ag/v6");
40+
41+
let quote_request = QuoteRequest {
42+
amount: 1_000_000,
43+
input_mint: USDC_MINT,
44+
output_mint: NATIVE_MINT,
45+
slippage_bps: 50,
46+
..QuoteRequest::default()
47+
};
48+
49+
// GET /quote
50+
let quote_response = jupiter_swap_api_client.quote(&quote_request).await.unwrap();
51+
println!("{quote_response:#?}");
52+
53+
// POST /swap
54+
let swap_response = jupiter_swap_api_client
55+
.swap(&SwapRequest {
56+
user_public_key: TEST_WALLET,
57+
quote_response: quote_response.clone(),
58+
config: TransactionConfig::default(),
59+
})
60+
.await
61+
.unwrap();
62+
63+
println!("Raw tx len: {}", swap_response.swap_transaction.len());
64+
65+
// Perform further actions as needed...
66+
67+
// POST /swap-instructions
68+
let swap_instructions = jupiter_swap_api_client
69+
.swap_instructions(&SwapRequest {
70+
user_public_key: TEST_WALLET,
71+
quote_response,
72+
config: TransactionConfig::default(),
73+
})
74+
.await
75+
.unwrap();
76+
println!("{swap_instructions:#?}");
77+
}
78+
79+
```
80+
For the full example, please refer to the [examples](../example/) directory in this repository.
881

982
### Using hosted swap API URLs
1083

@@ -13,3 +86,8 @@ You can set custom URLs via environment variables for any self-hosted Jupiter AP
1386
```
1487
API_BASE_URL=https://jupiter-swaps.quiknode.pro/D3ADB33F
1588
```
89+
90+
## Additional Resources
91+
92+
- [Jupiter Swap API Documentation](https://station.jup.ag/docs/v6/swap-api): Learn more about the Jupiter Swap API and its capabilities.
93+
- [Jup.ag Website](https://jup.ag/): Explore the official website for additional information and resources.

0 commit comments

Comments
 (0)