Utvecklingsportal
Tema

Get Intent Quotes#

Get the best quote for a swap through OKX DEX.

Request URL#

GET
https://web3.okx.com/api/v6/dex/aggregator/quote

Request Parameters#

ParameterTypeRequiredDescription
chainIndexStringYesUnique identifier for the chain.
e.g., 1: Ethereum.
See more here.
amountStringYesThe input amount of a token to be sold (if swapMode=exactIn) or buy (if swapMode=exactOut), set in minimal divisible units, e.g., 1.00 USDT set as 1000000, 1.00 DAI set as 1000000000000000000, you could get the minimal divisible units from Token Basic Information.
swapModeStringYesPossible values: [exactIn, exactOut].
Default: exactIn.
exactOut is for supporting use cases where you need an exact output amount.

Note:
1.ExactOut feature currently only support Ethereum、Base、BSC 、Arbitrum chain.
2.ExactOut feature currently support only Uni v3 protocols
3. In this case the slippage is on the input token.
fromTokenAddressStringYesThe contract address of a token to be sold (e.g., 0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee)
toTokenAddressStringYesThe contract address of a token to be bought (e.g., 0xa892e1fef8b31acc44ce78e7db0a2dc610f92d00)
dexIdsStringNoDexId of the liquidity pool for limited quotes, multiple combinations separated by , (e.g.,1,50,180, see liquidity list for more)
excludeDexIdsStringNoThe dexId of the liquidity pool will not be used, multiple combinations separated by , (e.g.,1,50,180, see liquidity list for more)
forJitoBundleBooleanNoDefalut is false.Set to true if the quote will be used in a Jito bundle. When enabled, the router excludes DEXes that are incompatible with Jito bundles, such as HumidiFi and BisonFi.
excludePoolAddressesStringNoSpecify pool addresses to exclude from routing. Up to 20 addresses are supported, separated by commas.
directRouteBooleanNoThe default setting is false. When enabled, Direct Routes restrict our routing to a single liquidity pool only. Currently, this feature is only active for Solana swaps.
singleRouteOnlyBooleanNoDefault is false. When enabled, routing is restricted to a single route.Multi-hop and multi-pool routes are allowed, but no parallel split routes will be constructed
singlePoolPerHopBooleanNoDefault is false. When enabled, each hop in the route is restricted to a single pool.
assetAwareRoutingBooleanDefault is false. When enabled routing will consider pair-related asset properties. For example, in U-U token pairs, routes are restricted to stable assets. Currently only support in U-U and U-Native token pairs
priceImpactProtectionPercentStringNoThis is an optional feature. The default value is 90 (representing 90%). The priceImpactProtectionPercent parameter can be set between 0 and 100.
When it’s set to 100, the feature is disabled and every transaction will be allowed to pass.
If the estimated price impact is above the percentage indicated, an error will be returned. For example, if priceImpactProtectionPercent = 25 (25%), any quote with a price impact higher than 25% will return an error.
Note: If we’re unable to calculate the price impact, we’ll return null, and the price impact protection will be disabled.
feePercentStringNoThe percentage of fromTokenAmount will be sent to the referrer's address, the rest will be set as the input amount to be sold.
min percentage> 0
max percentage: 10 for Solana, 3 for all other chains.
By configuring this parameter, you can obtain the final amount of totoken provided to the user after deducting the commission from fromtoken.
A maximum of nine decimal places is allowed.
If more decimals are entered, the system will automatically round up.
modeStringNoRouting mode. Possible values: dex, intent, auto. Default: dex.
- dex: Standard DEX aggregator routing.
- intent: Routes through the intent protocol, where solvers compete to fill the order off-chain.
- auto: The system automatically selects the optimal routing mode.
userWalletAddressStringNoThe wallet address of the user. Required when mode is intent or auto for intent-based quote and signing flows.
expirationStringNoThe expiry duration for the intent order in seconds. Default: 180, Max: 300. Only applicable when mode is intent or auto.
slippagePercentStringNoSlippage tolerance percentage (0–100). For example, 0.5 represents 0.5% slippage tolerance. when mode = auto,intent it is required.
swapReceiverAddressStringNoThe wallet address to receive the output tokens. If not provided, defaults to userWalletAddress.
fromTokenReferrerWalletAddressStringNoThe referrer wallet address for receiving fromToken commission. Used together with feePercent.
toTokenReferrerWalletAddressStringNoThe referrer wallet address for receiving toToken commission.
disableRFQBooleanNoDefault is false. When set to true, RFQ (Request for Quote) routing is disabled and only on-chain DEX routes are used.

Response Parameters#

ParameterTypeDescription
chainIndexStringUnique identifier for the chain.
swapModeStringSwap mode of this quote.
modeStringThe routing mode used for this quote, reflecting the mode request parameter. Possible values: dex, intent, auto.
quoteIdStringA unique identifier for this quote.
contextSlotIntegerThe blockchain slot number at the time the quote was generated. Used to reference the on-chain state at quote time (primarily relevant for Solana-based chains).
swapModeStringSwap mode encoding.
dexRouterListArrayQuote path data set.
fromTokenAmountStringThe input amount of a token to be sold (e.g., 500000000000000000000000).
toTokenAmountStringThe resulting estimated amount of a token to be bought. Please refer to the actual on-chain execution result (e.g., 168611907733361).
tradeFeeStringEstimated network fee (USD) of the quote route.
estimateGasFeeStringEstimated gas consumption, returned in the smallest unit of each chain, such as wei.
routerStringMain path for the token swap.
fromTokenObjectThe information of a token to be sold.
> tokenContractAddressStringToken contract address (e.g., 0xa892e1fef8b31acc44ce78e7db0a2dc610f92d00).
> tokenSymbolStringToken symbol.
> tokenUnitPriceStringThe token unit price returned by this interface is a general USD real-time price based on data from on-chain sources. Note: This price is only a recommended price. For some special cases, the token unit price may be null.
> decimalStringThe decimal number defines the smallest unit into which a single currency token can be divided.
> isHoneyPotBooleanWhether the token is a honeypot token. true: yes; false: no.
> taxRateStringToken tax rate for selling. Returns 0 for regular tokens without tax. The value ranges from 0 to 1, where 0.01 represents 1%.
toTokenObjectThe information of a token to be bought.
> tokenContractAddressStringToken contract address (e.g., 0xa892e1fef8b31acc44ce78e7db0a2dc610f92d00).
> tokenSymbolStringToken symbol.
> tokenUnitPriceStringThe token unit price returned by this interface is a general USD price based on data from on-chain, exchange, and other third-party sources. Note: This price is only a recommended price. For some special cases, the token unit price may be null.
> decimalStringThe decimal number defines the smallest unit into which a single currency token can be divided.
> isHoneyPotBooleanWhether the token is a honeypot token. true: yes; false: no.
> taxRateStringToken tax rate for buying. Returns 0 for regular tokens without tax. The value ranges from 0 to 1, where 0.01 represents 1%.
priceImpactPercentStringPercentage = (received value - paid value) / paid value. The swap amount will affect the liquidity pool depth and may cause a value difference. This percentage can be positive if the received value exceeds the paid value, e.g., 5 represents 5%.
signDataObjectSigning data required for intent orders.
> domainObjectEIP-712 domain separator information.
> > nameStringProtocol name.
> > versionStringProtocol version.
> > chainIdIntegerChain ID.
> > verifyingContractStringAddress of the contract that verifies the signature.
> messageObjectThe order body to be signed.
> > appDataStringApplication data hash.
> > commissionInfosArrayCommission info list.
> > > feePercentStringFee rate.
> > > referrerWalletAddressStringWallet address receiving the commission.
> > > flagStringBitmap encoding the fee routing rules.
> > fromTokenAddressStringSell token contract address.
> > toTokenAddressStringBuy token contract address.
> > ownerStringOrder owner wallet address.
> > partiallyFillableBooleanWhether partial fills are allowed.
> > receiverStringWallet address receiving the output token.
> > fromTokenAmountStringSell amount.
> > toTokenAmountStringBuy amount.
> > validToIntegerOrder expiry Unix timestamp.
> primaryTypeStringEIP-712 primary type, fixed as Order.
> typesObjectEIP-712 type definitions.
> > OrderArrayField type definitions for the Order struct.
> > CommissionInfoArrayField type definitions for the CommissionInfo struct.
> > EIP712DomainArrayField type definitions for the EIP712Domain struct.

Request Example#

shell
curl --location --request GET 'https://web3.okx.com/api/v6/dex/aggregator/quote?amount=10000000000000000000&chainIndex=1&toTokenAddress=0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48&fromTokenAddress=0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee' \

--header 'OK-ACCESS-KEY: 37c541a1-****-****-****-10fe7a038418' \
--header 'OK-ACCESS-SIGN: leaV********3uw=' \
--header 'OK-ACCESS-PASSPHRASE: 1****6' \
--header 'OK-ACCESS-TIMESTAMP: 2023-10-18T12:21:41.274Z'

Response Example#

Intent Mode#

json
{
    "code": "0",
    "data": [
        {
            "chainIndex": "1",
            "contextSlot": 0,
            "dexRouterList": [],
            "estimateGasFee": "0",
            "fromToken": {
                "decimal": "18",
                "isHoneyPot": false,
                "taxRate": "0",
                "tokenContractAddress": "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2",
                "tokenSymbol": "WETH",
                "tokenUnitPrice": "2498.123456789012345678901234567890"
            },
            "fromTokenAmount": "10000000000000000000",
            "mode": "INTENT",
            "priceImpactPercent": "-0.35",
            "quoteId": "10000000000000001",
            "router": "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2--0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48",
            "signData": {
                "domain": {
                    "chainId": 1,
                    "name": "OKX Intent Swap",
                    "verifyingContract": "0x1111111254fb6c44bac0bed2854e76f90643097d",
                    "version": "v1.0.0"
                },
                "message": {
                    "appData": "0xa1b2c3d4e5f6a1b2c3d4e5f6a1b2c3d4e5f6a1b2c3d4e5f6a1b2c3d4e5f6a1b2",
                    "commissionInfos": [
                        {
                            "feePercent": "30000000",
                            "flag": "86412300000000000000000000000000000000000000000000000000000000000000",
                            "referrerWalletAddress": "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266"
                        },
                        {
                            "feePercent": "10000000",
                            "flag": "86567800000000000000000000000000000000000000000000000000000000000000",
                            "referrerWalletAddress": "0x70997970C51812dc3A010C7d01b50e0d17dc79C8"
                        }
                    ],
                    "fromTokenAddress": "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2",
                    "fromTokenAmount": "10000000000000000000",
                    "owner": "0x5B38Da6a701c568545dCfcB03FcB875f56beddC4",
                    "partiallyFillable": false,
                    "receiver": "0x5B38Da6a701c568545dCfcB03FcB875f56beddC4",
                    "swapMode": "0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef12",
                    "toTokenAddress": "0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48",
                    "toTokenAmount": "24900000000",
                    "validTo": 1893456000
                },
                "primaryType": "Order",
                "types": {
                    "Order": [
                        { "name": "fromTokenAddress", "type": "address" },
                        { "name": "toTokenAddress", "type": "address" },
                        { "name": "owner", "type": "address" },
                        { "name": "receiver", "type": "address" },
                        { "name": "fromTokenAmount", "type": "uint256" },
                        { "name": "toTokenAmount", "type": "uint256" },
                        { "name": "validTo", "type": "uint32" },
                        { "name": "appData", "type": "bytes32" },
                        { "name": "swapMode", "type": "bytes32" },
                        { "name": "partiallyFillable", "type": "bool" },
                        { "name": "commissionInfos", "type": "CommissionInfo[]" }
                    ],
                    "CommissionInfo": [
                        { "name": "feePercent", "type": "uint256" },
                        { "name": "referrerWalletAddress", "type": "address" },
                        { "name": "flag", "type": "uint256" }
                    ],
                    "EIP712Domain": [
                        { "name": "name", "type": "string" },
                        { "name": "version", "type": "string" },
                        { "name": "chainId", "type": "uint256" },
                        { "name": "verifyingContract", "type": "address" }
                    ]
                }
            },
            "swapMode": "exactIn",
            "toToken": {
                "decimal": "6",
                "isHoneyPot": false,
                "taxRate": "0",
                "tokenContractAddress": "0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48",
                "tokenSymbol": "USDC",
                "tokenUnitPrice": "1"
            },
            "toTokenAmount": "24950000000",
            "tradeFee": "0"
        }
    ],
    "msg": ""
}