> loading_
# Let's walk through how to create a transaction that gets enriched with an AI security analysis.
# 1. Import your transaction handler and the new AI analysis service.
import { approvalQueue } from './transactions';
import { aiSecurityAnalyzer } from './ai';
# 2. Define the raw transaction you want the agent to propose.
# This could be a token approval, a swap, or any other interaction.
const rawTx = {
to: '0x1a2b3c...', // Malicious contract address
data: '0x095ea7b30000000000000000000000007a250d5630b4cf539739df2c5dacb4c659f2488dffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff', // approve(spender, uint256.max)
value: '0x0',
};
# 3. Before adding to the queue, pass the raw transaction to the analyzer.
# The analyzer simulates the transaction and returns a human-readable report.
console.log('Analyzing transaction for security risks...');
const securityReport = await aiSecurityAnalyzer.analyze(rawTx);
/*
securityReport might look like:
{
summary: "This transaction grants another contract permission to spend all of your tokens.",
warnings: [
"Grants UNLIMITED approval for a token.",
"The destination contract is newly deployed and unverified."
],
stateChanges: ["Your token balance will not change, but your token allowance for the spender will be set to maximum."]
}
*/
# 4. Attach the security report to the transaction object and add it to the approval queue.
# The UI will now display this enriched information to the user.
approvalQueue.add({
...rawTx,
securityReport, // The UI uses this object to display warnings.
});
console.log('Transaction with security analysis added to approval queue!');