Skip to main content
This page provides complete, working code examples for integrating Solana with OneBalance. All examples use real data from our testing environment and are copy-paste ready.

Prerequisites

Install the required dependencies:
npm install @solana/web3.js bs58

Signing Utilities

Here’s the signing function you’ll need for Solana operations:
For browser wallets like Phantom or Solflare:
import { MessageV0, VersionedTransaction } from '@solana/web3.js';
import bs58 from 'bs58';

/**
 * Signs a Solana operation using a browser wallet
 * @param dataToSign - Base64 encoded data from quote response
 * @param wallet - Connected Solana wallet (Phantom, Solflare, etc.)
 * @returns Base58 encoded signature
 */
async function signSolanaOperation(dataToSign: string, wallet: any): Promise<string> {
  const msgBuffer = Buffer.from(dataToSign, 'base64');
  const message = MessageV0.deserialize(msgBuffer);
  const transaction = new VersionedTransaction(message);
  
  const signedTx = await wallet.signTransaction(transaction);
  return bs58.encode(Buffer.from(signedTx.signatures[signedTx.signatures.length - 1]));
}

Example 1: SOL → USDC (Same Chain)

The simplest Solana operation - swap SOL to USDC within Solana:
curl -X POST 'https://be.onebalance.io/api/v3/quote' \
  -H 'Content-Type: application/json' \
  -H 'x-api-key: 42bb629272001ee1163ca0dbbbc07bcbb0ef57a57baf16c4b1d4672db4562c11' \
  -d '{
    "from": {
      "accounts": [{
        "type": "solana",
        "accountAddress": "J5CCzBULFax899tcirb6wMbenQUd8whbaetG7EfSick5"
      }],
      "asset": {
        "assetId": "solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp/slip44:501"
      },
      "amount": "10000000"
    },
    "to": {
      "asset": {
        "assetId": "solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp/token:EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v"
      }
    }
  }'

Example 2: SOL → USDC (Cross-Chain)

Swap SOL on Solana to USDC on Arbitrum - the most common cross-chain pattern:
curl -X POST 'https://be.onebalance.io/api/v3/quote' \
  -H 'Content-Type: application/json' \
  -H 'x-api-key: 42bb629272001ee1163ca0dbbbc07bcbb0ef57a57baf16c4b1d4672db4562c11' \
  -d '{
    "from": {
      "accounts": [{
        "type": "solana",
        "accountAddress": "J5CCzBULFax899tcirb6wMbenQUd8whbaetG7EfSick5"
      }],
      "asset": {
        "assetId": "solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp/slip44:501"
      },
      "amount": "10000000"
    },
    "to": {
      "asset": {
        "assetId": "eip155:42161/erc20:0xaf88d065e77c8cC2239327C5EDb3A432268e5831"
      },
      "account": "eip155:42161:0x895Cf62399bF1F8b88195E741b64278b41EB7F09"
    }
  }'

Example 3: USDC (Solana) → USDC (Arbitrum)

Transfer USDC from Solana to Arbitrum:
curl -X POST 'https://be.onebalance.io/api/v3/quote' \
  -H 'Content-Type: application/json' \
  -H 'x-api-key: 42bb629272001ee1163ca0dbbbc07bcbb0ef57a57baf16c4b1d4672db4562c11' \
  -d '{
    "from": {
      "accounts": [{
        "type": "solana",
        "accountAddress": "J5CCzBULFax899tcirb6wMbenQUd8whbaetG7EfSick5"
      }],
      "asset": {
        "assetId": "solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp/token:EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v"
      },
      "amount": "1000000"
    },
    "to": {
      "asset": {
        "assetId": "eip155:42161/erc20:0xaf88d065e77c8cC2239327C5EDb3A432268e5831"
      },
      "account": "eip155:42161:0x895Cf62399bF1F8b88195E741b64278b41EB7F09"
    }
  }'
This operation only requires a Solana account since funds come entirely from Solana. The recipient is specified in to.account.

Example 4: Aggregated USDC → SOL (Multi-Account)

Use aggregated USDC balance from both EVM and Solana accounts to buy SOL:
curl -X POST 'https://be.onebalance.io/api/v3/quote' \
  -H 'Content-Type: application/json' \
  -H 'x-api-key: 42bb629272001ee1163ca0dbbbc07bcbb0ef57a57baf16c4b1d4672db4562c11' \
  -d '{
    "from": {
      "accounts": [
        {
          "type": "kernel-v3.1-ecdsa",
          "accountAddress": "0xd4f5A60c9b500f875ADf757BC3027A4424079E05",
          "deploymentType": "ERC4337",
          "signerAddress": "0x9b747cC14A5672a7166b4eccdc92d7F4003f8081"
        },
        {
          "type": "solana",
          "accountAddress": "J5CCzBULFax899tcirb6wMbenQUd8whbaetG7EfSick5"
        }
      ],
      "asset": {
        "assetId": "ob:usdc"
      },
      "amount": "10000000"
    },
    "to": {
      "asset": {
        "assetId": "solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp/slip44:501"
      }
    }
  }'
This example shows OneBalance’s power - using funds from multiple blockchains in a single operation.

Check Balances

Always verify your balances before creating quotes:
curl -X GET 'https://be.onebalance.io/api/v3/balances/aggregated-balance?account=solana:J5CCzBULFax899tcirb6wMbenQUd8whbaetG7EfSick5' \
  -H 'x-api-key: 42bb629272001ee1163ca0dbbbc07bcbb0ef57a57baf16c4b1d4672db4562c11'

Quick Error Handling

import { PublicKey } from '@solana/web3.js';

// Ensure Solana address is valid before making requests
try {
  new PublicKey(accountAddress);
} catch (error) {
  throw new Error('Invalid Solana address format');
}

Next Steps

Contract Calls

Use Solana assets to fund smart contract calls on EVM chains

Troubleshooting

Common issues and solutions for Solana integration

API Reference

Complete API documentation for v3 endpoints

Solana Overview

Concepts and setup guide for Solana integration
For additional support, use the Intercom chat widget in the bottom right corner, join our Discord, or reach out via support.
Last modified on October 24, 2025