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
simulateTransaction
Description
The simulateTransaction
method simulates the execution of a Solana VersionedTransaction
without submitting it to the blockchain. This is useful for checking whether a transaction will succeed before broadcasting it, and for debugging errors or estimating compute usage.
Use this method for dry runs in staging environments, CI pipelines, or before pushing high-value transactions.
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.
Returns
Promise<boolean>
: A promise that resolves to:
true
if the simulation was successful (no errors)false
if the simulation failed
Example
import { Connection } from '@solana/web3.js';
async function testSimulation() {
try {
const rpc = new Connection("https://frankfurt.quickscope.so/api?api-key=your-api-key");
const encodedTx = "AAABAgMEBQYH..."; // From swap.getSwapCustom() or getSwapBest()
const tx = await quickscope.v1.utils.createTransaction(encodedTx);
const success = await quickscope.v1.utils.simulateTransaction(
rpc,
tx,
process.env.PRIVATE_KEY!
);
if (success) {
console.log("Simulation passed");
} else {
console.warn("Simulation failed");
}
} catch (error) {
console.error("Error simulating transaction:", error);
}
}
testSimulation();
Error Handling
This method throws or returns an error if:
- The base58 private key is invalid or cannot be decoded
- The transaction is malformed or unsigned
- The simulation encounters a runtime error (e.g., compute failure, account mismatch)
Wrap the call in a try/catch
block for robust error handling.