Skip to main content

Before you start

  • The TypeScript project, plus npm install @solana/web3.js bs58.
  • A Solana wallet with some SOL. Add its base58 private key as SOLANA_PRIVATE_KEY, and a Solana RPC URL as SOLANA_RPC_URL, to .env.

Script

Save this as src/swap-across-chains.ts and run npx tsx src/swap-across-chains.ts.
src/swap-across-chains.ts

Notes

  • fromToken and toToken accept a symbol such as USDC, a token address, or null for the chain’s native token.
  • A wallet may add its own compute-budget instructions, but every instruction BRDG built must stay exactly as it is. Any other change is refused as built_mismatch.
  • BRDG sets a recent blockhash on the transaction before returning it, so do not replace it. A Solana blockhash is only valid for about a minute, so sign and send promptly. If it expires, get a new quote.

Endpoints used