Execute a Cross Chain Swap
This section explains the integration and usage of bridge protocols for cross-chain swapping functionalities.
Step 1: Check the Allowance of the Bridge on the Token Contract
To initiate a swap, first determine if the Bridge has the necessary allowance to access the tokens. This can be done using the following API endpoint:
API URL:
https://api.expand.network/fungibletoken/getuserallowance
Sample Request:
https://api.expand.network/fungibletoken/getuserallowance?owner=0x6Fb447Ae94F5180254D436A693907a1f57696900&tokenAddress=0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2&spender=0xBA12222222228d8Ba445958a75a0704d566BF2C8
Sample Response:
{
"status": 200,
"msg": "success",
"data": {
"allowance": "999000000000000000000"
}
}
Step 2: Approve the Bridge from the Token Contract
If the allowance is less than the token amount to be swapped, the user must approve the Bridge contract from the token contract. This can be done using the following API endpoint:
API URL:
https://api.expand.network/fungibletoken/approve
Sample Request:
{
"from": "0x6Fb447Ae94F5180254D436A693907a1f57696900",
"tokenAddress":"0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2",
"amount": "1000000000000000000000",
"to": "0x6Fb447Ae94F5180254D436A693907a1f57696900",
"gas": "100000",
"chainId": "1"
}
Sample Response:
{
"status": 200,
"msg": "success",
"data": {
"from": "0x6Fb447Ae94F5180254D436A693907a1f57696900",
"to": "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2",
"value": "0",
"gas": "100000",
"data": "0x095ea7b3000000000000000000000000828b154032950c8ff7cf8085d841723db269605600000000000000000000000000000000000000000000003635c9adc5dea00000"
}
}
Step 3: Swap the tokens
After the successful approval, we can do the swap. User can swap the tokens on their preferred Bridge by changing the "bridgeId" parameter. This can be done using the following API endpoint:
API URL:
https://api.expand.network/bridge/swap
Sample Request:
{
"bridgeId": "200",
"srcChainId": "1",
"dstChainId": "137",
"srcTokenSymbol": "WETH",
"dstTokenSymbol": "USDC",
"amountIn": "100000000000000",
"from": "0x6Fb447Ae94F5180254D436A693907a1f57696900",
"gas": "920000",
"to": "0x6Fb447Ae94F5180254D436A693907a1f57696900"
}
Sample Response:
{
"status": 200,
"msg": "success",
"data": {
"from": "0x6Fb447Ae94F5180254D436A693907a1f57696900",
"to": "0xce16F69375520ab01377ce7B88f5BA8C48F8D666",
"value": "83660648338674",
"gas": "920000",
"data": "0x846a1bc6000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc200000000000000000000000000000000000000000000000000005af3107a4000000000000000000000000000000000000000000000000000000000000000012000000000000000000000000000000000000000000000000000000000000004a000000000000000000000000000000000000000000000000000000000000004e000000000000000000000000000000000000000000000000000000000000005200000000000000000000000000000000000000000000000000000000000000580000000000000000000000000a67e9b68c41b0f26184d64c26e0b2b81466e599400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000001800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000001200000000000000000000000000000000000000000000000000000000000000044095ea7b300000000000000000000000068b3465833fb72a70ecdf485e0e4c7bd8665fc4500000000000000000000000000000000000000000000000000005af3107a4000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000068b3465833fb72a70ecdf485e0e4c7bd8665fc45000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000001c000000000000000000000000000000000000000000000000000000000000000e404e45aaf000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb4800000000000000000000000000000000000000000000000000000000000001f4000000000000000000000000ce16f69375520ab01377ce7b88f5ba8c48f8d66600000000000000000000000000000000000000000000000000005af3107a400000000000000000000000000000000000000000000000000000000000000265460000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000455534443000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000007506f6c79676f6e00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002a3078636531364636393337353532306162303133373763653742383866354241384334384638443636360000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000005800000000000000000000000000000000000000000000000000000000000000040000000000000000000000000a67e9b68c41b0f26184d64c26e0b2b81466e599400000000000000000000000000000000000000000000000000000000000000030000000000000000000000000000000000000000000000000000000000000060000000000000000000000000000000000000000000000000000000000000016000000000000000000000000000000000000000000000000000000000000002e000000000000000000000000000000000000000000000000000000000000000030000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000000c000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000020000000000000000000000000750e4c4984a9e0f12978ea6742bc1c5d248f40ed0000000000000000000000000000000000000000000000000000000000000001000000000000000000000000750e4c4984a9e0f12978ea6742bc1c5d248f40ed000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000001200000000000000000000000000000000000000000000000000000000000000044095ea7b3000000000000000000000000f9c2b5746c946ef883ab2660bbbb1f10a5bdeab40000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000040000000000000000000000000750e4c4984a9e0f12978ea6742bc1c5d248f40ed00000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000001000000000000000000000000f9c2b5746c946ef883ab2660bbbb1f10a5bdeab4000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000001e00000000000000000000000000000000000000000000000000000000000000104a8c9ed67000000000000000000000000750e4c4984a9e0f12978ea6742bc1c5d248f40ed0000000000000000000000002791bca1f2de4661ed88a30c99a7a9449aa841740000000000000000000000000000000000000000000000000000000000000008000000000000000000000000a67e9b68c41b0f26184d64c26e0b2b81466e59940000000000000000000000000000000000000000000000000000018b4beef6870000000000000000000000000000000000000000000000000000000000026a3b00000000000000000000000000000000000000000000000000000000000264100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000040000000000000000000000000750e4c4984a9e0f12978ea6742bc1c5d248f40ed0000000000000000000000000000000000000000000000000000000000000005"
}
}
Last updated