Skip to main content

Quickstart: minimal working example

The following example demonstrates a complete transaction flow:
  1. Fetches a quote from delora API for token swap
  2. Executes the transaction using @solana/web3.js
⚠️ Security Note: Never hardcode private keys in production code. Use wallet adapters or secure key management solutions.

React Integration Example

For React applications, you can integrate the swap function as follows:

Breaking it down

1. Building the quote request

The getQuote function constructs a query string from parameters and fetches the quote from the API: senderAddress is required, while receiverAddress is optional for same-type routes like this one and defaults to senderAddress.
Key parameters:
  • originChainId / destinationChainId: Chain IDs (1000000001 for Solana)
  • amount: Token amount in smallest unit (e.g., "100000000" for 100 USDC with 6 decimals)
  • originCurrency / destinationCurrency: SPL token mint addresses (e.g., EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v for USDC)
  • senderAddress: Required Solana wallet address (base58 encoded)
  • receiverAddress: Optional for same-type routes; defaults to senderAddress. For routes across different chain types, provide it explicitly.

2. Wallet provider setup

The function accepts a SolanaProvider interface, which can be obtained from various sources: Browser extension (Phantom, Solflare, etc.):
Wallet adapter (React):
Keypair (development only):
⚠️ Never hardcode private keys or secret keys in production code.

3. Transaction deserialization

The quote response contains a base64-encoded VersionedTransaction that needs to be decoded:
Notes:
  • Use Uint8Array.from(atob(...)) instead of Buffer.from() for browser compatibility
  • The transaction is already prepared with all necessary instructions
  • Always wrap deserialization in try-catch for error handling

4. Transaction signing and execution

Sign the transaction with the wallet provider and send it to the network: