// Get system transactions by block hash on Hyperliquid
const getSystemTxsByBlockHash = async (blockHash) => {
const response = await fetch('https://hyperliquid-mainnet.core.chainstack.com/YOUR_ENDPOINT/evm', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
jsonrpc: '2.0',
method: 'eth_getSystemTxsByBlockHash',
params: [blockHash],
id: 1
})
});
const data = await response.json();
if (data.result === null) {
throw new Error(`Block not found: ${blockHash}`);
}
return data.result;
};
// Analyze system transactions from a specific block
const analyzeSystemTransactions = async (blockHash) => {
try {
const systemTxs = await getSystemTxsByBlockHash(blockHash);
if (systemTxs.length === 0) {
return {
blockHash,
message: 'No system transactions in this block'
};
}
const analysis = {
blockHash,
blockNumber: parseInt(systemTxs[0].blockNumber, 16),
totalSystemTxs: systemTxs.length,
transactions: systemTxs.map(tx => ({
hash: tx.hash,
type: parseInt(tx.type, 16),
from: tx.from,
to: tx.to,
value: parseInt(tx.value, 16),
gasUsed: parseInt(tx.gasUsed, 16),
gasPrice: parseInt(tx.gasPrice, 16),
status: tx.status === "0x1" ? "Success" : "Failed",
index: parseInt(tx.transactionIndex, 16)
})),
summary: {
successfulTxs: systemTxs.filter(tx => tx.status === "0x1").length,
failedTxs: systemTxs.filter(tx => tx.status === "0x0").length,
totalGasUsed: systemTxs.reduce((sum, tx) => sum + parseInt(tx.gasUsed, 16), 0),
uniqueTypes: [...new Set(systemTxs.map(tx => parseInt(tx.type, 16)))]
}
};
return analysis;
} catch (error) {
return {
blockHash,
error: error.message,
suggestion: 'Block may not exist or may have been reorganized'
};
}
};
// Compare system transactions between two blocks
const compareSystemTxsBetweenBlocks = async (blockHash1, blockHash2) => {
const [block1Txs, block2Txs] = await Promise.all([
getSystemTxsByBlockHash(blockHash1).catch(() => null),
getSystemTxsByBlockHash(blockHash2).catch(() => null)
]);
return {
block1: {
hash: blockHash1,
exists: block1Txs !== null,
systemTxCount: block1Txs ? block1Txs.length : 0,
types: block1Txs ? [...new Set(block1Txs.map(tx => parseInt(tx.type, 16)))] : []
},
block2: {
hash: blockHash2,
exists: block2Txs !== null,
systemTxCount: block2Txs ? block2Txs.length : 0,
types: block2Txs ? [...new Set(block2Txs.map(tx => parseInt(tx.type, 16)))] : []
},
comparison: {
bothExist: block1Txs !== null && block2Txs !== null,
countDifference: block1Txs && block2Txs ? block1Txs.length - block2Txs.length : null
}
};
};
// Usage examples
const blockHash = "0x1970d9c7ce6f00a982b421610ad400a79522c102a26db24ef3ec1f2bd621c399";
analyzeSystemTransactions(blockHash)
.then(analysis => console.log('System Transaction Analysis:', analysis))
.catch(error => console.error('Error:', error));