LogoLogo
SwapKit's websiteRegister for an API Key
  • 🏡Getting started
    • SwapKit's trade offerings
  • 💰Monetization
  • 🤝Partnership
  • SwapKit API
    • Introduction
    • /providers - Request supported chains by a swap provider
    • /tokens - Request supported tokens by a swap provider
    • /quote - Request a trade quote
    • /quote - Understanding the response
    • /chainflip/broker/channel - Opening a Chainflip deposit channel
    • /track - Request the status of a swap
    • /screen - Check AML compliance
    • /price - Lookup token prices
Powered by GitBook
On this page
  1. SwapKit API

/chainflip/broker/channel - Opening a Chainflip deposit channel

To initiate a swap through the CHAINFLIPor CHAINFLIP_STREAMINGproviders, 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.chainflipobject of the /quoteresponse, as in the example below. The object needs to be passed to the /chainflip/broker/channelendpoint, 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 depositAddresswhich 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 /quoterequest 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
    ...

}
Previous/quote - Understanding the responseNext/track - Request the status of a swap

Last updated 2 months ago