@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
const jupiter = await Jupiter.load({
connection,
cluster: 'mainnet-beta',
user: wallet.payer
})
const routeMap = jupiter.getRouteMap();
const possibleSOLPairs = routeMap.get('So11111111111111111111111111111111111111112');
const routes = jupiter.computeRoutes('So11111111111111111111111111111111111111112', 'EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v', 1_000_000_000, 1);
console.log('Quoted out amount', routes[0].outAmount);
const { execute } = await jupiter.exchange({
route: routes[0]
})
const swapResult = await execute()
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)
}