Create Bridge Order

Create Bridge Order feature is pivotal for executing the bridging operation. It processes essential inputs such as source and destination chains, asset, amount, and the sender and receiver wallet addresses. This functionality is the core of the bridging service, enabling the actual transfer of assets from one blockchain network to another. By handling these key parameters, it ensures a smooth and efficient transaction, encapsulating the essence of the service's capability to facilitate cross-chain asset movements.

Executes bridge of specified asset from user wallet on source chain to user specified wallet on destination chain.

POST /api/bridge/execute

Headers

NameTypeDescription

api-key*

string

Received API key.

network-type*

string

EVM or Starknet.

cookie*

Array

Cookie with session data

Request Body

NameTypeDescription

source_chain*

string

Name of source chain.

destination_chain*

string

Name of destination chain.

asset_from*

string

Name of the asset in source chain.

asset_to*

string

Name of the asset in destination chain.

receiver_wallet*

string

Address of receiver wallet.

amount*

string

Amount to be sent.

{
    "transaction_id": "string",
    "hot_wallet_address": "string"
}

Here is the code snippet that demonstrates how to call bridge execution transaction:

//..

const sourceChain= 'ZKSYNC';
const destinationChain= 'ARBITRUM';
const assetFrom = 'USDT';
const assetTo = 'USDT';
const amount = '254.33'; 
const senderWallet = '0x'; 
const receiverWallet= '0x'; 
const API_KEY = 'YOUR_API_KEY';

const executeBridge = async (
    source_chain: string,
    destination_chain: string,
    asset_from: string,
    asset_to: string,
    amount: string,
    senderWallet: string,
    receiverWallet: string,
    sourceNetworkType: string,
    walletCookie?: string[],
  ) => {
    const url = `/api/bridge/execute`;

    const data = {
      source_chain: sourceChain,
      destination_chain: destinationChain,
      asset_from: asset_from,
      asset_to: asset_to,
      amount: amount,
      sender_wallet: senderWallet,
      receiver_wallet: receiverWallet,
    };

    const res = await axios.post(url, data, {
      headers: {
        ["api-key"]: API_KEY,
        ["network-type"]: sourceNetworkType,
        cookie: walletCookie,
      },
    });

    return res;
  }

const bridge = async (
    amount: string,
    sourceNetworkType: string,
  ) => {
    const cookies = walletCookies[senderWallet];

    if (!walletCookies) {
      throw new Error(`Cookies for wallet: ${senderWallet} don't exist`);
    }

    const bridgeData = await executeBridge(
      sourceChain,
      destinationChain,
      assetFrom,
      assetTo,
      amount,
      senderWallet,
      receiverWallet,
      sourceNetworkType,
      cookies,
    );

   const transactionId = bridgeData.transaction_id;
   const hotWalletAddress = bridgeData.hot_wallet_address;
   //..
}

//..

Once bridge transaction has been sent to API, backend constantly monitors it's Hot wallet transactions on source chain to track incoming assets movement from the user wallet. In order to make process completed on-chain transfer transaction should be sent to Hot wallet on source chain.

Last updated