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

6.0.0-beta.8 • Public • Published

@jup-ag/react-hook

The react hook to connect integrate Jupiter.

Installation

Yarn

yarn add @jup-ag/react-hook

NPM

npm install @jup-ag/react-hook

Usage

At your App shell:

import { JupiterProvider } from '@jup-ag/react-hook';
import { Connection } from '@solana/web3.js';

const connection = new Connection('https://rpc.ankr.com/solana');

const App = ({ children }) => {
  const wallet = useWallet() // user wallet
  return (
    <JupiterProivder connection={connection} cluster="mainnet-beta" userPublicKey={wallet.publicKey}>
      {children}
    </JupiterProvider>
  )
}
import { useJupiter } from '@jup-ag/raect-hook';

const SwapForm = () => {
  const jupiter = useJupiter({
    amount, // integer amount in term of input mint
    inputMint,
    outputMint,
    slippageBps,
    debounceTime, // debounce time before refresh
  })

  const {
    allTokenMints, // all the token mints that is possible to be input
    routeMap, // routeMap, same as the one in @jup-ag/core
    exchange, // exchange 
    refresh, // function to refresh rates
    lastRefreshTimestamp: lastRefreshTimestamp.current, // timestamp when the data was last returned
    loading, // loading states
    routes, // all the routes from inputMint to outputMint
    error,
  } = jupiter
}

Example repo

https://github.com/ZhengYuTay/create-dapp-solana-nextjs

Dependencies (6)

Dev Dependencies (16)

Package Sidebar

Install

npm i @jup-ag/react-hook

Weekly Downloads

2,531

Version

6.0.0-beta.8

License

MIT

Unpacked Size

135 kB

Total Files

8

Last publish

Collaborators

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