Endpoint
POST /createSwap
Description
This endpoint initiates a multi-chain token swap transaction. Users must provide source and destination chain IDs, token details, addresses, and swap parameters.
Request Structure
URL :
https://multichain-api-bd341ad6bfc7.herokuapp.com/createSwap
HTTP Method :
POST
Headers :
Content-Type: application/json
Authorization: <API_KEY>
An API key for authentication must be provided in the Authorization
header.
Request Body (JSON):
The chain ID of the source blockchain.
The token identifier on the source chain. For sending native chain tokens (eth, bsc, poly, etc) please use
Copy 0x0000000000000000000000000000000000000000
For sol:
Copy 11111111111111111111111111111111
other wise use the token's address.
The chain ID of the destination blockchain.
The token identifier on the destination chain. For receving native chain tokens (eth, bsc, poly, etc) please use
Copy 0x0000000000000000000000000000000000000000
For sol:
Copy 11111111111111111111111111111111
other wise use the token's address.
The recipient wallet address on the destination chain.
The authority wallet address on the source chain initiating the transaction.
The authority wallet address on the destination chain for the transaction.
The amount of tokens to be swapped.
The acceptable slippage percentage. Set to
"auto"
or don't include to use automatically adjusted slippage.
Example Request
Request URL :
POST https://multichain-api-bd341ad6bfc7.herokuapp.com/createSwap
Headers :
Authorization: <API_KEY>
Content-Type: application/json
Request Body :
Copy //This example will swap 0.1 ARB for CRX (eth)
{
"source_chain": 42161,
"source_token": "0x0000000000000000000000000000000000000000",
"dest_chain": 1,
"dest_token": "0x49218282042072e054afdc90e552e832735f8316",
"dest_address": "0xDestinationWalletAddress",
"src_authority_address": "0xSourceAuthorityWallet",
"dst_authority_address": "0xDestinationAuthorityWallet",
"amount": 0.1,
"slippage": "auto"
}
Note : If slippage
is not provided, it defaults to "auto"
.
Example Response
Success Response :
Copy {
"status": 1,
"swapTxInfo": {
"approximateTimeInSeconds": 12,
"dstChainToken": {
"address": "0x49218282042072e054afdc90e552e832735f8316",
"amount": "2776816417315670140859",
"approximateUsdValue": 307.2314919404435,
"chainId": 1,
"decimals": 18,
"maxTheoreticalAmount": "2785171933115015186418",
"maxTheoreticalApproximateUsdValue": 308.1559598199032,
"name": "Cerebro",
"recommendedAmount": "2776816417315670140859",
"recommendedApproximateUsdValue": 307.2314919404435,
"symbol": "CRX"
},
"srcChainToken": {
"address": "0x0000000000000000000000000000000000000000",
"amount": "102756853086491862",
"approximateOperatingExpense": "2756853086491862",
"approximateUsdValue": 343.3777376774561,
"chainId": 42161,
"decimals": 18,
"mutatedWithOperatingExpense": true,
"name": "Ethereum",
"originApproximateUsdValue": 334.16529152408964,
"symbol": "ETH"
},
"unsignedTx": {
"data": "0xb930370100000000000000000000000000000000000000000000000000000000000000c0000000000000000000000000000000000000000000000000000001941ec7fef70000000000000000000000000000000000000000000000000000000000000360000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000003c000000000000000000000000000000000000000000000000000000000000003e00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000016d10d03e7514d600000000000000000000000000000000000000000000000000000000000001600000000000000000000000000000000000000000000000968811ab583d5f27bb000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000001a0000000000000000000000000a1a6abcbd4b267b3839956df59308bc597628acd00000000000000000000000000000000000000000000000000000000000001e0000000000000000000000000000000000000000000000000000000000000022000000000000000000000000000000000000000000000000000000000000002600000000000000000000000000000000000000000000000000000000000000280000000000000000000000000000000000000000000000000000000000000001449218282042072e054afdc90e552e832735f83160000000000000000000000000000000000000000000000000000000000000000000000000000000000000014a1a6abcbd4b267b3839956df59308bc597628acd0000000000000000000000000000000000000000000000000000000000000000000000000000000000000014a1a6abcbd4b267b3839956df59308bc597628acd0000000000000000000000000000000000000000000000000000000000000000000000000000000000000014555ce236c0220695b68341bc48c68d52210cc35b0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000341d3585cd23cd206aa5e6b8344c26eb1588fed0df0000000000000000000000000000000000000000000000000003a6917143bb17000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000420101000000d614ebe057cb0900000000000000000000000000bb275f3d58ab1188960000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
"to": "0xeF4fB24aD0916217251F553c0596F8Edc630EB66",
"value": "103756853086491862"
}
}
}
Example Error Response :
Copy {
"status": 0
"ErrorCode": "INVALID QUERY PARAMETERS",
"errorMessage": "dstChainOrderAuthorityAddress has unexpected address representation: expecting EVM-compatible 40 character hexadecimal address representation"
}
Error codes:
403 - incorrect or expired api key
400 - incorrect arguments/request inputs
401 - swap tx creation error
Parameter Details
source_chain
/ dest_chain
:
The unique identifier for the blockchain networks. Example IDs: 1
for Ethereum, 56
for Binance Smart Chain.
source_token
/ dest_token
:
The tokens to be swapped between the source and destination chains. Provide token symbols or contract identifiers.
dest_address
:
The wallet address to receive the swapped tokens on the destination chain. Ensure it's valid for the specified chain.
src_authority_address
/ dst_authority_address
:
Authority addresses needed to validate the transaction. These are typically associated with the initiating and receiving parties.
amount
:
The number of tokens to swap. Must be a positive number.
slippage
:
The maximum allowable price movement during the swap. Use a numerical percentage (e.g., 1
for 1%) or "auto"
to use the default slippage.
All available chains and fees:
Full Code Examples:
Python :
Copy import requests
url = 'https://multichain-api-bd341ad6bfc7.herokuapp.com/createSwap'
params = {
"source_chain": 42161,
"source_token": "0x0000000000000000000000000000000000000000",
"dest_chain": 1,
"dest_token": "0x49218282042072e054afdc90e552e832735f8316",
"dest_address": "0xDestinationWalletAddress",
"src_authority_address": "0xSourceAuthorityWallet",
"dst_authority_address": "0xDestinationAuthorityWallet",
"amount": 0.1,
"slippage": "auto"
}
headers = {
'Content-type': 'application/json',
"Authorization": 'API_KEY'
}
response = requests.post(url, headers=headers, json=params)
print(response.status_code, response.json())
Node.js:
Copy const axios = require('axios');
const url = 'https://multichain-api-bd341ad6bfc7.herokuapp.com/createSwap';
params = {
"source_chain": 42161,
"source_token": "0x0000000000000000000000000000000000000000",
"dest_chain": 1,
"dest_token": "0x49218282042072e054afdc90e552e832735f8316",
"dest_address": "0xDestinationWalletAddress",
"src_authority_address": "0xSourceAuthorityWallet",
"dst_authority_address": "0xDestinationAuthorityWallet",
"amount": 0.1,
"slippage": "auto"
};
const headers = {
'Content-Type': 'application/json',
'Authorization': 'API_KEY'
};
axios.post(url, params, { headers })
.then(response => {
console.log(response.status);
console.log(response.data);
})
.catch(error => {
console.error(error.response ? error.response.data : error.message);
});
cURL:
Copy curl -X POST https://multichain-api-bd341ad6bfc7.herokuapp.com/createSwap \
-H "Content-Type: application/json" \
-H "Authorization: API_KEY" \
-d '{
"source_chain": 42161,
"source_token": "0x0000000000000000000000000000000000000000",
"dest_chain": 1,
"dest_token": "0x49218282042072e054afdc90e552e832735f8316",
"dest_address": "0xDestinationWalletAddress",
"src_authority_address": "0xSourceAuthorityWallet",
"dst_authority_address": "0xDestinationAuthorityWallet",
"amount": 0.1,
"slippage": "auto"
}'