@@ -45,22 +45,22 @@ Calling the [**Get Route API**](solve-get-route-v1) returns the finalized route,
4545- ** Base:** ` https://swaps.sprinter.tech/base `
4646
4747``` ts title="Example Fetch Quote Request Payload"
48- const AMOUNT_IN; // the amount of token that you want exchange in their decimals denomination
49- const TOKEN_IN_ADDRESS; // token_in_address
50- const TOKEN_OUT_ADDRESS; // token_out_addres - tokens that you want to receieve
51- const SLIPPAGE; // the slipapge that you want to allow for the swap ( 0.5 - 2%)
52- const TARGET_DURATION;
48+ const AMOUNT_IN = " 100000000" ; // the amount of token you want to exchange, in its smallest unit (as a string)
49+ const TOKEN_IN_ADDRESS = " 0x..." ; // address of the token you want to sell
50+ const TOKEN_OUT_ADDRESS = " 0x..." ; // address of the token you want to buy
51+ const SLIPPAGE_BPS = 50 ; // slippage in basis points (e.g., 50 = 0.5%)
52+ const API_USER = " your_api_user" ;
53+ const API_PASS = " your_api_pass" ;
5354
5455const fetchRoute = async () => {
55- const response = await fetch (
56- " https://swaps.sprinter.tech/mainnet/v2/route?amount_in=[AMOUNT_IN]&token_in=[TOKEN_IN_ADDRESS]&token_out=[TOKEN_OUT_ADDRESS]&slippage=[SLIPPAGE]&target_duration_ms=[TARGET_DURATION]" ,
57- {
58- method: " GET" ,
59- headers: {
60- " X-API-Key" : " your_api_key_here" ,
61- },
56+ const url = ` https://swaps.sprinter.tech/mainnet/v1/route?amountIn=${AMOUNT_IN }&tokenIn=${TOKEN_IN_ADDRESS }&tokenOut=${TOKEN_OUT_ADDRESS }&slippageBps=${SLIPPAGE_BPS } ` ;
57+
58+ const response = await fetch (url , {
59+ method: " GET" ,
60+ headers: {
61+ Authorization: " Basic " + btoa (` ${API_USER }:${API_PASS } ` ),
6262 },
63- );
63+ } );
6464
6565 const data = await response .json ();
6666 return data ;
0 commit comments