constparams= { sellToken:'0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee', buyToken:'0xabbaf2746c46f8f269e0a252285abe9d8d8cdf63', slippagePercentage:0.05, buyTokenOrSellTokenHasFees:true, sellAmount:'10000000000000000000', integratorId:'test-api',//Example ID feeRecipient:'0x_fee_wallet_address',// Enter wallet address to receive fee, buyTokenPercentageFee:0.001,//0.1% }// Construct the query stringconstsearch=Object.keys(params).reduce( (searchString, key) => (params[key] !==undefined?`${searchString}&${key}=${params[key]}`: searchString),'',)// Make a GET request to the API endpoint constresponse=awaitfetch(`https://shib-api.marswap.exchange/swap/v1/price?${search.slice(1)}`, { headers: {'marswap-api-key':'4b5f885c-b764-4160-95f4-00ceb5124abb'//Example API Key }})// Check if the response is okif (response.ok) {constrouteResponse=awaitresponse.json()console.log(routeResponse)} else {console.error('Failed to fetch data');}
import requestsparams ={'sellToken':'0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee','buyToken':'0xabbaf2746c46f8f269e0a252285abe9d8d8cdf63','slippagePercentage':0.05,'buyTokenOrSellTokenHasFees':True,'sellAmount':'10000000000000000000','integratorId':'test-api',# Example ID'feeRecipient':'0x_fee_wallet_address',# Enter wallet address to receive fee,'buyTokenPercentageFee':0.001,# 0.1%}# Construct the query stringsearch ='&'.join([f"{key}={value}"for key, value in params.items() if value isnotNone])# Make a GET request to the API endpointurl =f"https://shib-api.marswap.exchange/swap/v1/price?{search}"headers ={'marswap-api-key':'4b5f885c-b764-4160-95f4-00ceb5124abb'}# Example API Keyresponse = requests.get(url, headers=headers)# Check if the response is okif response.ok: route_response = response.json()print(route_response)else:print('Failed to fetch data')
Allowance
An "allowance" refers to the amount of a specific ERC-20 token that an owner has approved another Ethereum address to swap. In our case, we would like the Marswap Aggregator smart contract to trade ERC20 tokens.
To do so, we will need to give an allowance to the allowanceTarget parameter that's returned by the API. The allowanceTarget is the the target contract address, in our case the Marswap Aggregator smart contract address on the relevant network.
For swaps with "ETH" as sellToken, wrapping "ETH" to "WETH" or unwrapping "WETH" to "ETH" no allowance is needed.