Swapping
Integrations
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 DepositAddressRequest.

requestDepositAddress(
  depositAddressRequest: DepositAddressRequest
): Promise<DepositAddressResponse>

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

ParamDescriptionData type
srcChain(required)Source chain for the swapChain
destChain(required)Destination chain for the swapChain
srcAsset(required)Symbol of the token to be swapped from the source chainAsset
destAsset(required)Symbol of the token to be received on the destination chainAsset
destAddress(required)Address where the swapped tokens will be sent to on the destination chainstring
amount(required)Amount of the source token to be swapped, represented in the base unit of the source tokenstring
brokerCommissionBps(optional)Commission charged by the broker creating the channel, in basis points. If given, this value will be used instead of the brokerCommissionBps value used when initializing the SDK. This option is only available when the SDK is initialized with a brokerUrlnumber
affiliateBrokers(optional)An array of objects defining affiliate broker accounts that take a commission in addition to brokerCommissionBps. This option is only available when the SDK is initialized with a brokerUrlArray
ccmMetadata(optional)Optional metadata for triggering a smart contract call on the destination chain.Object
maxBoostFeeBps(optional)The accepted boost fee limit (in bps).
Defaults to 0 - non-boostable deposit channel.
If set to a value higher than 0, the deposits coming through this channel will have a chance to get boosted by paying a fee that doesn't exceed the boost fee limit set - boostable deposit channel.
It is recommended to understand under which conditions deposits get boosted.
number

Example

Normal deposit address

import { Chains, Assets } from "@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
  brokerCommissionBps: 100, // 100 basis point = 1%
  affiliateBrokers: [
    { account: "cFM8kRvLBXagj6ZXvrt7wCM4jGmHvb5842jTtXXg3mRHjrvKy", commissionBps: 50 }
  ], // total commission 150 bps = 1.5%
};
console.log(await swapSDK.requestDepositAddress(swapDepositAddressRequest));

Boostable deposit address

import { Chains, Assets } from "@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
  maxBoostFeeBps: 10 // Willing to pay up to 10 bps fee for a boosted deposit
};
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
  "depositChannelBrokerCommissionBps": 100,
  "depositChannelAffiliateBrokers": [
    { "account": "cFM8kRvLBXagj6ZXvrt7wCM4jGmHvb5842jTtXXg3mRHjrvKy", "commissionBps": 50 }
  ],
  "estimatedDepositChannelExpiryTime": 1630000000, // Estimated expiry time of the deposit channel
  "maxBoostFeeBps": 10 // Boost fee bps limit set upon channel creation. 0 by default
}

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
message(required)Message that is passed to the destination address on the destination chain. The message should be shorter than 10k bytes.string
gasBudget(required)Gas budget for the call on the destination chain. This amount is based on the source asset and will be subtracted from the input amount and swapped to pay for gas.number

Example

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

import { Chains, Assets } from "@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
  "brokerCommissionBps": 0, // Commission charged by the broker for this swap
  "estimatedDepositChannelExpiryTime": 1630000000, // Estimated expiry time of the deposit channel
}

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/sdk/swap';
 
const sdk = new SDK({
  network: 'perseverance',
  broker: {
    url: 'https://my.broker.io',
    commissionBps: 15,
  },
});
 
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',
    brokerCommissionBps: 15,
    estimatedDepositChannelExpiryTime: 1630000000,
  }
*/