Dies ist eine zweisprachige Schnappschussseite, die vom Benutzer um 2024-10-26 6:11 für https://docs.changelly.com/dex/#tag/Flow-example gespeichert wurde, mit zweisprachiger Unterstützung bereitgestellt von Immersive Übersetzung. Wie speichern?

Changelly DEX API

Download OpenAPI specification:Download

DEX Aggregator API

Key features:

  • 7 supported blockchains:
    • Ethereum;
    • Optimistic Ethereum;
    • BNB Smart Chain;
    • Polygon;
    • Fantom;
    • Avalanche;
    • Arbitrum.
  • Over 100 connected liquidity sources and 3600 tokens available for exchange.
  • Full cycle of preparing a transaction for tokens exchange in the network.

You can check an example of a DEX service developed on the basis of the DEX API.

Get Started

  1. URL for API – https://dex-api.changelly.com/.
  2. Without an API access key, a number of requests per second is limited, suitable for testing and development.
  3. To obtain the key, contact pro@changelly.com.
  4. The given key should be added to the header of each request, parameter {X-API-Key: <key>}.

Flow example

  1. API — provides a list of supported blockchains upon v1/platforms request.
  2. GUI — the user selects a network the exchange is made within. For example, Ethereum, ChainID=1.
  3. API — provides a list of blockchain tokens upon request /v2/tokens/list. In our example, POST /v2/tokens/list.
  4. API (optional) – provides calculated gas price values in GWEI (nAVAX for Avalanche) upon /v1/{chainID}/gasprices request. The gas price values are returned for fast, medium and low transaction time.
  5. GUI — the user selects the exchange tokens and the sale amount. For example, 1000 USDT to WBTC.
  6. GUI — the user sets the slippage tolerance value in percentage. The recommended value is 1%.
  7. GUI (optional) — the user selects the gas price value from pt 4.
  8. API — endpoint /v1/{chainID}/price provides the number of the tokens which the user will get for the purchase (0.05 WBTC).
  9. GUI — the user connects the wallet.
  10. API — endpoint /v1/{chainID}/transaction/allowance returns the amount of tokens that the exchange smart contract has access to (not required for native coins).
  11. GUI — if the value of the sale is greater than the value from pt 10, the user is prompted to provide access for the tokens exchange (otherwise the exchange transaction will not be processed).
  12. API — endpoint /v1/{chainID}/transaction/approve returns the input parameters (calldata) for a transaction to provide access to tokens, and the address of the contract where the transaction should be sent to.
  13. GUI — generates an unsigned transaction based on the data from pt 12 and sends it to the user's connected wallet.
  14. WALLET — the user confirms the operation in the wallet, and the wallet then signs the transaction and sends it to the blockchain.
  15. GUI — after successful confirmation of the transaction from pt 14, the user is offered a button to exchange the selected tokens.
  16. API — endpoint /v1/{chainID}/quote provides the number of the tokens purchased (0.05 WBTC) and transaction input parameters.
  17. GUI — generates an unsigned transaction based on the data from pt 16 and sends it to the user's connected wallet.
  18. WALLET — the user confirms the operation in the wallet, and the wallet then signs the transaction and sends it to the blockchain.

Blockchains

Provides a list of supported blockchains.

header Parameters
X-Api-Key
string

Your API access key. Without an API access key, a number of requests per second is limited.

Responses

Request samples

curl --location --request GET
'https://dex-api.changelly.com/v1/platforms'

Response samples

Content type
application/json
{
  • "platforms": [
    ]
}

Tokens

Returns list of tokens with filtration and pagination.

header Parameters
X-Api-Key
string

Your API access key. Without an API access key, a number of requests per second is limited.

Request Body schema: application/json

Filter with pagination.

Note. Only paging object is required.

object (filter)

Object with information for filtration.

required
object (paging)

Object with information for pagination.

Responses

Request samples

Content type
application/json
{
  • "filter": {
    },
  • "paging": {
    }
}

Response samples

Content type
application/json
{}

Gas prices

Provides calculated gas price values in GWEI (nAVAX for Avalanche).

path Parameters
chainId
required
integer
Example: 1

Blockchain ID.

List: https://chainlist.org/

header Parameters
X-Api-Key
string

Your API access key. Without an API access key, a number of requests per second is limited.

Responses

Request samples

curl --location --request GET
'https://dex-api.changelly.com/v1/1/gasprices'

Response samples

Content type
application/json
{
  • "low": "29.521",
  • "medium": "31.521",
  • "high": "33.521"
}

Liquidity sources

Provides a list of liquidity sources.

header Parameters
X-Api-Key
string

Your API access key. Without an API access key, a number of requests per second is limited.

Responses

Request samples

curl --location --request GET 
'https://dex-api.changelly.com/v1/sources'

Response samples

Content type
application/json

Exchange offer

Returns only the best exchange offer.

Doesn't generate the input parameters for creating exchange transaction.

path Parameters
chainId
required
integer
Example: 1

Blockchain ID.

List: https://chainlist.org/

query Parameters
fromTokenAddress
required
string
Example: fromTokenAddress=0xdac17f958d2ee523a2206206994597c13d831ec7

Smart contract address of the sale token.

toTokenAddress
required
string
Example: toTokenAddress=0x6b175474e89094c44da98b954eedeac495271d0f

Smart contract address of the purchase token.

amount
required
integer
Example: amount=1500000000

The amount of sale tokens in decimals of the token. Can be taken from the /{chainID}/tokens endpoint.

slippage
required
number
Example: slippage=1

The amount of slippage allowed during the actual execution of the transaction (10 = 1% slippage).

If the price changes by more than this percentage, the transaction will be reverted.

gasPrice
string
Example: gasPrice=16000000000

Gas price value for making a transaction in WEI (nAVAX for Avalanche).

1 GWEI = 1000000000 WEI.

Default value is the value high from the /{chainID}/gasprices endpoint.

feeRecipient
string
Example: feeRecipient=0xdac17f958d2ee523a2206206994597c13d831ec7

Wallet address for receiving fees.

The commission is paid from the purchase or sale token. It depends on which of the fields is sent in the request: buyTokenPercentageFee or sellTokenPercentageFee.

buyTokenPercentageFee
integer
Example: buyTokenPercentageFee=1

Percentage of commission from the amount of purchase tokens, is taken in favor of feeRecipient.

10 = 1%, maximum value is 500.

If you specify both fields (buyTokenPercentageFee and sellTokenPercentageFee) in the request, the commission will be taken from the amount of sale tokens.

sellTokenPercentageFee
integer
Example: sellTokenPercentageFee=1

Percentage of commission from the amount of sale tokens, is taken in favor of feeRecipient.

10 = 1%, maximum value is 500.

If you specify both fields (buyTokenPercentageFee and sellTokenPercentageFee) in the request, the commission will be taken from the amount of sale tokens.

header Parameters
X-Api-Key
string

Your API access key. Without an API access key, a number of requests per second is limited.

Responses

Request samples

curl --location --request GET 
'https://dex-api.changelly.com/v1/1/price?fromTokenAddress=0xdac17f958d2ee523a2206206994597c13d831ec7&toTokenAddress=0x6b175474e89094c44da98b954eedeac495271d0f&amount=1500000000&slippage=1&gasPrice=16000000000&feeRecipient=0xdac17f958d2ee523a2206206994597c13d831ec7&buyTokenPercentageFee=1&sellTokenPercentageFee=1'

Response samples

Content type
application/json
{
  • "amount_out_total": "1520418496203262297769",
  • "estimate_gas_total": "144085",
  • "token_in": "0xdac17f958d2ee523a2206206994597c13d831ec7",
  • "token_out": "0x6b175474e89094c44da98b954eedeac495271d0f",
  • "gas_price": "16000000000",
  • "fee_recipient_amount": "1518896558810500225",
  • "routes": {
    }
}

Transaction allowance

Checks how many user’s tokens the exchange smart contract has access to.

path Parameters
chainId
required
integer
Example: 1

Blockchain ID.

List: https://chainlist.org/

query Parameters
tokenAddress
required
string
Example: tokenAddress=0xdAC17F958D2ee523a2206206994597C13D831ec7

Smart contract address of the token for which access is being checked.

walletAddress
required
string
Example: walletAddress=0x58f58219e2d2598588c1b457bb6da65c34d99310

Wallet of the user for which access is being checked.

header Parameters
X-Api-Key
string

Your API access key. Without an API access key, a number of requests per second is limited.

Responses

Request samples

curl --location --request GET 
'https://dex-api.changelly.com/v1/1/transaction/allowance?tokenAddress=0xdAC17F958D2ee523a2206206994597C13D831ec7&walletAddress=0x58f58219e2d2598588c1b457bb6da65c34d99310'

Response samples

Content type
application/json
{
  • "remaining": "11579208923731620000"
}

Transaction approve

Generates input parameters for the access transaction. This transaction provides access to the user's tokens for the exchange smart contract.

Note. The endpoint doesn't generate transaction.

path Parameters
chainId
required
integer
Example: 1

Blockchain ID.

List: https://chainlist.org/

query Parameters
tokenAddress
required
string
Example: tokenAddress=0xdAC17F958D2ee523a2206206994597C13D831ec7

Smart contract address of the token for which access is being checked.

amount
required
integer
Example: amount=1500000000

The amount of sale tokens in decimals of the token. Can be taken from the /{chainID}/tokens endpoint.

gasPrice
string
Example: gasPrice=16000000000

Gas price value for making a transaction in WEI (nAVAX for Avalanche).

1 GWEI = 1000000000 WEI.

Default value is the value high from the /{chainID}/gasprices endpoint.

header Parameters
X-Api-Key
string

Your API access key. Without an API access key, a number of requests per second is limited.

Responses

Request samples

curl --location --request GET 
'https://dex-api.changelly.com/v1/1/transaction/approve?tokenAddress=0xdAC17F958D2ee523a2206206994597C13D831ec7&amount=100000000000&gasPrice=100000000000'

Response samples

Content type
application/json
{
  • "calldata": "0x095ea7b30000000000000000000000001aaad07998466cd3eb8140827dddb37570be1e63000000000000000000000000000000000000000000000000000000174876e800",
  • "estimate_gas": "48561",
  • "gas_price": "100000000000",
  • "to": "0xdac17f958d2ee523a2206206994597c13d831ec7"
}

Data for creating transaction

Returns the best route and generates input parameters for exchange transaction.

Note. The endpoint doesn't generate transaction.

path Parameters
chainId
required
integer
Example: 1

Blockchain ID.

List: https://chainlist.org/

query Parameters
fromTokenAddress
required
string
Example: fromTokenAddress=0xdac17f958d2ee523a2206206994597c13d831ec7

Smart contract address of the sale token.

toTokenAddress
required
string
Example: toTokenAddress=0x6b175474e89094c44da98b954eedeac495271d0f

Smart contract address of the purchase token.

amount
required
integer
Example: amount=1500000000

The amount of sale tokens in decimals of the token. Can be taken from the /{chainID}/tokens endpoint.

slippage
required
number
Example: slippage=1

The amount of slippage allowed during the actual execution of the transaction (10 = 1% slippage).

If the price changes by more than this percentage, the transaction will be reverted.

gasPrice
string
Example: gasPrice=16000000000

Gas price value for making a transaction in WEI (nAVAX for Avalanche).

1 GWEI = 1000000000 WEI.

Default value is the value high from the /{chainID}/gasprices endpoint.

feeRecipient
string
Example: feeRecipient=0xdac17f958d2ee523a2206206994597c13d831ec7

Wallet address for receiving fees.

The commission is paid from the purchase or sale token. It depends on which of the fields is sent in the request: buyTokenPercentageFee or sellTokenPercentageFee.

buyTokenPercentageFee
integer
Example: buyTokenPercentageFee=1

Percentage of commission from the amount of purchase tokens, is taken in favor of feeRecipient.

10 = 1%, maximum value is 500.

If you specify both fields (buyTokenPercentageFee and sellTokenPercentageFee) in the request, the commission will be taken from the amount of sale tokens.

sellTokenPercentageFee
integer
Example: sellTokenPercentageFee=1

Percentage of commission from the amount of sale tokens, is taken in favor of feeRecipient.

10 = 1%, maximum value is 500.

If you specify both fields (buyTokenPercentageFee and sellTokenPercentageFee) in the request, the commission will be taken from the amount of sale tokens.

recipientAddress
string
Example: recipientAddress=0xFD5c1C3d086a9CC0f21beaB6ddE3900C9351FC59

The address of the recipient of the tokens after the exchange.

If this field is not specified, then the recipient of the tokens will be the one who sends the transaction for the exchange.

takerAddress
string
Example: takerAddress=0xF9C7aE9200CAc6597AE57b0C047205c28A7f53f7

The wallet address from which the transaction will be performed.
If this field is specified, then the local transaction (dry-run) will be performed. It will allow you to validate the transaction and more accurately estimate the amount of gas that will be used during the transaction.

If the local transaction fails, the 500 error code and JSON will return as response.

skipValidation
boolean
Example: skipValidation=true

Validation flag. If value is true - validation will be skipped.

header Parameters
X-Api-Key
string

Your API access key. Without an API access key, a number of requests per second is limited.

Responses

Request samples

curl --location --request GET 
'https://dex-api.changelly.com/v1/1/quote?fromTokenAddress=0xdac17f958d2ee523a2206206994597c13d831ec7&toTokenAddress=0x6b175474e89094c44da98b954eedeac495271d0f&amount=1500000000&slippage=1&gasPrice=16000000000&feeRecipient=0xdac17f958d2ee523a2206206994597c13d831ec7&buyTokenPercentageFee=1&sellTokenPercentageFee=1&recipientAddress=0xFD5c1C3d086a9CC0f21beaB6ddE3900C9351FC59&takerAddress=0xF9C7aE9200CAc6597AE57b0C047205c28A7f53f7&skipValidation=true'

Response samples

Content type
application/json
{
  • "amount_out_total": "1494075314383326809742",
  • "estimate_gas_total": "401000",
  • "token_in": "0xdac17f958d2ee523a2206206994597c13d831ec7",
  • "token_out": "0x6b175474e89094c44da98b954eedeac495271d0f",
  • "gas_price": "16000000000",
  • "fee_recipient_amount": "1497002",
  • "routes": {
    },
  • "calldata": "0x351eb598000000000000000000000000fd5c1c3d086a9cc0f21beab6dde3900c9351fc.....00000eada1c640EF9200000",
  • "to": "0x1AAAd07998466cD3Eb8140827DDdb37570BE1e63"
}