🔸Price API

Step by step guide to set up the Marswap Aggregator API

GET/v1/swap/price

This endpoint can be used to request the amount of token received for a swap between two tokens.

Headers

NameValue

Marswap-Api-Key

string

Query Parameters

ParameterDescriptionRequiredType

sellToken

The address of the token you want to sell.

Yes

string

buyToken

The address of the token you want to buy.

Yes

string

sellAmount

The amount of sell token to swap in base units.

Yes

number

buyTokenOrSellTokenHasFees

Boolean indicating if buy or sell token has fees/taxes.

No. Default is true

boolean

slippagePercentage

Maximum slippage percentage for the swap.

Yes

number

integratorId

The integrator ID provided by the Marswap team for authentication.

Yes

string

buyTokenPercentageFee

The percentage of the buyAmount that will be sent to the feeRecipient as affiliate fees. Maximum is 1%.

No

number

feeRecipient

The wallet address that will receive affiliate fees from each trade.

No

string

Response

ParameterDescription

chainId

The blockchain network ID.

price

The calculated swap price of the buy token relative to the sell token.

minimumPrice

The minimum acceptable swap price of the buy token relative to the sell token considering slippage.

value

The amount of ETH in Wei to be sent in the transaction.

buyTokenAddress

The address of the token you want to buy.

buyAmount

The calculated amount of buy token to receive in base units.

sellTokenAddress

The address of the token you want to sell.

sellAmount

The amount of sell token to swap in base units.

sellTokenToEthRate

The exchange rate of sell token to ETH. Multiply this by the USD price of ETH to get the USD value of the sell token.

buyTokenToEthRate

The exchange rate of buy token to ETH. Multiply this by the USD price of ETH to get the USD value of the buy token.

swapFeeInEth

The swap fee in ETH.

allowanceTarget

The address of the contract to grant approval allowance to for the swap.

{
    "chainId": 109,
    "price": "3483.238112891189899652",
    "minimumPrice": "3465.821922326733950154",
    "value": "10010000000000000000",
    "buyTokenAddress": "0xabbaf2746c46f8f269e0a252285abe9d8d8cdf63",
    "buyAmount": "34832381128911898996523",
    "sellTokenAddress": "0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee",
    "sellAmount": "10000000000000000000",
    "sellTokenToEthRate": "1",
    "buyTokenToEthRate": "3521.22067806470155094",
    "swapFeeInEth": "10000000000000000",
    "allowanceTarget": "0x0000000000000000000000000000000000000000"
}

Example

curl -X GET \
  'https://shib-api.marswap.exchange/swap/v1/price?sellToken=0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee&buyToken=0xabbaf2746c46f8f269e0a252285abe9d8d8cdf63&slippagePercentage=0.05&buyTokenOrSellTokenHasFees=true&sellAmount=10000000000000000000&integratorId=test-api&feeRecipient=0x_fee_wallet_address&buyTokenPercentageFee=0.001' \
  -H 'marswap-api-key: 4b5f885c-b764-4160-95f4-00ceb5124abb'

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.

Read more here about setting token allowances.

Last updated