Skip to content

Instantly share code, notes, and snippets.

@troggy
Last active January 10, 2025 16:37
Show Gist options
  • Save troggy/39f4e0fddfd1754f2b03fef948d34e3f to your computer and use it in GitHub Desktop.
Save troggy/39f4e0fddfd1754f2b03fef948d34e3f to your computer and use it in GitHub Desktop.
Gnosis Safe confirmations stats
const fetchSafeTransactionHistory = async (safeAddress, chainId = 56) => {
const delay = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
const fetchMultisigData = async (safeTxId) => {
await delay(500); // Rate limiting
try {
const response = await fetch(`https://safe-client.safe.global/v1/chains/${chainId}/transactions/${safeTxId}`);
return response.json();
} catch (error) {
console.error('Error fetching multisig data:', error);
return null;
}
};
const fetchHistory = async (accumulator = [], nextUrl = null) => {
const baseUrl = nextUrl || `https://safe-client.safe.global/v1/chains/${chainId}/safes/${safeAddress}/transactions/history?trusted=true&imitation=false&executionInfo=true`;
await delay(500); // Rate limiting
try {
const response = await fetch(baseUrl);
const data = await response.json();
const transactions = data.results.filter(item => item.type === 'TRANSACTION');
const transactionsWithMultisig = [];
for (const item of transactions) {
const multisigData = await fetchMultisigData(item.transaction.id);
const signers = multisigData.detailedExecutionInfo?.confirmations?.map(s => s.signer.value);
transactionsWithMultisig.push({
...item.transaction,
signers,
});
}
const updatedHistory = [...accumulator, ...transactionsWithMultisig];
if (data.next) {
return fetchHistory(updatedHistory, data.next);
}
return updatedHistory;
} catch (error) {
console.error('Error fetching Safe transaction history:', error);
throw error;
}
};
return fetchHistory();
};
const safeAddr = process.argv[2]
if (!safeAddr) {
console.error('Provide Safe address. E.g. node get-signers-who-confirmed.js 0xd34d...')
return
}
fetchSafeTransactionHistory(safeAddr).then(txs => {
txs.forEach(tx => {
if (!tx.signers || tx.signers.length === 0) return
tx.signers.forEach(signer =>
console.log(`${tx.timestamp / 1000};${tx.id};${tx.txHash};${signer}`)
);
});
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment