deBridge
  • Introduction
  • The deBridge Messaging Protocol
    • Protocol Overview
    • Fees and Supported Chains
    • 🟢Deployed Contracts
    • Development Guides
      • Building an EVM-based dApp
        • EVM smart contract interfaces
          • Interfaces
            • ICallProxy
            • IDeBridgeGate
            • IDeBridgeToken
            • IDeBridgeTokenDeployer
            • IOraclesManager
            • ISignatureVerifier
            • IWethGate
          • Libraries
            • Flags
          • Periphery
            • CallProxy
            • DeBridgeToken
            • DeBridgeTokenProxy
            • SimpleFeeProxy
          • Transfers
            • DeBridgeGate
            • DeBridgeTokenDeployer
            • OraclesManager
            • SignatureVerifier
            • WethGate
      • Sending cross-chain messages from Solana
        • On-Chain external call preparation for Solana
        • Off-chain external call preparation for Solana
      • Lifecycle of a cross-chain call
      • Gathering data for the claim
    • Development Tools
    • Security
    • Slashing and Delegated Staking
  • 🔁DLN: The deBridge Liquidity Network Protocol
    • Introduction
    • Protocol Overview
    • deBridge Hooks
    • Fees and Supported Chains
    • 🟢Deployed Contracts
    • Market and Limit Orders
    • Integration Guidelines
      • Interacting with the API
        • Authentication
        • Creating an Order
          • Quick Start
          • Reserve Assets
          • Bridging Reserve Assets
          • Bridging non-reserve assets
          • API Parameters
            • Estimation-Only
            • prependOperatingExpenses
          • API Response
            • JSON Example
          • Refreshing Estimates
          • Fees and operating expenses
          • Order Fulfillment
            • Detecting the Order
            • Fulfilling the Order
              • Pre-Fill-Swap
            • Claiming the Order
        • Tracking Order Status
          • Order States
        • Integrating deBridge hooks
          • Creating Hook data for Solana
        • Submitting an Order Creation Transaction
        • Cancelling the Order
        • Affiliate fees
      • deBridge Widget
      • Interacting with smart contracts
        • Placing orders
        • Filling orders
        • Withdrawing Affiliate Fees
    • Interacting with the deBridge App
      • Custom Linking
    • Protocol specs
      • Deterministic order ID
      • Hook data
        • Anatomy of a Hook for the EVM-based chains
        • Anatomy of a Hook for Solana
  • 💸dePort
    • Getting started
    • Transfers Flow
  • ⚡deBridge Points
    • Referrers Overview
    • Integrators Overview
  • 🌐deBridge IaaS
    • Getting started
  • 🌐Legal
    • SDK & API License Agreement
  • External Links
    • deBridge Use Cases
      • 💡Examples
    • Talks, Videos, and Articles
    • Website
    • Github
    • Twitter
    • Social channels
      • Discord
      • Facebook
      • LinkedIn
      • Medium
      • Telegram
      • YouTube
Powered by GitBook
On this page
  • EVM-based blockchains
  • Solana

Was this helpful?

  1. DLN: The deBridge Liquidity Network Protocol
  2. Integration Guidelines
  3. Interacting with the API

Submitting an Order Creation Transaction

The transaction call retrieved from the DLN API must be signed by a user how is willing to sell the asset, and then broadcasted to the source chain.

EVM-based blockchains

The tx object has the following structure and is ready to be signed and broadcasted:

{
    "estimation": { ... }
    
    "tx": {
        "data": "0xfbe16ca70000000000000000000000000000000[...truncated...]",
        "to": "0xeF4fB24aD0916217251F553c0596F8Edc630EB66",
        "value": "5000000000000000",
    },
}

Field names from the tx object speak for themselves:

  • the to is the field the transaction should be sent to, and typically you should expect the address of one of the smart contracts responsible for forwarding;

  • the data is the contents of the transaction, containing instructions related to swaps planned on the source or (and) on the destination chains, bridging settings, etc;

  • the value is the amount of native blockchain currency that must be sent along with the transaction.

However, there are a few things you must consider:

First, the value is always positive, even if the input token is an ERC-20 token. This is because the underlying DLN protocol takes a fixed amount in the native currency, so the API always includes it as the transaction value. In the above example, the value equals the current fixed fee, which is 0.005 BNB on the BNB Chain.

Second, in case the input token is an ERC-20 token, a user need to give approval to the smart contract address specified in the tx.to field prior to submitting this transaction so it can transfer them on the behalf of the sender. This can be typically done by calling either approve() or increaseAllowance() method of the smart contract which implements the token you are willing to swap. Approve at least the amount that has been specified as the estimation.srcChainTokenIn.amount response property.

Other than that, the transaction is ready to be signed by a user and broadcasted to the blockchain. It is also worth mentioning that the given transaction data can be used as a part of another transaction: a dApp can bypass the given to, data and value to your smart contract, and make a low-level call. There is even possible to create multiple transactions for different orders, and perform several low-level calls.

The affiliate fee is paid only after the order gets fulfilled, and the taker requests order unlock during the unlock procedure.

Solana

To convert the hex-encoded string into VersionedTransaction decode hex to buffer using any library and call VersionedTransaction.deserialize(decoded).

Example:

import { VersionedTransaction, Connection, clusterApiUrl, Keypair } from "@solana/web3.js";

function encodeNumberToArrayLE(num: number, arraySize: number): Uint8Array {
  const result = new Uint8Array(arraySize);
  for (let i = 0; i < arraySize; i++) {
    result[i] = Number(num & 0xff);
    num >>= 8;
  }

  return result;
}

function updatePriorityFee(tx: VersionedTransaction, computeUnitPrice: number, computeUnitLimit?: number) {
  const computeBudgetOfset = 1;
  const computeUnitPriceData = tx.message.compiledInstructions[1].data;
  const encodedPrice = encodeNumberToArrayLE(computeUnitPrice, 8);
  for (let i = 0; i < encodedPrice.length; i++) {
    computeUnitPriceData[i + computeBudgetOfset] = encodedPrice[i];
  }

  if (computeUnitLimit) {
    const computeUnitLimitData = tx.message.compiledInstructions[0].data;
    const encodedLimit = encodeNumberToArrayLE(computeUnitLimit, 4);
    for (let i = 0; i < encodedLimit.length; i++) {
      computeUnitLimitData[i + computeBudgetOfset] = encodedLimit[i];
    }
  }
}

const wallet = new Keypair(); // your actual wallet here
const connection = new Connection(clusterApiUrl("mainnet-beta")); // your actual connection here
const tx = VersionedTransaction.deserialize(Buffer.from(tx.data.slice(2), "hex"));

// make sure to set correct CU price & limit for the best UX 
updatePriorityFee(tx, NEW_CU_PRICE, NEW_CU_LIMIT);
const { blockhash } = await connection.getLatestBlockhash();
tx.message.recentBlockhash = blockhash; // Update blockhash!
tx.sign([wallet]); // Sign the tx with wallet
connection.sendTransaction(tx);
PreviousCreating Hook data for SolanaNextCancelling the Order

Last updated 4 months ago

Was this helpful?

For DLN trades coming from Solana the tx object returned by DLN API has only one field data which is hex-encoded

Make sure you properly set transaction priority fees based on the current load of the Solana network. Refer to one of these guides to learn more about how to estimate tx fee parameters: - guide - guide

More info about sending versioned transactions .

🔁
VersionedTransaction
Triton
Helius
here