import { Transaction, VersionedTransaction } from "@solana/web3.js";
/**
* Sends a base64-encoded Solana transaction as plain text
* to the Astralane Iris2 gateway.
*/
async function sendTransaction(
transaction: Transaction | VersionedTransaction,
apiKey: string
): Promise<void> {
const url = new URL("https://lim.gateway.astralane.io/iris2");
url.searchParams.set("api-key", apiKey);
url.searchParams.set("method", "sendTransaction");
// Serialize and base64-encode the transaction
const base64Tx = Buffer.from(transaction.serialize()).toString("base64");
const response = await fetch(url.toString(), {
method: "POST",
headers: {
"Content-Type": "text/plain",
},
body: base64Tx,
});
if (!response.ok) {
throw new Error(
`sendTransaction failed: ${response.status} ${response.statusText}`
);
}
}
// Usage
// ... build and sign your transaction ...
await sendTransaction(signedTransaction, "YOUR_API_KEY");