Overview
Solana deposits are straightforward because the Layerswap API returns a fully constructed, serialized transaction incall_data. You only need to decode it, set a fresh blockhash, sign it, and send it.
Prerequisites:
- @solana/web3.js for transaction handling and RPC communication
call_data Format
For Solana,call_data is a base64-encoded serialized Transaction. It contains all the instructions, accounts, and program IDs already set up by the Layerswap backend — including SPL token transfers when applicable.
Transaction Construction
Set a fresh blockhash
Fetch the latest blockhash from the Solana RPC and update the transaction. This ensures the transaction doesn’t expire before it’s confirmed.
Validate balances (optional)
Estimate the transaction fee and verify the sender has enough SOL for fees and enough of the source token for the transfer amount.
Full Example (Server-side with Keypair)
Full Example (Browser with Wallet Adapter)
When your users connect via a Solana wallet (Phantom, Solflare, etc.), use the wallet adapter’ssignTransaction method: