Announcing our $20m venture round co-led by cyber•Fund and Blockchain Capital. Read more.
Working code examples for Solana integration with OneBalance, including transaction signing and cross-chain operations
import { MessageV0, VersionedTransaction, PublicKey } from '@solana/web3.js'; import bs58 from 'bs58'; /** * Signs a Solana chain operation from OneBalance quote response * @param dataToSign - Base64 encoded data from quote response * @param wallet - Solana wallet instance (Phantom, Solflare, etc.) * @returns Base58 encoded signature */ async function signSolanaOperation(dataToSign: string, wallet: any): Promise<string> { // 1. Convert base64 data to message buffer const msgBuffer = Buffer.from(dataToSign, 'base64'); // 2. Deserialize into MessageV0 const message = MessageV0.deserialize(msgBuffer); // 3. Create versioned transaction const transaction = new VersionedTransaction(message); // 4. Sign with wallet const signedTx = await wallet.signTransaction(transaction); // 5. Extract signature and encode as base58 const signature = bs58.encode(Buffer.from(signedTx.signatures[signedTx.signatures.length - 1])); return signature; }
curl -X POST 'https://be.staging.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" } } }'
curl -X POST 'https://be.staging.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" } }'
curl -X POST 'https://be.staging.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" } }'
to.account
curl -X POST 'https://be.staging.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": "ds:usdc" }, "amount": "10000000" }, "to": { "asset": { "assetId": "solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp/slip44:501" } } }'
# Single Solana account balance curl -X GET 'https://be.staging.onebalance.io/api/v3/balances/aggregated-balance?account=solana:J5CCzBULFax899tcirb6wMbenQUd8whbaetG7EfSick5' \ -H 'x-api-key: 42bb629272001ee1163ca0dbbbc07bcbb0ef57a57baf16c4b1d4672db4562c11' # Multi-chain aggregated balance curl -X GET 'https://be.staging.onebalance.io/api/v3/balances/aggregated-balance?account=eip155:42161:0xfe52613d747E20F2f62e0A5cC36B0DFAe771C442,solana:J5CCzBULFax899tcirb6wMbenQUd8whbaetG7EfSick5' \ -H 'x-api-key: 42bb629272001ee1163ca0dbbbc07bcbb0ef57a57baf16c4b1d4672db4562c11'
https://be.staging.onebalance.io
// Check if wallet is connected and supports signing if (!wallet.connected || !wallet.signTransaction) { throw new Error('Wallet not properly connected'); }
// Ensure you're using correct Solana asset IDs const SOL_ASSET_ID = "solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp/slip44:501"; const USDC_SOLANA_ASSET_ID = "solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp/token:EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v";
// Always use base58 encoding for Solana signatures const signature = bs58.encode(Buffer.from(signedTransaction.signatures[signedTransaction.signatures.length - 1])); // NOT: signedTransaction.signatures[0].toString()
Was this page helpful?