import axios from "axios";
import { ethers } from "ethers";
const API_URL = "https://api.alyra.finance/v1";
// Replace with your own type when you define the API response
type QuoteResponse = any;
async function fetchQuote(): Promise<QuoteResponse> {
const senderAddress = "0xYOUR_SENDER_ADDRESS";
const receiverAddress = "0xYOUR_RECEIVER_ADDRESS"; // optional for some EVM→EVM flows
const params = {
senderAddress,
receiverAddress,
originChainId: 1, // Ethereum Mainnet
destinationChainId: 137, // Polygon PoS
amount: "25000000", // 25 USDT if token has 6 decimals
originCurrency: "USDT",
destinationCurrency: "USDT",
};
const { data } = await axios.get<QuoteResponse>(`${API_URL}/quotes`, {
params,
});
return data;
}
async function main() {
// 1. Configure provider and signer for the origin chain
const provider = new ethers.JsonRpcProvider(
"https://mainnet.infura.io/v3/YOUR_INFURA_KEY",
1
);
// Do NOT hardcode the mnemonic in real apps – use environment variables / secure storage
const wallet = ethers.Wallet.fromPhrase("YOUR_MNEMONIC").connect(provider);
// 2. Fetch quote
const quote = await fetchQuote();
// 3. (Optional) Check allowance & approve
// Use the spender / approval address from the quote response in your own allowance helper.
// 4. Execute transaction
const txRequest = quote.transactionRequest;
if (!txRequest) {
throw new Error("transactionRequest is missing in the quote response");
}
const tx = await wallet.sendTransaction(txRequest);
const receipt = await tx.wait();
console.log("Transaction confirmed:", receipt.hash);
}
main().catch((error) => {
console.error("Quote example failed:", error);
});