> loading_
// In `src/workflow.ts`, let's upgrade our `main` function to provide AI summaries.
//
// 1. First, locate the part of the code where the payment transaction is submitted and validated.
// Previously, we just logged a link to the explorer.
// --- BEFORE ---
// console.log(`Transaction successful: https://testnet.xrpl.org/transactions/${paymentResult.result.hash}`);
// 2. Now, instead of just printing the URL, we'll capture the full transaction result.
// Then, we'll pass this result to a new function that generates an AI summary.
// --- AFTER ---
// In your main function, after the transaction is validated:
const paymentResult = await client.submitAndWait(signed, { wallet });
if (paymentResult.result.meta?.TransactionResult === "tesSUCCESS") {
console.log("Transaction was successful! Generating AI summary...");
// Create a new function to handle the AI interaction
const summary = await getAiSummary(paymentResult.result);
console.log("\n--- AI Transaction Summary ---");
console.log(summary);
console.log("----------------------------");
console.log(`\nView full details on explorer: https://testnet.xrpl.org/transactions/${paymentResult.result.hash}`);
} else {
throw new Error(`Transaction failed: ${paymentResult.result.meta?.TransactionResult}`);
}
// 3. Define the `getAiSummary` helper function. This function takes the transaction
// JSON, constructs a prompt, and calls an LLM API.
// Note: You will need an API key for your chosen LLM provider.
async function getAiSummary(txResult: object): Promise<string> {
const prompt = `
Please summarize the following XRPL transaction result in plain English.
Explain the key details including the sender, receiver, amount (in XRP),
the transaction fee, and the final confirmation status.
Be concise and clear.
Transaction Data:
${JSON.stringify(txResult, null, 2)}
`;
// Example using a fictional LLM service API
const response = await fetch("https://api.example-ai.com/v1/completions", {
method: "POST",
headers: {
"Content-Type": "application/json",
"Authorization": "Bearer YOUR_AI_API_KEY", // Replace with your actual key
},
body: JSON.stringify({
model: "text-davinci-003", // or any other suitable model
prompt: prompt,
max_tokens: 150,
}),
});
const data = await response.json();
return data.choices[0].text.trim();
}