Skip to content

Instantly share code, notes, and snippets.

@SgtPooki
Created November 11, 2025 13:44
Show Gist options
  • Select an option

  • Save SgtPooki/03e0f3bf3a5f63bc4eb2b02fc342acf2 to your computer and use it in GitHub Desktop.

Select an option

Save SgtPooki/03e0f3bf3a5f63bc4eb2b02fc342acf2 to your computer and use it in GitHub Desktop.
;(async () => {
const { ethers } = await import('https://cdn.jsdelivr.net/npm/[email protected]/dist/ethers.min.js')
const abi = [
'event PieceAdded(uint256 indexed dataSetId,uint256 indexed pieceId,tuple(bytes raw) pieceCid,string[] metadataKeys,string[] metadataValues)',
]
const iface = new ethers.Interface(abi)
const event = iface.getEvent('PieceAdded')
const getFieldNode = (container, label) => {
for (const dt of container.querySelectorAll('dt')) {
if (dt.textContent.trim() === label) return dt.nextElementSibling ?? null
}
return null
}
const logContainers = [...document.querySelectorAll('div.border-background.py-1.pr-4.border-t')]
const pieceAddedContainers = logContainers.filter((container) => {
const nameNode = getFieldNode(container, 'Name')
return nameNode?.textContent.trim().startsWith('PieceAdded(')
})
if (pieceAddedContainers.length === 0) {
console.warn('No PieceAdded logs found on this page.')
return
}
for (const container of pieceAddedContainers) {
const topicsNode = getFieldNode(container, 'Topics')
const topicRows = topicsNode ? [...topicsNode.querySelectorAll('div.flex.items-center')] : []
const topics = topicRows
.map((row) => row.textContent.match(/0x[a-fA-F0-9]+/g)?.pop() ?? null)
.filter((value) => value != null)
const dataNode = getFieldNode(container, 'Data')
const data = dataNode?.querySelector('pre')?.textContent.trim()
if (!data || topics.length < 3) {
console.warn('Skipping log: missing topics or data', container)
continue
}
const decoded = iface.decodeEventLog(event, data, topics)
const metadata = Object.fromEntries(
decoded.metadataKeys.map((key, idx) => [key, decoded.metadataValues[idx] ?? null])
)
console.log('--- PieceAdded log ---')
console.log('dataSetId:', decoded.dataSetId.toString())
console.log('pieceId:', decoded.pieceId.toString())
console.log('metadata:', metadata)
}
})()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment