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
          • API Parameters
            • Estimation-Only
            • prependOperatingExpenses
          • API Response
            • JSON Example
          • Refreshing Estimates
        • Tracking Order Status
          • Order States
        • Integrating deBridge hooks
          • Creating Hook data for Solana
        • Submitting an Order Creation Transaction
        • Cancelling the Order
      • deBridge Widget
      • Interacting with smart contracts
        • Placing orders
        • Filling orders
      • Under the Hood
        • Reserve Assets
        • Bridging Reserve Assets
        • Bridging Non-Reserve Assets
        • Order Fulfillment
          • Detecting the Order
          • Fulfilling the Order
            • Pre-Fill-Swap
          • Claiming the Order
      • Affiliate fees
        • Withdrawing Affiliate Fees
      • Fees and operating expenses
    • 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

Was this helpful?

  1. The deBridge Messaging Protocol
  2. Development Guides

Sending cross-chain messages from Solana

How to interact with deBridge infrastructure from Solana

PreviousWethGateNextOn-Chain external call preparation for Solana

Last updated 11 months ago

Was this helpful?

To streamline communication with deBridge programs on the Solana blockchain, the has been developed. This SDK allows for easy and efficient connection to the deBridge infrastructure, which enables decentralized transfers of messages and value between different supported blockchains.

To start using our sdk, add it to dependencies by :

cargo add debridge-solana-sdk

If you use the framework, then your program calling for a deBridge send might look like this:

use anchor_lang::prelude::*;

declare_id!("3botMWU4s1Lcs4Q2wQBkZqsCW1vc3N9H9tY9SZYVs5vZ");

#[program]
pub mod send_via_debridge {
    use debridge_solana_sdk::prelude::*;

    use super::*;

    pub fn send_via_debridge(ctx: Context<SendViaDebridge>) -> Result<()> {
        invoke_debridge_send(
            // Debridge Instruction Data
            SendIx {
                // Chain id to which the tokens are sent
                target_chain_id: chain_ids::POLYGON_CHAIN_ID,
                /// Address in `target_chain_id` that will receive the transferred tokens
                receiver: hex::decode("bd1e72155Ce24E57D0A026e0F7420D6559A7e651").unwrap(),
                // Use of fee in transfer token (not currently enabled)
                is_use_asset_fee: false,
                // Amount of sending tokens. From this amount fee will be taken
                amount: 1000,
                // Additional data for tokens sending with auto external execution
                submission_params: None,
                // Referral code to track your transfers
                referral_code: None,
            },
            // List of accounts used by debridge-program, generated on the client
            ctx.remaining_accounts,
        )
        .map_err(|err| err.into())
    }
}

#[derive(Accounts)]
pub struct SendViaDebridge {}
import { DeBridgeSolanaClient } from "@debridge-finance/solana-contracts-client";
import { AnchorProvider, Program, Wallet as AnchorWallet } from "@coral-xyz/anchor";
import { Connection, clusterApiUrl } from "@solana/web3.js";
import { crypto, helpers, WRAPPED_SOL_MINT } from "@debridge-finance/solana-utils";

const connection = new Connection(clusterApiUrl("mainnet-beta"));
const example = new Program(
    ExampleIDL,
    "3botMWU4s1Lcs4Q2wQBkZqsCW1vc3N9H9tY9SZYVs5vZ",
    new AnchorProvider(connection, {} as unknown as AnchorWallet, {}),
  );
const deBridge = new DeBridgeSolanaClient(connection, undefined, {
    programId: "DEbrdGj3HsRsAzx6uH4MKyREKxVAfBydijLUF3ygsFfh",
    settingsProgramId: "DeSetTwWhjZq6Pz9Kfdo1KoS5NqtsM6G8ERbX4SSCSft",
  });

const chainTo = 137;
const receiver = "0xbd1e72155Ce24E57D0A026e0F7420D6559A7e651";
const amount = 1000;
const tokenMint = WRAPPED_SOL_MINT;

const builder = example.methods.sendViaDebridge(
    amount,
    Array.from(crypto.normalizeChainId(chainTo)),
    helpers.hexToBuffer(receiver),
    false,
  );

const context = await deBridge.buildSendContext(
    sender,
    null,
    tokenMint,
    receiver,
    chainTo,
    false,
    receiver,
  );
builder.remainingAccounts([...context.asAccountMeta, { isWritable: false, isSigner: false, pubkey: deBridge.program.programId }]);
const tx = await builder.transaction();

The dependency packages that are used:

You can use any account in your logic. However, the remaining accounts you pass on will have to be created by the client. Our SDK provides an of how to use the TypeScript library. For this example it is:

For detailed examples, within the SDK there is an project that allows you to see examples of various integrations and the corresponding client code for them. For example:

debridge-solana-sdk
Rust
cargo
Anchor
example
@debridge-finance/solana-contracts-client
@debridge-finance/solana-utils
@coral-xyz/anchor
@solana/web3.js
example-program
send_via_debridge
send_via_debridge_with_native_fixed_fee
send_via_debridge_with_exact_amount
send_via_debridge_with_asset_fixed_fee
send_via_debridge_with_execution_fee
send_via_debridge_with_external_call
send_message_via_debridge
check_claiming