Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@jup-ag/core

Package Overview
Dependencies
Maintainers
1
Versions
193
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@jup-ag/core

  • 0.0.0-alpha.4
  • npm
  • Socket score

Version published
Weekly downloads
1.2K
increased by1.45%
Maintainers
1
Weekly downloads
 
Created
Source

@jup-ag/core

Jupiter core typescript library

Installation

Yarn

yarn add @jup-ag/core

NPM

npm install @jup-ag/core

Usage

import { Connection } from '@solana/web3.js';
import { Jupiter } from '@jup-ag/core';
import { Wallet } from '@project-serum/anchor';

const wallet = Wallet.local()
const main = async () => {
    const connection = new Connection('https://solana-api.projectserum.com');
    const wallet = new Wallet
    
    // load Jupiter
    const jupiter = await Jupiter.load({
        connection,
        cluster: 'mainnet-beta',
        user: wallet.payer // or public key
    })

    // RouteMap which map each tokenMint and their respective tokenMints that are swappable
    const routeMap = jupiter.getRouteMap();
    const possibleSOLPairs = routeMap.get('So11111111111111111111111111111111111111112'); // return an array of token mints that can be swapped with SOL

    // Calculate routes for swapping 1 SOL to USDC with 1% slippage
    // routes are sorted based on outputAmount, so ideally the first route is the best.
    const routes = jupiter.computeRoutes('So11111111111111111111111111111111111111112', 'EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v', 1_000_000_000, 1);


    console.log('Quoted out amount', routes[0].outAmount);

    // Prepare execute exchange
    const { execute } = await jupiter.exchange({
        route: routes[0]
    })

    // Swap for keypair
    const swapResult = await execute()

    // Swap for publicKey
    // const swapResult = await execute({
    //     wallet: SignerWalletAdapter // from @solana/wallet-adapter-base, mainly need signTransaction and signAllTransactions
    // })

    if (swapResult.error) {
        console.log(swapResult.error)
    } else {
        console.log(swapResult.txid)
        console.log(swapResult.inputAddress)
        console.log(swapResult.outputAddress)
        console.log(swapResult.inputAmount)
        console.log(swapResult.outputAmount)
    }

FAQs

Package last updated on 17 Nov 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc