npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

solana-swap

v1.1.6

Published

Solana Swap Library for Solana Tracker Swap API

Downloads

1,670

Readme

Solana Swap by Solana Tracker

Easiest way to add Solana based swaps to your project. Uses the Solana Swap api from https://docs.solanatracker.io

Update July 12

You can now use "auto" on amount to automatically set the amount to the Balance of that token in the wallet. Only for Swap not for Rate endpoints! Jito has been added to the library with example below.

UPDATE - July 9: Swap API has been updated, way faster and supporting new markets!

Now supporting

  • Raydium
  • Raydium CPMM
  • Pump.fun
  • Moonshot
  • Orca
  • Jupiter (Private Self Hosted API)

Example Projects

Volume Bot: https://github.com/YZYLAB/solana-volume-bot Trading Bot: https://github.com/YZYLAB/solana-trade-bot More coming soon

Installation

Install Solana Swap with NPM

  npm install solana-swap

Or

git clone https://github.com/YZYLAB/solana-swap.git

Demo

Swap API is used live on: https://www.solanatracker.io

Add your site here

Example Usage

import { Keypair } from "@solana/web3.js";
import bs58 from "bs58";
import { SolanaTracker } from "../";

async function swap() {
  const keypair = Keypair.fromSecretKey(
    bs58.decode(
      "YOUR_SECRET_KEY_HERE"
    )
  );
  const solanaTracker = new SolanaTracker(
    keypair,
    "https://rpc.solanatracker.io/public?advancedTx=true"
  );

  const swapResponse = await solanaTracker.getSwapInstructions(
    "So11111111111111111111111111111111111111112", // From Token
    "4k3Dyjzvzp8eMZWUXbBCjEvwSkkk59S5iCNLY3QrkX6R", // To Token
    0.0001, // Amount to swap
    30, // Slippage
    keypair.publicKey.toBase58(), // Payer public key
    0.0005, // Priority fee (Recommended while network is congested)
  );

  // Regular transaction
  try {
    const txid = await solanaTracker.performSwap(swapResponse, {
      sendOptions: { skipPreflight: true },
      confirmationRetries: 30,
      confirmationRetryTimeout: 500,
      lastValidBlockHeightBuffer: 150,
      resendInterval: 1000,
      confirmationCheckInterval: 1000,
      commitment: "processed",
      skipConfirmationCheck: false // Set to true if you want to skip confirmation checks and return txid immediately
    });
    // Returns txid when the swap is successful or throws an error if the swap fails
    console.log("Transaction ID:", txid);
    console.log("Transaction URL:", `https://solscan.io/tx/${txid}`);
  } catch (error: any) {
    const {signature, message} = error;
    console.error("Error performing swap:", message, signature);
  }

  // Jito transaction
  try {
    const txid = await solanaTracker.performSwap(swapResponse, {
      sendOptions: { skipPreflight: true },
      confirmationRetries: 30,
      confirmationCheckInterval: 500,
      commitment: "processed",
      jito: {
        enabled: true,
        tip: 0.0001,
      },
    });
    // Returns txid when the swap is successful or throws an error if the swap fails
    console.log("Transaction ID:", txid);
    console.log("Transaction URL:", `https://solscan.io/tx/${txid}`);
  } catch (error: any) {
    const {signature, message} = error;
    console.error("Error performing swap:", message, signature);
  }
}

swap();

ES5 Example Import

const { SolanaTracker } = require("solana-swap")

FAQ

Why should I use this API?

We retrieve all Solana (raydium, pumpfun, etc) tokens the second they are available, so you can perform fast snipes. We also provide our own hosted Jupiter Swap API with no rate limits and faster market updates.

Is there a fee for using this API?

We charge a 0.5% fee on each successful transaction . Using this for a bot or site with a high processing volume? Contact us via Discord or email ([email protected]) and get the fee reduced (down to 0.1% only if accepted.)