async function getUserTransactionHistory(userTokenShare, fromTimestamp, toTimestamp = null) {
const crypto = require('crypto');
// Calculate user_id for ledger
const userId = crypto
.createHash('sha256')
.update(userTokenShare + 'ledger')
.digest('hex');
let url = `https://dev.app.boop.it/api/v1/ledger/transactions/${userId}?from=${fromTimestamp}`;
if (toTimestamp) {
url += `&to=${toTimestamp}`;
}
const response = await fetch(url, {
headers: {
'X-API-Key': 'your-api-key'
}
});
const { transactions } = await response.json();
// Decode hex-encoded transaction data
return transactions.map(hexString => {
const jsonString = Buffer.from(hexString, 'hex').toString('utf8');
return JSON.parse(jsonString);
});
}
// Usage
const lastMonth = Math.floor(Date.now() / 1000) - (30 * 24 * 60 * 60);
const history = await getUserTransactionHistory(userTokenShare, lastMonth);