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.
The pre-built transaction includes a top-level SPL Memo instruction
whose UTF-8 content is the swap’s
metadata.sequence_number — this is how Layerswap matches your
deposit to the swap (the Solana equivalent of Bitcoin’s OP_RETURN), and it works identically for
native SOL and SPL-token deposits. Refreshing the blockhash and signing is expected, but don’t drop
or alter the instructions — a deposit that reaches to_address without the memo won’t be matched and
the swap will expire. Submitting call_data as-is guarantees the memo is present and correct.Transaction Construction
1
Decode the transaction
Convert the base64
call_data string into a Transaction object.2
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.
3
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.
4
Sign the transaction
Sign the transaction with the sender’s keypair or wallet adapter.
5
Send and confirm
Submit the signed transaction to the network and wait for confirmation.
Full Example
TheServer-side tab signs locally with a Keypair. The Browser tab uses a connected wallet adapter (Phantom, Solflare, etc.) and its signTransaction method.
Sending with Retry Logic
Solana transactions can sometimes fail to land due to network congestion. A robust implementation resends the transaction periodically until it’s confirmed or the blockhash expires:Building the transaction yourself
If you construct the deposit transaction yourself instead of submittingcall_data, you must satisfy
both conditions, or the deposit won’t be matched:
- Send the funds to
to_address— native SOL via the System program, or SPL tokens to the recipient’s associated token account. - Add the swap’s
metadata.sequence_numberas a top-level instruction through the SPL Memo program. A memo emitted from inside another program (via CPI / inner instruction) is not read.