How to interact with deBridge infrastructure from Solana
To streamline communication with deBridge programs on the Solana blockchain, the debridge-solana-sdk has been developed. This Rust 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:
cargoadddebridge-solana-sdk
If you use the Anchor framework, then your program calling for a deBridge send might look like this:
use anchor_lang::prelude::*;declare_id!("3botMWU4s1Lcs4Q2wQBkZqsCW1vc3N9H9tY9SZYVs5vZ");#[program]pubmod send_via_debridge {use debridge_solana_sdk::prelude::*;use super::*;pubfnsend_via_debridge(ctx:Context<SendViaDebridge>) ->Result<()> {invoke_debridge_send(// Debridge Instruction DataSendIx {// 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)]pubstructSendViaDebridge {}
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 example of how to use the TypeScript library. For this example it is:
For detailed examples, within the SDK there is an example-program project that allows you to see examples of various integrations and the corresponding client code for them. For example: