@jup-ag/hook
TypeScript icon, indicating that this package has built-in type declarations

0.0.0-alpha.0 • Public • Published

@jup-ag/hook

The hook to connect to Jupiter aggregator.

Props

Props Types
cluster "mainnet-beta" | "testnet" | "devnet"
connection Connection
amount Number
inputMint PublicKey
outputMint PublicKey
slippage number

Returns

interface Jupiter {
  /** routes that are possible, sorted decending based on outAmount */
  routes?: RouteInfo[];
  /** exchange function to submit transaction */
  exchange: (
    wallet: WalletAdapter,
    inputAmount: number,
    route: RouteInfo
  ) => Promise<SwapResult>;
  /** refresh function to refetch the prices */
  refresh: () => void;
  /** last refresh timestamp */
  lastRefreshTimestamp: number;
  /** all possible token mints to be chosen from */
  allTokenMints: string[];
  /** route map input mint with output mints */
  routeMap: Map<string, string[]>;
  /** loading state */
  loading: boolean;
}

How to use?

import { useJupiter } from '@jup-ag/hook'
import { PublicKey } from '@solana/web3.js'

const App = ()=> {
    const connection = useConnection() // from a provider
    const [amount, setAmount] = useState(0)
    const [inputMint, setInputMint] = useState(new PublicKey('...'))
    const [outputMint, setOutputMint] = useState(new PublicKey('...'))
    const [slippage, setSlippage] = useState(0)

    const {
        routes,
        allTokenMints,
        routeMap,
        exchange,
        loading,
        refresh,
        lastRefreshTimestamp
    } = useJupiter({
        cluster: 'devnet',
        connection,
        amount,
        inputMint,
        outputMint
    })
}

Example

TODO

Readme

Keywords

none

Package Sidebar

Install

npm i @jup-ag/hook

Weekly Downloads

1

Version

0.0.0-alpha.0

License

MIT

Unpacked Size

79.5 kB

Total Files

14

Last publish

Collaborators

  • wkitsin
  • jjsb
  • hjchan
  • arowana
  • siong
  • dicksonp
  • zhengyutay