sendTransaction

Installation

npm install @quickscope/sdk

Usage

Initialization

First, initialize the Quickscope class with your location ("frankfurt" or "nyc") and your API key:

import Quickscope from '@quickscope/sdk';
// OR
const Quickscope = require('@quickscope/sdk');

const quickscope = new Quickscope("frankfurt", "your-api-key");

Method: simulateTransaction

Description

The sendTransaction method signs and sends a Solana VersionedTransaction using a base58-encoded private key. It includes optional retry logic and an option to simulate the transaction before sending, helping prevent on-chain errors and reducing failure rates.

Use this method after building and deserializing a transaction with getSwapBest, getSwapCustom, or createTransaction.


Parameters

{
  rpc: Connection;
  transaction: VersionedTransaction;
  privateKey: string;
}
  • rpc: (Connection) – A Solana RPC connection (e.g., from @solana/web3.js) used to simulate the transaction.
  • transaction: (VersionedTransaction) – The deserialized transaction object to simulate (typically from createTransaction).
  • privateKey: (string) – A base58-encoded secret key used to sign the transaction before simulation.
  • retries (optional): (number) – Number of retry attempts if the transaction fails (default = 3).
  • simulateBeforeSend (optional): (boolean) – Whether to simulate the transaction before broadcasting (default = false).

Returns

Promise<string>: A promise that resolves to the transaction signature (base58 string) upon successful confirmation.


Example

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

async function sendSwapTransaction() {
    try {
        const rpc = new Connection("https://frankfurt.quickscope.so/api?api-key=your-api-key");

        const encodedTx = "AAABAgMEBQYH..."; // Base64 transaction string
        const tx = await quickscope.v1.utils.createTransaction(encodedTx);

        const signature = await quickscope.v1.utils.sendTransaction(
            rpc,
            tx,
            process.env.PRIVATE_KEY!, // base58 secret key
            3,                        // retries
            true                      // simulate before sending
        );

        console.log("Transaction sent with signature:", signature);
    } catch (error) {
        console.error("Transaction failed:", error);
    }
}

sendSwapTransaction();

Error Handling

This method throws or returns an error if:

  • The private key is invalid or cannot be decoded
  • The transaction simulation fails (when simulateBeforeSend is true)
  • The transaction fails after all retry attempts
  • The RPC node cannot confirm the transaction

Use try/catch blocks and monitor signature response for confirmation tracking.