Migrating from Voyager to Nitro is a straightforward task and won't require more than 10 minutes of effort. Follow the steps given below to migrate your existing codebase from Voyager to Nitro:
Step 1) To fetch the quote from the pathfinder API, change the PATH_FINDER_API_URLchange the endpoint from "quote" to "v2/quote" and remove userAddress and feeTokenAddres from the params.
Step 2) Add another function getTransaction() to fetch the transaction data using the quote returned by the pathfinder quote endpoint. Here, you need to add the senderAddress, receiverAddress, and the refundAddress.
import { ethers } from 'ethers'
const PATH_FINDER_API_URL = "https://k8-testnet-pf.routerchain.dev/api"
const getTransaction = async (params, quoteData) => {
const endpoint = "v2/transaction"
const txDataUrl = `${PATH_FINDER_API_URL}/${endpoint}`
console.log(txDataUrl)
try {
const res = await axios.post(txDataUrl, {
...quoteData,
senderAddress: "<sender-address>",
receiverAddress: "<receiver-address>",
refundAddress: "<refund-address>" // optional, by default senderAddress will be treated as the refundAddress
})
return res.data;
} catch (e) {
console.error(`Fetching tx data from pathfinder: ${e}`)
}
}
const main = async () => {
const params = {
'fromTokenAddress': '0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174', // USDC on Polygon
'toTokenAddress': '0x04068DA6C83AFCFA0e13ba15A6696662335D5B75', // USDC on Fantom
'amount': '10000000', // 10 USDC (USDC token contract on Polygon has 6 decimal places)
'fromTokenChainId': 137, // Polygon
'toTokenChainId': 250, // Fantom
'partnerId': 24, // get your unique partner id - https://app.routernitro.com/partnerId
}
const quoteData = await getQuote(params);
// get transaction data via the Transaction endpoint
const txResponse = await getTransaction(quoteData);
// sending the transaction using the data given by the pathfinder
const tx = await wallet.sendTransaction(txResponse.txn)
}
main()
info
In Voyager, the pathfinder API used to return the transaction data along with the quote. However, in Nitro, the data is prepared via a separate endpoint.