@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