import axios from "axios";
import {
Connection,
VersionedTransaction,
} from "@solana/web3.js";
const API_URL = "https://api.alyra.finance/v1";
type QuoteResponse = {
transaction?: string;
};
async function fetchQuote(): Promise<QuoteResponse> {
const senderAddress = "YOUR_SOLANA_PUBLIC_KEY";
const receiverAddress = "YOUR_RECEIVER_PUBLIC_KEY";
const params = {
senderAddress,
receiverAddress,
originChainId: 1000000001,
destinationChainId: 137,
amount: "1000000",
originCurrency: "So11111111111111111111111111111111111111112",
destinationCurrency: "0x...",
};
const { data } = await axios.get<QuoteResponse>(`${API_URL}/quotes`,{
params }
);
return data;
}
async function main() {
const connection = new Connection(
"https://api.mainnet-beta.solana.com",
"confirmed"
);
const quote = await fetchQuote();
if (!quote.calldata.data) {
throw new Error("Missing Solana transaction in quote response");
}
const txBuffer = Buffer.from(quote.calldata.data, "base64");
const transaction = VersionedTransaction.deserialize(txBuffer);
const signer = /* your Keypair or wallet adapter */;
transaction.sign([signer]);
const signature = await connection.sendTransaction(transaction);
await connection.confirmTransaction(signature, "confirmed");
console.log("Transaction confirmed:", signature);
}
main().catch(console.error);