Describe
Get a one-sentence description of what is about to happen.
Get Transaction Description
Describe is an endpoint that will return a one-sentence description of what is about to happen. It does not return an output as enriched as Preview, but it is cheaper and faster to run.
The endpoint takes an unsigned transaction object via POST (you can generate a sample one here), and returns a one-sentence description.
Let's see how we'd call the endpoint, assuming we have an unsigned transaction where the user is depositing MATIC as collateral into Aave v3:
const axios = require('axios');
const API_BASE_URL = 'https://foresight.noves.fi';
// Set your API Key as an env var or directly as a string
const NOVES_API_KEY = process.env.NOVES_API_KEY;
async function describeTransaction(chain, unsignedTx) {
try {
const response = await axios.post(
`${API_BASE_URL}/evm/${chain}/describe`,
{ transaction: unsignedTx },
{
headers: {
apiKey: NOVES_API_KEY,
},
}
);
return response.data;
} catch (error) {
console.error('Error describing transaction:', error);
return null;
}
}
const chain = 'polygon';
// Sample Aave v3 transaction
const unsignedTx = {
from: '0x840cb722e7acf3f970aa79f0e3a37460a6dcd46a',
to: '0x1e4b7a6b903680eab0c5dabcb8fd429cd2a9598c',
value: '0x4563918244f400',
data: '0x474cf53d000000000000000000000000794a61358d6845594f94dc1db02a252b5b4814ad000000000000000000000000840cb722e7acf3f970aa79f0e3a37460a6dcd46a0000000000000000000000000000000000000000000000000000000000000000',
gas: '0x493e0',
gasPrice: '0x208034bdf4',
};
describeTransaction(chain, unsignedTx).then((data) => {
console.log(JSON.stringify(data, null, 2));
});
The endpoint will return:
{
"description": "Deposit collateral into a lending protocol."
}
We can easily display this description to the user in a React component. For example:
import React, { useState, useEffect } from 'react';
const PresignDescription = ({ chain, unsignedTx }) => {
const [description, setDescription] = useState(null);
useEffect(() => {
describeTransaction(chain, unsignedTx).then(data => {
setDescription(data.description);
});
}, [chain, unsignedTx]);
return (
<div>
<h2>This transaction will:</h2>
<p>{description}</p>
</div>
);
}
export default PresignDescription;
Updated about 1 year ago