Integration
Swapping and Aggregation
Javascript SDK
Swap Assets
Request Deposit Address

Request Deposit Address

The ability to create a unique deposit address that is reserved for a user during a fixed period of time (24hs) provides a lot of flexibility and is a unique feature of the Chainflip protocol.

Once the deposit address is available, the user can send the funds from any wallet(s) to trigger the swap process. No need to connect a wallet.

Sending funds to a deposit address is cheaper than a smart contract call, as no token and amount approval involved.

Learn more on Deposit Channels & Brokers section.

requestDepositAddress

Requests a deposit address based on the provided swapRequest.

requestDepositAddress(
  depositAddressRequest: SwapRequest,
  options?: RequestOptions
): Promise<SwapResponse>

The depositAddressRequest object describes the swap for which a deposit address is requested.

ParamDescriptionData type
srcChainSource chain for the swapstring
destChainDestination chain for the swapstring
srcAssetSymbol of the token to be swapped from the source chainstring
destAssetSymbol of the token to be received on the destination chainstring
destAddressAddress where the swapped tokens will be sent to on the destination chainstring
amountAmount of the source token to be swappedstring
ccmMetadataOptional metadata for triggering a smart contract call on the destination chain.Object

Example

import { Chains, Assets } from "@chainflip-io/chainflip-sdk/swap";
 
const swapDepositAddressRequest = {
  srcChain: Chains.Ethereum,
  destChain: Chains.Bitcoin,
  srcAsset: Assets.ETH,
  destAsset: Assets.BTC,
  destAddress: "bc1qar0srrr7xfkvy5l643lydnw9re59gtzzwf5mdq",
  amount: (1.5e18).toString(), // 1.5 ETH
};
console.log(await swapSDK.requestDepositAddress(swapDepositAddressRequest));

The amount will always be in the base unit of the source asset, i.e. for ETH it will be Wei.

Sample Response

{
  "srcChain": "Ethereum",
  "destChain": "Bitcoin",
  "srcAsset": "ETH",
  "destAsset": "BTC",
  "destAddress": "bc1qar0srrr7xfkvy5l643lydnw9re59gtzzwf5mdq",
  "amount": "1500000000000000000", // 1.5 ETH
  "depositChannelId": "1234567890", // Identifies the deposit channel for this swap
  "depositAddress": "0x1234567890abcdef1234567890abcdef12345678" // Address where funds need to be deposited to start the swap
}

requestDepositAddress + Cross-Chain Messaging (CCM)

The optional ccmMetadata object enables executing a smart contract call on the destination chain (see #executecall) and has the following properties:

ParamDescriptionData type
messageMessage that is passed to the destination address on the destination chainstring
gasBudgetGas budget for the call on the destination chain. This amount is based on the source asset and will be swapped to pay for gas.number

Example

In this example, we're including ccmMetadata in the request:

import { Chains, Assets } from "@chainflip-io/chainflip-sdk/swap";
 
const callDepositAddressRequest = {
  srcChain: Chains.Bitcoin,
  destChain: Chains.Ethereum,
  srcAsset: Assets.BTC,
  destAsset: Assets.ETH,
  destAddress: "0x2f41dd5dEe1BcF767139b6bB6e27673aE90061b5",
  amount: (1e8).toString(), // 1 BTC
  ccmMetadata: {
    message: "0xdeadc0de",
    gasBudget: (0.001e8).toString(), // 0.001 BTC will be swapped for ETH to pay for gas
  },
};
console.log(await swapSDK.requestDepositAddress(callDepositAddressRequest));

The amount and gasBudget will always be in the base unit of the source asset, i.e. for ETH it will be Wei.

Sample Response

{
  "srcChain": "Bitcoin",
  "destChain": "Ethereum",
  "srcAsset": "BTC",
  "destAsset": "ETH",
  "destAddress": "0x2f41dd5dEe1BcF767139b6bB6e27673aE90061b5",
  "amount": "100000000", // 1 BTC
  "ccmMetadata": {
    "message": "0xdeadc0de",
    "gasBudget": "100000", // 0.001 BTC will be swapped for ETH to pay for gas
  },
  "depositChannelId": "1234567890", // Identifies the deposit channel for this swap
  "depositAddress": "tb1pylj9uhsmuz7h62spprv2z2vcnx2lw9epzt4amm3j45y75r6rrd8sdx0sjf", // Address where funds need to be deposited to start the swap
}

The resulting depositChannelId can be used in Get Status.

requestDepositAddress + Bring Your Own Broker

The previous two examples can also be performed with your own broker, instead of the broker that is provided by the Chainflip SDK:

import { SwapSDK } from '@chainflip-io/chainflip-sdk/swap';
 
const sdk = new SDK({
  network: 'perseverance',
  broker: {
    url: 'https://my.broker.io',
    commissionBps: 0,
  },
});
 
const channel = await sdk.requestDepositAddress({
  srcAsset: 'ETH',
  srcChain: 'Ethereum',
  destAsset: 'FLIP',
  destChain: 'Ethereum',
  amount: '1000000000000000000', // 1 ETH
  destAddress: '0x1234567890abcdef1234567890abcdef12345678',
});
 
console.log(channel);
/*
  {
    srcAsset: 'ETH',
    srcChain: 'Ethereum',
    destAsset: 'FLIP',
    destChain: 'Ethereum',
    amount: '1000000000000000000',
    destAddress: '0x717e15853fd5f2ac6123e844c3a7c75976eaec9b',
    depositChannelId: '710643-Ethereum-615',
    depositAddress: '0x2d564a0754168cf49af604c82e84bd3a30599bf5',
  }
*/
;