/chainflip/broker/channel - Opening a Chainflip deposit channel
To initiate a swap through the CHAINFLIP
or CHAINFLIP_STREAMING
providers, a deposit channel must be opened first.
Method: POST
URL: https://api.swapkit.dev/chainflip/broker/channel
The information needed to open a channel is included inside the meta.chainflip
object of the /quote
response, as in the example below. The object needs to be passed to the /chainflip/broker/channel
endpoint, which creates a deposit channel.
It contains a deposit address for the chain initiating the swap, where the tokens can be sent to.
"meta": {
...
"chainflip": {
"sellAsset": {
"chain": "Ethereum",
"asset": "ETH"
},
"buyAsset": {
"chain": "Bitcoin",
"asset": "BTC"
},
"destinationAddress": "357a3So9CbsNfBBgFYACGvxxS6tMaDoa1P",
"affiliateFees": [{
"brokerAddress": "cFNwtr2mPhpUEB5AyJq38DqMKMkSdzaL9548hajN2DRTwh7Mq",
"feeBps": 100
}],
"refundParameters": {
"minPrice": "0x2c166186363d48000000000",
"refundAddress": "0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045",
"retryDuration": 150
}
}
}
As an example a channel can be requested as:
curl -X 'POST' \
'https://api.swapkit.dev/chainflip/broker/channel' \
-H 'Content-Type: application/json' \
-H "x-api-key: YOUR_VARIABLE_HERE" \
-d '{
"sellAsset": {
"chain": "Ethereum",
"asset": "ETH"
},
"buyAsset": {
"chain": "Bitcoin",
"asset": "BTC"
},
"destinationAddress": "357a3So9CbsNfBBgFYACGvxxS6tMaDoa1P",
"affiliateFees": [{
"brokerAddress": "cFNwtr2mPhpUEB5AyJq38DqMKMkSdzaL9548hajN2DRTwh7Mq",
"feeBps": 100
}],
"refundParameters": {
"minPrice": "0x2c166186363d48000000000",
"refundAddress": "0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045",
"retryDuration": 150
}
}'
The response contains a depositAddress
which funds can be sent to.
No approval is needed for this address in the case of ERC-20 tokens, and a memo is not needed either.
{
"depositAddress": "0xd3f189d1cab37e5dc1f920639ed13bf61132ab16",
"channelId": "6543210-Ethereum-1933",
"explorerUrl": "https://scan.chainflip.io/channels/6543210-Ethereum-1984"
}
Here is an example integrating a /quote
request with opening a channel:
async function swapThroughChainflip () {
const request = {
sellAsset: "SOL.SOL",
buyAsset: "BTC.BTC",
sellAmount: "1",
providers: ["CHAINFLIP", "CHAINFLIP_STREAMING"],
sourceAddress: "sol_address",
destinationAddress: "btc_address",
slippage: 1.5,
};
const quoteResponse = await fetch('https://api.swapkit.dev/quote', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'x-api-key': apiKey,
},
body: JSON.stringify(request),
});
const [chainflipRoute, chainflipStreamingRoute] = await quoteResponse.json();
// Pick deposit channel info from quote response
const chainflipDepositChannelParams = chainflipRoute.meta.chainflip;
// Use params to open deposit channel
const depositChannelResponse = await fetch('https://api.swapkit.dev/chainflip/broker/channel', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'x-api-key': apiKey,
},
body: JSON.stringify(chainflipDepositChannelParams),
});
const depositChannel = await depositChannelResponse.json();
const { depositAddress, explorerUrl } = depositChannel;
// Send funds to deposit address
...
}
Last updated